3 ms·
Maybe I'm being naive here, but the lalrpop grammer seems very similar to rust code. Couldn't this be a proc macro instead of a generator? You could define a pa
by conradludgate 6y ago
Maybe I'm being naive here, but the lalrpop grammer seems very similar to rust code. Couldn't this be a proc macro instead of a generator? You could define a parse tree as an enum. Each field of the parse tree should implement a Parse trait and then the enum can derive its own parse trait.
Perhaps the output won't be so smart if its only building the parser element by element rather than seeing the full picture. Also grammers like `"(" Term ")"` would probably be implemented as a struct and that's a bit less developer friendly to quickly code. (Although it could be tuple `(LParen, Term, RParen)` which isn't too far off)
Maybe I'll take a deeper look into the code when I have some free time, but I think I would prefer a proc macro based system
- ibraheemdev 6y agoI believe there is a work in progress implementation of a proc-macro interface for lalrpop here [0] 0: https://github.com/dtolnay/lalrproc https://github.com/dtolnay/lalrproc
- conradludgate 6y agoNot saying it's ever sensible to go against dtolnay and his infinite wisdom when it comes to proc macros, but I think i might create my own alternative implementation. I'm not sure though, I'll need to play around with lalrpop some more first and figure out some complex scenarios before I decide
- diragon 6y agoFrom Nim's tutorial: "Macros are very powerful. A piece of good advice is to use them as little as possible, but as much as necessary."