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

Confusing error message for failed positive lookahead expression #640

Open
vsemozhetbyt opened this issue Feb 18, 2020 · 8 comments
Open

Comments

@vsemozhetbyt
Copy link

Issue type

  • Bug Report: yes
  • Feature Request: maybe
  • Question: no
  • Not an issue: no

Prerequisites

  • Can you reproduce the issue?: yes
  • Did you search the repository issues?: yes
  • Did you check the forums?: no (cannot find the URL)
  • Did you perform a web search (google, yahoo, etc)?: no (seems unneeded)

Description

Error message for failed positive lookahead expression does not mention this expression

Steps to Reproduce

Consider a rule where double hyphens are not allowed:

const pegResult = require('pegjs/')
  .generate('root = ([^-] / "-" !"-")+')
  .parse('a-b--c');

console.log(pegResult);

Expected behavior:

Something like: peg$SyntaxError: Expected "-" !"-", [^\-], or end of input but "--" found.

Actual behavior:

peg$SyntaxError: Expected "-", [^\-], or end of input but "-" found.

Software

  • PEG.js: 0.11.0-master.b7b87ea
  • Node.js: 14.0.0-v8-canary202002123546737a75
  • NPM or Yarn: npm 6.13.7
  • Browser: -
  • OS: Windows 7 x64
  • Editor: -
@StoneCypher
Copy link

Hi, I'm not very good at peg yet. I want to make sure I'm understanding this correctly.

It seems like what you're saying is "I have a rule where abcd is forbidden because d is disallowed as a lookahead in a rule about cd. When it complains, I'd prefer to hear about cd but I only hear about d."

Is that roughly correct?

@vsemozhetbyt
Copy link
Author

vsemozhetbyt commented Feb 19, 2020

I would rather say: "I have a rule where abcc is forbidden because c is disallowed as a lookahead for a c in a rule about abc. When it complains, I'd prefer to hear about cc but I only hear about c." Otherwise, the error message is not useful or clear: Expected "c"... but "c" found.

@StoneCypher
Copy link

StoneCypher commented Feb 19, 2020

Oh, the error message is confusing because the forbiddance is a repetition?

@vsemozhetbyt
Copy link
Author

vsemozhetbyt commented Feb 19, 2020

I would say the message is confusing because

  1. Expected and Found is the same in this case and
  2. the real cause of failure is not clear.

Maybe it would be useful to mention lookahead expressions if they are the cause of failure. Forbidden repetitions are just a case, compare this without a forbidden repetition.

const pegResult = require('pegjs/')
  .generate('root = ("a" / "b" !"a")+')
  .parse('aba');

console.log(pegResult);
peg$SyntaxError: Expected "a", "b", or end of input but "b" found.

@vsemozhetbyt
Copy link
Author

vsemozhetbyt commented Feb 19, 2020

Sorry, I am a bit clumsy, as I've just started to learn the PEG.

BTW, I've tried about dozen other parser generators (I am a newbie in this area) and this seems to be my favorite now)

@StoneCypher
Copy link

Yeah, peg's almost the only parser generator for javascript that I consider acceptable

Don't worry about being clumsy. We all are

@Mingun
Copy link
Contributor

Mingun commented Feb 20, 2020

@vsemozhetbyt, actually, you grammar should issue a info/warning at build stage, because it accept only inputs, which are accepted by grammar

root
  = "a"+ "b"*
  / "b"+

but compiler not (yet?) smart enough to infer that. I even don't know, may be it is NP-complete problem...

@StoneCypher
Copy link

the thing about np complete problems is that you can often still do a pretty decent job heuristically

if it's often right and never wrong, then it's a defacto improvement

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

No branches or pull requests

3 participants