-
Notifications
You must be signed in to change notification settings - Fork 31
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
Implement std::error::Error for lrpar::lex::Lexeme<T> #126
Comments
I'm not sure about this: I think it will confuse people, partly because Integer -> Result<i32, ()>:
"INT" {
let v = $1.map_err(|_| ())?;
...
}
; In other words, as soon as I encounter an inserted token for "something that matters", I stop evaluation (but don't bother reporting the reason why to the user, as I find that it's generally obvious from the syntax errors they will also have received). That said, in your grammar file, could you not implement |
Correct, that does not work, unfortunately: error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
| impl<T> std::error::Error for lrpar::lex::Lexeme<T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------
| | |
| | `lrpar::lex::Lexeme` is not defined in the current crate
| impl doesn't use only types from inside the current crate That being said, I haven't looked at the error handling / recovery of grmtools yet, because currently I get plain unrecoverable I'll try to find out the cause for that, because eventually I also want to report nice errors with locations in the parser input to the user. I don't have time for that right now, but I'll come back to this when I finished the core part of my project where I use grmtools. |
That doesn't sound good! If that's a bug in grmtools, please report it back here! |
After reading the Rust guidelines for publishing crates I thought of this issue again. Due to the orphaning rules for implementing traits, they recommend eagerly implementing |
161: impl Error on Lexeme. r=ptersilie a=ltratt This can make some idioms in .y files easier. @pablosichert Does this do what you were asking for in #126 (comment)? I'd like to know for sure that it helps before we consider merging this! Co-authored-by: Laurence Tratt <laurie@tratt.net>
It would be nice if
std::error::Error
was implemented forlrpar::lex::Lexeme<T>
.That way, if we're in the context of a
-> Result<T, Box<dyn std::error::Error>>
function, we can doinstead of
In context:
$1
is of typeResult<Lexeme<u32>, Lexeme<u32>>
in the generated code.The text was updated successfully, but these errors were encountered: