Skip to content
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

Parser throw exception as soon as the parser doesn't find the expected element #87

Closed
yantang-msft opened this issue Aug 9, 2016 · 2 comments

Comments

@yantang-msft
Copy link

For a grammar like below, the expected input is "a b c d e f". And if I the input is like "a b c", the parser will tell me if failed to parse "rule" with the cursor pointing at column 1.
However, it would be better if it tell me it failed to find the "d" in rule2, and point the cursor at column 5.
rule = _ rule1 _ rule2 _ rule3 _ eof
rule1 = _ "a" _ "b" _
rule2 = _ "c" _ "d" _
rule3 = _ "e" _ "f" _
_ = [ \t\r\n]*
eof = !.

A workaround for now would be write the rule like this, but it can explode when the grammar is more complicated.
rule = _ rule1 _ rule2 _ rule3 _ eof
rule1 = _ ("a"/#error{"Expect a"} _ ("b"/#error{"Expect b"} _
...

@yantang-msft
Copy link
Author

Just a minor supplement.
If rule2 changed to _ "c" _ ("d")* _, then there can be multiple candidate token after "c". i.e., given the input "a b c", the return the error message is something like "Expect 'd' or 'e' at line 1 column 5".

@otac0n
Copy link
Owner

otac0n commented Nov 11, 2016

I'm combining this feedback with another item in #89.

@otac0n otac0n closed this as completed Nov 11, 2016
@otac0n otac0n removed this from the Unscheduled Non-breaking Change milestone Nov 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants