softdevteam / grmtools

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

Is there a way to pass Conext in `$lexer` when doing action? #454

Closed Taylor-lagrange closed 1 month ago

Taylor-lagrange commented 1 month ago

In my syntax parsing scenario, I need some external information to explain the current AST. It would be very convenient if I could acces/modify a context in $lexer during action, but after looking through the documentation, there seems to be no way to do this.

Case like I wanna do:

duration -> Result<Duration, String>:
       DURATION {
               let ctx = $lexer.get_context();
               parse_duration($lexer.span_str($span), ctx.get_attr("step")) 
       }
;

Generally to hope lexer has the ability to store context, Is there any way to do this?

ltratt commented 1 month ago

Does https://softdevteam.github.io/grmtools/master/book/actioncode.html#additional-parse-parameter help?

Taylor-lagrange commented 1 month ago

That is very helpful! Thank you, I am new to grmtools.

ltratt commented 1 month ago

Best of luck! I'll close this for now but feel free to reopen if this feature isn't sufficient.