igordejanovic / parglare

A pure Python LR/GLR parser - http://www.igordejanovic.net/parglare/
MIT License
136 stars 32 forks source link

Support for parenthesized groups #135

Closed igordejanovic closed 3 years ago

igordejanovic commented 3 years ago

Idea is to be able to use parentheses in place of symbol references. This would make grammars more compact and natural for some syntactic constructs.

For example:

    A: (B C)*[COMMA];
    A: (B C)*[COMMA] a=(A+ (B | C)*)+[COMMA];
    B: C;
    terminals
    C: "c";
    COMMA: ",";

In this contrived example we can see that we could apply repetitions (*, +, ?) and separators to subexpression in between (). Thus (B C)* means zero or more sequences of B C, and (B C)*[COMMA] is the same but requires comma separator between any two B C match.

Also, assignments could accept a group instead a rule reference. Groups can be nested at an arbitrary level.

igordejanovic commented 3 years ago

Done. Available on the master branch.