GithubHelp home page GithubHelp logo

Comments (3)

Geordi7 avatar Geordi7 commented on July 22, 2024 1

No, as in scopes delimited by indented sections of text (al a pug python haskell, etc.)

from nearley.

TekuConcept avatar TekuConcept commented on July 22, 2024

significant whitespace

As in multiple contiguous whitespace characters?

OMS -> [\s]:* # optional multi-line whitespace
RMS -> [\s]:+ # required multi-line whitespace

from nearley.

TekuConcept avatar TekuConcept commented on July 22, 2024

as in scopes delimited by indented sections of text (al a pug python haskell, etc.)

Ah, so indent / dedent... that will be a context-aware parsing solution.

Use local state

You could get away with creating and updating a local context in the grammar post-processing step, eg.

LINES
    -> LINES RBS LINE {% d => {
        // where d[0] is the state object
        d => updateState(d)
    } %}
    |  LINE {% d => createState(d) %}
    
RBS -> OWS LF OMS # required break space
OMS -> [\s]:*     # optional multi-line space
OWS -> [ \t\r]:*  # optional white space
LF -> "\n"

This technique, however, will pose a few challenges and limitations, but it's one way to go about this without creating your own lexer.

Use a custom lexer

This may perhaps be the more trivial way of parsing indent / dedent - as your sneaking suspicion was hinting to. (Haven't tried it myself yet.) I found the following on moo's issue tracker for context-aware indent / dedent parsing: no-context/moo#55 with the last link (moo-indentation-lexer) being the one you probably want.

Then according to the nearley docs:

@{%
    const moo = require("moo")
    const IndentationLexer = require('moo-indentation-lexer')

    // Create a lexer from rules
    const mooLexer = moo.compile({ ... })
    // Create an indentation-aware lexer using the lexer
    const lexer = new IndentationLexer({ lexer: mooLexer })
%}

# Pass your lexer object using the @lexer option:
@lexer lexer

BLOCK -> HEADING %indent STATEMENTS %dedent

from nearley.

Related Issues (20)

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.