-
Notifications
You must be signed in to change notification settings - Fork 89
Make most lexer errors recoverable #204
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
Open
mikmart
wants to merge
21
commits into
tsoding:main
Choose a base branch
from
mikmart:lexer-recover
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+246
−160
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before: $ build/b tests/lexer_errors.b
INFO: Compiling files tests/lexer_errors.b ./libb/all.b ./libb/gas-x86_64-linux.b
tests/lexer_errors.b:5:5: LEXER ERROR: Empty character literal After, without peeking: $ build/b tests/lexer_errors.b
INFO: Compiling files tests/lexer_errors.b ./libb/all.b ./libb/gas-x86_64-linux.b
tests/lexer_errors.b:5:5: LEXER ERROR: Empty character literal
tests/lexer_errors.b:5:5: LEXER ERROR: Empty character literal
tests/lexer_errors.b:5:5: LEXER ERROR: Empty character literal
tests/lexer_errors.b:6:5: LEXER ERROR: Character literal contains more than two characters
tests/lexer_errors.b:6:5: LEXER ERROR: Character literal contains more than two characters
tests/lexer_errors.b:6:5: LEXER ERROR: Character literal contains more than two characters
tests/lexer_errors.b:9:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:9:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:9:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:10:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:10:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:10:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:13:7: LEXER ERROR: Unknown escape sequence starting with `f`
tests/lexer_errors.b:13:11: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:15: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:7: LEXER ERROR: Unknown escape sequence starting with `f`
tests/lexer_errors.b:13:11: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:15: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:7: LEXER ERROR: Unknown escape sequence starting with `f`
tests/lexer_errors.b:13:11: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:15: LEXER ERROR: Unknown escape sequence starting with `b` After, with peeking: $ build/b tests/lexer_errors.b
INFO: Compiling files tests/lexer_errors.b ./libb/all.b ./libb/gas-x86_64-linux.b
tests/lexer_errors.b:5:5: LEXER ERROR: Empty character literal
tests/lexer_errors.b:6:5: LEXER ERROR: Character literal contains more than two characters
tests/lexer_errors.b:9:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:10:5: LEXER ERROR: Integer literal overflow
tests/lexer_errors.b:13:7: LEXER ERROR: Unknown escape sequence starting with `f`
tests/lexer_errors.b:13:11: LEXER ERROR: Unknown escape sequence starting with `b`
tests/lexer_errors.b:13:15: LEXER ERROR: Unknown escape sequence starting with `b` |
This comment was marked as outdated.
This comment was marked as outdated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The idea is that when the lexer encounters an error it can tell the compiler whether compilation can continue or not based on the
Err
variant ofResult
rather than a simpleOption
:However there was a bad interaction with the backtracking we do in the compiler, which caused duplicate errors being reported when tokens were re-lexed. To avoid that, I implemented
peek_token()
and used it instead where possible.Closes #205.