-
Notifications
You must be signed in to change notification settings - Fork 22
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
More informative diagnostic messages for syntax errors in user input #35
Comments
@agentzh can you leave an example here? Maybe show a current error message you get, and then show what you would want it to be. |
@ingydotnet I'll use real examples to demonstrate the idea :) Firstly I'd use Parse::RecDescent for comparison because it gives contextual information with the rule names. Consider the following minimal and standalone Perl script: use Parse::RecDescent;
my $grammar = <<'_EOC_';
foo:
first
second
| <error>
first: 'a'
second:
bee
| cee
| <error>
bee: 'b'
cee: 'c'
_EOC_
Parse::RecDescent->new($grammar)->foo("ad"); Running the script gives:
And consider the following Pegex version: use Pegex;
my $grammar = <<'_EOC_';
foo:
first
second
first: 'a'
second:
| bee
| cee
bee: 'b'
cee: 'c'
_EOC_
pegex($grammar)->parse("ad") It gives
The Pegex version does give more detailed contextual info in the input string, but no contextual info in the grammar being applied (like related rule names "second", "bee", and "cee"). Maybe such additional hints can go to the "msg:" part? |
Wonderful example @agentzh !! I should be able to do this fairly easily. :) I might even be able to print a line #github url of the grammar rule involved! |
@ingydotnet Woot! |
Pegex has a wonder automatic error reporting feature for user input's syntax errors. What I've found could be a further improvement is an automatically generated hint like "expecting foo, bar, and baz instead" where
foo
,bar
, andbaz
are the related rule names automatically induced from the grammar.I know we already have the back-tick custom error message feature, but it quickly becomes a burden to add all the back-tick strings to large grammars.
Parse::RecDescent has limited support for such contextual hints. Hopefully Pegex can do even better than that :)
The text was updated successfully, but these errors were encountered: