Giter VIP home page Giter VIP logo

indent-stack's Introduction

indent-stack

Rust library for parsing off-side syntax like YAML or Python

Syntax specification

Although indents are typically spaces and tabs, this library does not specify any constraints on the characters used for indentation. As long as the character sequences are identical (without equivalent conversions), they are considered as the same indent level.

This library accepts indentation strings from callers; it is not the responsibility of this library to extract indentations from a file buffer. Callers should extract the indentation characters from each line and iteratively pass them to the accept() function.

The off-side syntax is defined by the following rules:

  • If the indent of line x + 1 is longer than and starts with that of line x, line x + 1 is called a "child" of line x.
  • If lines x and y have the same indent and lines x+1..=y-1 are children of line x, lines x and y are "siblings".
  • If line y is a child of line x and lines z and y are siblings, line z is also a child of line x.
  • All valid lines are either descendents or siblings of line 0 (which is defined as a line without indent).

This leads to the following results:

  • If the indent of a line is neither a prefix nor a continuation of that of the previous line, it is an invalid line.
  • The longest common prefix of the indents of all siblings and descendents of a line is its own indent.

Disallow inconsistent indents

By default, inconsistent indents are disallowed. That is, all indents must be repetitions of the first indent.

For example, if the first indent is 2 spaces, all indents must be 2 spaces; a line with 2-space indent followed by a line with 4-space indent is syntax error.

indent-stack's People

Contributors

chankyin avatar

Watchers

 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.