softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
494 stars 32 forks source link

Support lex-style definitions #417

Open FranklinChen opened 10 months ago

FranklinChen commented 10 months ago

I didn't see a way to do the following that can be done in lex:

DIGIT    [0-9]
ID       [a-z][a-z0-9]*
NUMBER {DIGIT}+"."{DIGIT}*

%%

{NUMBER} ...

so that patterns can be composed in definitions and definitions can be used in rules.

ltratt commented 10 months ago

Yes, this isn't currently supported. Given that we currently use the Rust regex crate, if we wanted to do something like this, we'd have some interesting fun and games getting escaping right. So a basic version is pretty easy; a version with good error messages might be challenging.