0x2a-42 / lelwel

Resilient LL(1) parser generator for Rust
Apache License 2.0
124 stars 3 forks source link

Parameterized rules? #1

Open xldenis opened 5 months ago

xldenis commented 5 months ago

This seems like an awesome project, I'm looking forward to trying this out on some small projects, but I noticed a missing feature which makes parsers much nicer to use with generators: paramerized rules.

This was introduced (I think) by menhir for ocaml, and allows you to factor out common repetition patterns like those found to make lists, arguments etc...

with this we could have something like:

list(R): emp | R ("," R)*
0x2a-42 commented 5 months ago

Thanks a lot. I actually already had the same idea, but postponed implementing it, because it was not strictly necessary.

There are some design decisions to be made about the syntax, the generated node name, and the allowed types of parameters (tokens, rules, parameterized rules). Maybe something like this doesn't look too bad:

arguments: list{expression, ','};
parameters: list{parameter, ','};

list{element, Delimiter}: [element (Delimiter element)*];

I'll look into it once I find some time.