-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
libsyntax: Simplify libsyntax lexer #66214
Conversation
What's the difference between "verification" and "validation" here? I don't immediately see why this is a simplification and wouldn't want to make changes to this (already recently rewritten) code without having some clear goal. If some code takes an already prepared error type (like If some code simultaneously produces and reports a (usually non-fatal) error and skips the error type, then it can be kept in some |
Could you also remove the rustfmt changes? |
☔ The latest upstream changes (presumably #65324) made this pull request unmergeable. Please resolve the merge conflicts. |
Regarding the motivation/purpose of the PR: well, as I said above, most of the checks are pretty trivial and the following code: self.verify_float_exponent_not_empty(start, empty_exponent);
self.verify_float_base(start, suffix_start, base); gives you exactly the same information as the if empty_exponent {
let mut err = self.struct_span_fatal(
start, self.pos,
"expected at least one digit in exponent"
);
err.emit();
}
match base {
Base::Hexadecimal => {
self.err_span_(start, suffix_start,
"hexadecimal float literal is not supported")
}
Base::Octal => {
self.err_span_(start, suffix_start,
"octal float literal is not supported")
}
Base::Binary => {
self.err_span_(start, suffix_start,
"binary float literal is not supported")
}
_ => ()
} Since none of the touched methods are public, IMO it makes sense to encapsulate those checks just for reader to be able to focus on the logic of parsing instead of logic of the error reporting. Regarding the Regarding the whole PR: it seems that I won't be able to work on this at least for this whole week, so I close it and open a new one when I'll have the time to implement it properly. |
tl;dr
This PR introduces 2 new modules in
libsyntax
lexer:literal_validation
andverification
. Those modules encapsulate most of the tokens validity checks and error reporting.This PR is completely cosmetic and does not introduce any new approaches in the lexer logic.
Motivation:
Most of checks performed in the lexer are trivial and mostly consist of checking some condition and reporting an error. Thus, IMHO it makes sense to extract them in the separate module, so the logic of the main module will become more declarative and parsing will not me mixed up with error reporting.
r? @petrochenkov
cc @matklad