GithubHelp home page GithubHelp logo

samvv / mage Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 549 KB

A work-in-progress lexer/parser generator for a growing number of languages

Python 100.00%
lexer-generator parse-trees parser-generator text-analysis

mage's People

Contributors

samvv avatar

Watchers

 avatar  avatar

mage's Issues

Add support for 'wrapping' nodes during emission

Take this Python snippet:

def foo(a: int, b: str, c: bool) -> None:
    print("Hello")

Something that is equally valid:

def foo(
    a: int,
    b: str,
    c: bool
) -> None:
    print("Hello")

In the second example, the parameters are wrapped and take up less horizontal space.

We'd like that Mage generator to handle this case automatically for any given grammar.

This might require generating a pseudo-emit function that just calculates the horizontal depth of the block being generated.

Create a pass that checks whether hidden expressions are optional

The following expression:

pub foo = 'hello' \[\s]+ 'world

Isn't valid because the emitter cannot reconstruct at least one \s out of the CST that was generated.

The following would be valid:

pub foo = 'hello' \[\s]* 'world'

In this case the emitter would just output zero characters.

Proper handling of whitespaces in generated emitter

Let's say we have the following grammar:

@skip
skip = [\s]*

pub token expr1 = [a-z]+

pub token expr2 = 'bar'

pub foo = expr1 expr2

expr1 is defined in such a way that it completely consumes expr2.

During transformation, foo is injected with the skip rule:

pub foo = expr1 skip expr2

We would like the code emitter to force emit a whitespace between expr1 and expr2.

Why should it do it?

  1. It knows it can emit a whitespace because the injected expression skip allows for such an emitted string to be parsed.
  2. It knows it must do so because the prefix of expr2, such as ba, is consumed by expr1 during a re-parse if it does not emit a whitespace

This boils down to adding an additional step in the code emitter where every skip in the grammar is checked and converted to some additional statements for emitting the whitespace. It is also possible to do part of this at runtime, where the whitespace is only emitted if it is strictly necessary.

Not all field values in a CST are validated

The following is a snippet of some generated code that is missing any checks:

new_params = list()
for params_element in params:
     params_element_0 = params_element[0]
     new_params_element_0 = params_element_0

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.