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

Nonsense error messages, such as 'Line 1, column 3: Expected "a" but "a" found'. #119

Closed
chrisdew opened this issue Nov 5, 2012 · 6 comments
Labels
Milestone

Comments

@chrisdew
Copy link

chrisdew commented Nov 5, 2012

I keep coming across nonsense error messages with PEG.js, of the form:

Line 1, column 3: Expected "a" but "a" found.

when parsing bda.

Typically I see them when parsing text which begins with a parseable expression, but adds unneeded text onto the end.

A simple example is:

start
  = presingle single
  / preplural plural

presingle
  = "a"
  / "b"

preplural
  = "b"
  / "c"

single
  = "d"
  / "e"

plural
  = "dd"
  / "ee"

Could there be a more sane error message, such as 'too much text' instead?

Thanks,

Chris.

@chrisdew
Copy link
Author

chrisdew commented Nov 5, 2012

I think the correct error should be: Line 1, column 2: Expected "d" but "da" found.

@dmajda
Copy link
Contributor

dmajda commented Nov 8, 2012

@chrisdew I reduced the testcase further:

Grammar

start = "a" / "b"

Input

bc

With both 0.7.0 and the current development version, the error message is:

Line 1, column 2: Expected "a" but "c" found.

It should be:

Line 1, column 2: Expected end of input but "c" found.

When I change the grammar to:

start = "a" / "b" "d"?

the message changes to:

Line 1, column 2: Expected "d" but "c" found.

It should be:

Line 1, column 2: Expected "d" or end of input but "c" found.

In short — this is a valid bug and I'll fix it. Thanks for reporting it.

@chrisdew
Copy link
Author

chrisdew commented Nov 8, 2012

Thanks for writing this library, I look forward to a fix.

@chrisdew
Copy link
Author

chrisdew commented Oct 2, 2013

Hi, any news on this bug?

@dmajda dmajda closed this as completed in a56d3ac Dec 8, 2013
@dmajda
Copy link
Contributor

dmajda commented Dec 8, 2013

@chrisdew Sorry this took so long. I wanted to redesign the error reporting first. Once done, the fix (or rather, its core) was trivial.

@chrisdew
Copy link
Author

chrisdew commented Dec 8, 2013

@dmajda Thanks for the fix - I'll have a look soon.

andreineculau pushed a commit to for-GET/pegjs that referenced this issue Apr 17, 2014
In case the generated parser parsed successfully part of input and left
some input unparsed (trailing input), the error message produced was
sometimes wrong. The code worked correctly only if there were no match
failures in the successfully parsed part (highly unlikely).

This commit fixes things by explicitly triggering a match failure with the
following expectation at the end of the successfully parsed part of the
input:

  peg$fail({ type: "end", description: "end of input" });

This change also made it possible to simplify the |buildMessage|
function, which can now ignore the case of no expectations.

Fixes pegjs#119.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants