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

Question about behavior of repetitions #381

Closed
MarcelBolten opened this issue Mar 10, 2023 · 1 comment · Fixed by #388
Closed

Question about behavior of repetitions #381

MarcelBolten opened this issue Mar 10, 2023 · 1 comment · Fixed by #388
Labels
blocks-release Blocks an imminent release. High Priorty.

Comments

@MarcelBolten
Copy link
Contributor

Hi all,

I think there is a discrepancy between the documentation for repetitions in conjunction with code blocks and results of preceding labeled expressions and the actual behavior.
In particular the statement

Any non-number values, returned by the code block, will be interpreted as 0.

seems to be wrong.
A grammar like:

start = text:"a"|{ return 'some string' }|

does not return a number and hence should be equivalent to

start = text:"a"|0|

However, the parser accepts infinite input of "a".

This is probably due to the following lines, in particular |0 and the operator precedence?:

case op.IF_LT_DYNAMIC: // IF_LT_DYNAMIC min, t, f
compileCondition(stack.top() + ".length < " + stack.index(bc[ip + 1]) + "|0", 1);
break;
case op.IF_GE_DYNAMIC: // IF_GE_DYNAMIC max, t, f
compileCondition(stack.top() + ".length >= " + stack.index(bc[ip + 1]) + "|0", 1);
break;

Any clarification is appreciated.

@Mingun
Copy link
Member

Mingun commented Mar 10, 2023

Yes, this is a bug. Need to wrap boundary|0 in parenthesis

@hildjj hildjj added the blocks-release Blocks an imminent release. High Priorty. label Mar 15, 2023
hildjj added a commit to hildjj/peggy that referenced this issue Mar 21, 2023
* main:
  Update deps, CHANGELOG, version.  Rebuild.
  Fix typos.  Move parens to correct place.
  Rebuilt patch from scratch, incorporating comments
  Update dependencies
  Remove --optimize.  Fixes peggyjs#392.
  --allowed-start-rule=\* documented for CLI.  Fixes peggyjs#386.
  Put parens around integer conversions in repetition.  Fixes peggyjs#381.
  Tweaking the error format() documentation
  Authors and small grammar fix
  Change silver to hex
  Update to node-inspect-extracted@2.0.2
  Update CHANGELOG
  Make online version work in old browsers.  Fixes peggyjs#371.
  Updating grammarSource documentation
  Add Marcel Bolten to authors
  Remove redundant options variants in behavior test
  Handle null and undefined explicitly
  Fixes peggyjs#374.  CLI was throwing exception on grammar errors without a CLI test also being specified.
  Stub out new CHANGELOG.md section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocks-release Blocks an imminent release. High Priorty.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants