-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Make lexer produce Result<Token, Error> instead of Token. #273
Conversation
Remove the requirement of designating an error token. Remove the `#[error]` attribute. Using Result instead allows passing the error details downstream.
Hi! I implemented that change for myself, but I think it might be useful to upstream it because the previous discussion/implementation effort seems to have stalled |
Perhaps this would be better suited as an additional function to the maybe rewriting of the |
Hm, I think that would require introducing a second trait (TryLogos?) and changing the derive macro to require either an If you want to keep the previous behavior you could map the
Sure, that's a breaking change - it would have to be included in 0.13, not 0.12.2. And there will have to be a migration guide. |
You know, an alternative for this behavior without this PR.
I find the changes added to be unergonomic, and badly composed. Request for close. |
This is not at all an alternative. Once all information about the error has been discarded, it is impossible to recover it. There is no information associated with |
I'll do a proper review in a bit, really good job with this one. I was tempted to do an implementation that's backwards compatible somehow, but I also reckon that the "There should be one-- and preferably only one --obvious way to do it" rule should apply here. The only thing I'd change, sans of fixing conflicts (but that's my fault), is changing the default error type from With that in mind:
Per my comment from almost 3 years ago when I was pondering this (<insert existential dread of getting old>), this should yield no performance cost at all and actually improve ergonomics. Using |
I'll tackle the error type in subsequent PR. Also looking at tests I reckon we need a better way of setting up skips for whitespace, I reckon a good place to start would be an attribute on the token, so that instead of: enum Token {
#[regex(r"[ \t\n\f]+", logos::skip)]
Ignored,
// ...
} We could just do: #[logos(skip r"[ \t\n\f]+")]
enum Token {
// ...
} Or some such. Thanks again for the PR @agluszak, and apologies for getting to it so late. |
Remove the requirement of designating an error token. Remove the
#[error]
attribute.Using Result instead allows passing the error details downstream.
Closes #158. Closes #104.