-
Notifications
You must be signed in to change notification settings - Fork 298
Custom parser errors #831
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
Comments
I'm a little unclear on what you mean here. Are you referring to the generics in the ParseError definition, L, T, E? Or do you mean the ParseError::User field? The ParseError generics are somewhat described here: https://docs.rs/lalrpop-util/0.12.1/lalrpop_util/enum.ParseError.html The User field is described pretty thoroughly here. There's of course always room for documentation improvement, but I'm not really clear on what you want to see improved here. Can you be more specific about what info you feel is missing from the docs that would be helpful? |
Oh, oops. I'm talking about fully custom parse errors. Like instead of this returning ParseError::UnrecognisedToken:
you can use the error recovery or something similar to make it UserError::MissedBracket. |
I think I'm getting closer to understanding you. Perhaps you're talking about one of these things?
|
I mean like instead of how its documented (errors on the action code) you can make errors if the parser fails, so you can have more descriptive errors. |
Can you point me at what specifically in the source you're looking at? I'm not finding whatever you see here.
So this is fundamentally a feature request for an ability for users to control ParseErrors? How do you envision this working?
Unless I'm missing something, this sounds like a separate unrelated request, in which case it should get its own issue to keep discussions straight. |
ParseError<L, T, E>
Each rule can add an attribute to the error with a more specific kind, depicting things like the rule it errored on, etc.
Alright, got it |
Okay, that generic is only used in the User field, which is fully documented in the "fallible actions" section of the book I've linked a few times. It sounds like your issue is that you don't want to use the User field via action code as it is documented, you'd like to augment it with more information about the parser grammar. Perhaps someone with more LR(1) knowledge than me will chime in with a better answer, but I think the fundamental issue around things like "which rule did it error out on?" is that the parser isn't necessarily parsing a particular rule. It has a stack of tokens encountered, and a collection of possible rules it could match. I'm guessing you're envisioning a situation like:
where we've seen The problem is that in the general case, could have:
etc. So if we've seen I suspect the cleanest answer here is to augment your parser so that you have cases for the expected cases you would like to have special errors for, and then use the fallible actions functionality to make special errors there. |
This conversation reminded me of http://moscova.inria.fr/~fpottier/menhir/manual.pdf#section.11. There has been some cool work on menhir which I think addresses this issue. Maybe there is a simplified version of what they do though(Some staticly known error messages which over approximate the set of possible errors that lead to it). I would imagine this would be a fair amount of work. |
How would I do what @emm312 suggested, and is supposed to be possible:
In this code for example:
I want to detect if the name ( I tried creating a "DefWindowName" rule:
But the issue here is, that it get's called multiple times. Let's take this input:
But the issue with that code is, that I can't recover from it in the parent, e.g. |
Here is how we do it in Nickel, not sure if that would fit your use-case, but it does seem so:
Here is an example of using this Doing so, you accumulate all the errors, and produce a valid AST as well. Then you can decide what to do with it. In theory you don't even need to accumulate the errors and can reconstruct the list from walking the AST, however if the AST is huge this can be costly to do so (and there might not even be a single error), so it's easier to just keep a duplicate list that is easily access 61F4 ible. |
Ive looked through the source and in the ParseError there is a generic for it, yet no docs.
Could this be documented or developed further?
The text was updated successfully, but these errors were encountered: