-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
capture groups in lexers #4
Comments
Glad to hear that you've found RLTK useful. Do you mind if I ask what kind of project you are using this for? Currently there is no functionality in the Lexer class for accessing capture groups in a rule match. This is because you would usually emit multiple tokens in the lexer and then have a rule in the parser that would produce the desired AST node. Continuing your example, you would want to emit a PERIOD, STRING, and LBRACE token in separate rules and then have a production in your parser something like Another solution, which I'd be fine with implementing, is to make the match object available in the Lexer::Environment instance in which the productions are evaluated. Anyway, I hope that helps. |
Hm, okay, that kind of makes sense. I'm prototyping a shell language that relies heavily on whitespace-delimited expressions, so for example
is two expressions, while
is just one. Currently the lexer has a Exposing the match object in |
So I've just pushed some changes that give you access to the MatchData object inside the Lexer::Environment object through the Since whitespace has semantic meaning in your language I would still recommend emitting the P.S. How did you come across RLTK? I'm trying to promote it better and it would be good to know how people have found it so far. |
Good points all. I'll start emitting Thanks! |
Hey there.
This is awesome. I'm wondering if there's a way to get access to the groups captured by a particular rule's regex, as in
String#scan
. For example:Currently it looks like the block is being passed only the whole match. I'm happy to patch it to be more like the core ruby matching methods, but I wanted to check first :)
The text was updated successfully, but these errors were encountered: