-
Notifications
You must be signed in to change notification settings - Fork 879
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
Add checkpoint logic for the parser #11441
Conversation
47ec6fe
to
dcab2ef
Compare
bfc513e
to
ecd5cb2
Compare
270d0d7
to
fe47dce
Compare
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
self.tokens.rewind(checkpoint.tokens); | ||
self.errors.truncate(checkpoint.errors_position); | ||
self.current_token_id = checkpoint.current_token_id; | ||
self.prev_token_end = checkpoint.prev_token_end; | ||
self.recovery_context = checkpoint.recovery_context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I like to use destructuring here. It adds a compile time guarantee that all fields are used (at the cost of a bit more code)
let ParserCheckpoint {
tokens,
errors_position,
prev_token_end,
recovery_context
} = checkpoint;
self.tokens.rewind(tokens);
self.errors.truncate(errors_position);
...
You can also do the destructuring right in the method signature, although it then becomes a bit hard to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I recently realized that with the amount of fields increasing in the lexer checkpoint and will be making the changes in a follow-up PR. Thanks for the recommendation.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
## Summary This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.
Summary
This PR adds the checkpoint logic to the parser and token source. It also updates the lexer checkpoint to contain the error position.