Giter Site home page Giter Site logo

off-side.rs's Introduction

off-side.rs

Build Status
Travis-CI

Use off-side syntax (indent instead of braces, like in Python) to write Rust!

Disclaimer: implementing a different standard of the language is apparently not a good idea. This project is just a proof of concept for fun.

Off-side rule

Off-side rule means that a computer language uses indents instead of using {} braces to distinguish code hierarchy. Well-known examples include YAML (a data serialization language), Python (a programming language) and PugJS (a JavaScript markup preprocessor language).

Example

#[macro_use]
extern crate off_side;

use std::io::{Error, ErrorKind};

off_side! {

fn try_int(i: i32) -> Result<i32, Error>:
    match i:
        0 => Ok(1),
        1 => Err(Error::new(ErrorKind::NotFound, "Hello")),
        _ => unreachable!(),

fn main():
    for i in 0..2:
        let result = try_int(i);
        let num = match result:;
            Ok(i) => i,
            Err(err) => err.raw_os_error().unwrap_or_else(|| 3),
        println!("num: {}", num);

}

Syntax specification

  • Indent rules follow the specification in the indent-stack crate.
  • Due to proc_macro limitations, all indent characters are considered the same. In other words, if you mix tabs and spaces, tabs will be considered as one space.
  • Do not place block comments /* */ before line start. They might be considered as spaces as well.
  • On the parent line of indent blocks that should have been wrapped by braces, end the parent line with an extra :.
  • If the braced indent block should be followed by a semicolon (e.g. let statements with match or if/else), end the parent line with :;.

Final disclaimer

This library is a proof of concept and just for fun. Not recommended for use in production or in publicly published crates.

off-side.rs's People

Contributors

chankyin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.