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

Different errors returned when cache is enabled/disabled #452

Closed
dmajda opened this issue Aug 28, 2016 · 20 comments
Closed

Different errors returned when cache is enabled/disabled #452

dmajda opened this issue Aug 28, 2016 · 20 comments
Labels
Milestone

Comments

@dmajda
Copy link
Contributor

dmajda commented Aug 28, 2016

Grammar:

Statement
  = "{" __ !Statement Statement __ "}"
__
  = [ \t\r\n]*

Input:

{x}

With results cache disabled, the above produces this error:

Expected "{" or [ \t\r\n] but "x" found.

With results cache enabled, the error changes to:

Expected [ \t\r\n] but "x" found.

The errors should be the same in both cases.

Original report

@dmajda dmajda added the bug label Aug 28, 2016
@dmajda dmajda added this to the 0.11.0 milestone Aug 28, 2016
nikku added a commit to nikku/pegjs that referenced this issue Jan 14, 2018
@nikku
Copy link

nikku commented Jan 14, 2018

I'm relying on the quite expressive SyntaxErrors pegjs throws to build syntax completion for users.

However, this issue prevents me from doing that for more complicated grammars:

  • with cache enabled it suppresses possible matches
  • without cache, parsing slows down by magnitudes, making it unusable

@nikku
Copy link

nikku commented Jan 14, 2018

Another grammar for which the error applies:

Start
    = Char+ End

End
    = "e"

Char
    = (!End [a-z])+

Input:

a

With results cache disabled, the above produces this error:

Expected "e", [a-z], or not "e" but end of input found.

With results cache enabled, the error changes to:

Expected [a-z] but end of input found.

The cache disabled error is correct, as ae matches the grammar.

@nikku
Copy link

nikku commented Jan 14, 2018

Failing test cases added with #555

@nikku
Copy link

nikku commented Jan 16, 2018

The reason for this issue seems to be:

  • during initial evaluation of a rule, peg$expect is called to record expected tokens. In certain cases (peg$silentFails > 0) tokens are being ignored though.

  • during cached evaluation, the cached result is being restored. At this point the parser must not only restore the new parse state, it must replay relevant calls to peg$expect, too. Otherwise it misses out on expected tokens. This manifests in the incomplete error messages seen above.

In a local prototype based on pegjs@0.10 I was able to fix this issue by recording and replaying calls to peg$expect. However with the changes introduced in 669f782 this stuff got a lot more complicated.

I could attempt a fix for pegjs@dev. Just wondering if I'm heading in the right direction.

Any comments @Mingun, @futagoza?

@futagoza
Copy link
Member

Can you show me your local prototype based on pegjs@0.10?

nikku added a commit to nikku/pegjs that referenced this issue Jan 17, 2018
@nikku
Copy link

nikku commented Jan 17, 2018

You can have a look at a fix here.

@nikku
Copy link

nikku commented Jan 17, 2018

It does not work properly yet for nested silenced elements:

Grammar:

Start
  = Char+ End
End "end"
  = "e"
Char
  = !End [a-z]'

Input:

a

Expected Message:

Expected end, or [a-z] but end of input found.

Actual Message:

Expected end, "e", or [a-z] but end of input found.

Cf. failing test case.

@futagoza
Copy link
Member

futagoza commented Jan 18, 2018

@nikku This should be resolved now (thanks to you 🙇 ), with all 3 of the test cases passing (including the 3rd one for nested silenced elements).

The fix is present in the latest pegjs@dev release is just pushed to NPM, pegjs@0.11.0-dev.224 (https://github.com/pegjs/pegjs#latest).

@nikku
Copy link

nikku commented Jan 18, 2018

Thanks.

@nikku
Copy link

nikku commented Jan 18, 2018

I've tested your changes today.

From what I see f5b323b#diff-cd2c6b13fdcedf68a390c8bb6ea65cafR148 introduces a breaking change, as it effectively removes the peg$silentFails === 0 guard in with --no-cache generated parsers.

@futagoza
Copy link
Member

😨 oops, that was a stupid mistake. Gonna fix that soon, thanks for the heads up

@nikku
Copy link

nikku commented Jan 18, 2018

Tried to create a test case but failed 😢. I see that line having an impact on one of my more complicated grammars though.

@futagoza
Copy link
Member

futagoza commented Jan 18, 2018

Restored the guard in d06a5b5 and pushed the changes to pegjs@dev, tell me if this fixes the problem

@futagoza
Copy link
Member

@nikku Is it fixed, or are you still having this problem? Just want to know whether I should reopen this issue.

@nikku
Copy link

nikku commented Jan 24, 2018

It's fixed.

@StoneCypher
Copy link

@nikku - It's not fixed. Nothing was released. npm still has 0.10.0, and this was merged to a feature 0.11.0 branch that ryuu said is never actually going to be released

@nikku
Copy link

nikku commented Feb 3, 2020

I've stopped hoping for pegjs and looked elsewhere a long time ago for exactly this reason.

No release = no one can actually use it. Pegjs has been historically bad with releases.

@StoneCypher
Copy link

I am hoping to change the peg release cycle by:

  1. asking the original owner to allow me to re-cut a 0.12.0 from 0.10.0,
  2. to cherry pick and consistently rapid-release features from the now dead 0.11.0 branch,
  3. to remove the uncommon tools and configuration, in favor of a standard development setup, and
  4. to get the library in a place where adding features is easy for the community

If something like that happened, under any set of hands, and then releases actually started, would you give it another chance?

@nikku
Copy link

nikku commented Feb 3, 2020

Wish you the best of luck to accomplish that.

@StoneCypher
Copy link

thanks 😁

We'll see.

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

Successfully merging a pull request may close this issue.

4 participants