-
Notifications
You must be signed in to change notification settings - Fork 20
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
Separate lexer utilities #579
Separate lexer utilities #579
Conversation
|
Based on #564 EDIT: As asked, this was split into supporting PRs (#579, #580, merged now), doesn't use the Error CST node anymore and only contains terminated-by recovery. To support error side-channel in a backtracking scenario, `Vec<ParseError>` was added to the `Stream` which serves more as a parse context now. To backtrack, we first record the position of the stream and how many errors are there; then, we reset the errors and the position to the first recorded `Marker` struct (basically copying what `chumsky` does). This wasn't changed everywhere as `Stream::set_position` in the lexer will never emit errors (only parsers do), nor will the optional trivia parsers. I'm happy to polish the lexer interface a bit to accommodate for this change later, if that's okay. First, I wanted to make sure the approach is fine and accepted, until we proceed with the DelimitedBy error recovery.
The 59645e6 change is unrelated but I hope it's simple enough that I can squeeze it in as well here.
This includes some smaller, some bigger refactorings while I worked on #567. I hope they are useful on their own and this will help with later work related to #567, as I'll need more lexer-related utilities (i.e. skipping or consuming until a token is found) and it got somewhat unwieldy when I left it in the language.tera.
Next up, I can separate lexer-related bits out of the language.tera into a dedicated lexer.tera that may contain
LexicalContext
(cc @AntonyBlakey wrt #567 (comment)) if if you think it's worthwhile.