softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
517 stars 31 forks source link

Docs Question - Optional Prefix to Regular Expressions #438

Closed DavidHVernon closed 9 months ago

DavidHVernon commented 10 months ago

Snip from https://softdevteam.github.io/grmtools/latest_release/book/lexcompatibility.html

Both Lex and grmtools lex files support start conditions as an optional prefix to regular expressions, listing necessary states for the input expression to be considered for matching against the input. Lex uses a special action expression BEGIN(state) to switch to the named state. grmtools lex files use a token name prefix.

Could someone point me at an example of this? I'm very curious, and think it might fix an issue that i've been wrestling with.

ratmice commented 10 months ago

The example in the repo that uses this is the lrpar/examples/start_states:

https://github.com/softdevteam/grmtools/blob/master/lrpar/examples/start_states/src/comment.l

When the left hand side matches the current state of the lexer (which starts out in the INITIAL state) it tries to apply the regex, if that then matches the state operation on the right hand side is applied, modifying the current state and a token is produced.

DavidHVernon commented 10 months ago

Thank you for the clarification. I'm not quite sure that I follow, but I will give it some more thought before I ask follow-on questions.

ratmice commented 10 months ago

I tried to update that hopefully making it a bit clearer.

DavidHVernon commented 10 months ago

Thank you for that, but the real issue is that I was reading it in the grocery store checkout line :)

DavidHVernon commented 9 months ago

Hey all. Thanks for the help here. Life has gotten in between me and Rust lately, but I've got my head around this now and I suppose we can close the issue.