-
Notifications
You must be signed in to change notification settings - Fork 109
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
Strategy for erroring immediately upon hitting invalid path? #225
Comments
I'm assuming what you mean is that you want to report an error at the position of the |
Mm, not quite, because expected!() doesn't short circuit. I'd like for the parsing to stop immediately upon hitting that expected!(). Essentially, I am asking how one should go about forcing a single expected error once parsing has entered a rule, and not allow backtracking. |
Ah, you're describing the cut operator, which doesn't exist in What change in the reported error are you hoping to get from this? Assuming you have no further rules that can match the "(foo", the error position won't be bumped forward by anything else and the reported error will be the one inside the failing Improved error reporting features are definitely something I'm interested in pursuing. Another potentially relevant idea is labeled failures. |
I thought I might have been talking about a cut operator but I wasn't certain. 😄 Hmm, negative lookahead actually should be suitable for my use case, if I make a rule of those idents that should never be in that position. I'm basically implementing a Scheme with I plan to use some environment horrors to track spans to assist with error handling, so I'll let you know how my experiments pan out. |
I'm not sure if I should open a new issue for this, but I think it's related to this one. My problem is that in case I use For example, consider the following snippet from a parser for an indentation-sensitive language: /// Assert that the next token has no indentation
rule _()
= ![_] // ignore eof
/ p:position!() &[_] {?
if state.get_indentation(p).is_some() {
// terminal error - no other rule should match after this
return Err("invalid indentation")
}
Ok(())
}
rule expr() -> Expr
= precedence! {
// arithmetic ops, comparison ops, etc. omitted for brevity
---
// field access expression (e.g. `a.b`)
left:(@) _ [Op_Dot] _ key:ident() { ast::Expr::GetField(left, key) }
---
// <snip>
} Some code like a
.b will emit the following parse error (in the full parser):
When the relevant error is only I currently hack around this by prefixing the error with a string i know will not appear anywhere else, and only emitting |
Say I have a simple rule along the lines of
"(foo" _ <some other stuff>
, where I know that if any of the following parameters fail, that there's no other possible rule that could match, and wish to return a descriptive error for this invalid use of(foo
, what should I do?The text was updated successfully, but these errors were encountered: