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

Issue 30 #209

Closed
wants to merge 16 commits into from
Closed

Issue 30 #209

wants to merge 16 commits into from

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Sep 20, 2013

Sorry fo my english, I hope, that it is not so bad...

I realize issue #30 -- feature for specify exact count an min-max range of repetitions of rule, optionally delimited by delimiter rule/expression. Delimiter not included in result. Syntax (, delimiter may be omitted):

expression |exact, delimiter|
expression |min.., delimiter|
expression |..max, delimiter|
expression |min..max, delimiter|
expression |.., delimiter|

Now all constraints -- a int in grammar, but bytecode not limited by this.

I add 2 opcodes to abstract VM: IF_ARRLEN_MIN and IF_ARRLEN_MAX.

New IF... opcodes use stack to get constraint and array and compiled to:

min = stack.pop();
if (typeof(min) !== "undefined" && stack.top().length < min) {
  <then code>
} else {
  <else code>
}

max = stack.pop();
if (typeof(max) !== "undefined" && stack.top().length >= max) {
  <then code>
} else {
  <else code>
}

@lavelle
Copy link

lavelle commented Nov 21, 2013

What's blocking this? Would be great to see it merged.

@Mingun
Copy link
Contributor Author

Mingun commented Jan 13, 2014

@dmajda , what you think about this? Now also included testcases and, I think, it may be merged...

@dmajda
Copy link
Contributor

dmajda commented Apr 27, 2014

What's blocking this? Would be great to see it merged.

@lavelle This is a pull request for a feature I clearly labeled as post-1.0.0, so it wasn't a high priority for me.

Now also included testcases and, I think, it may be merged...

@Mingun Sorry, I won't merge this, for several reasons:

@dmajda dmajda closed this Apr 27, 2014
Mingun added a commit to Mingun/pegjs that referenced this pull request May 17, 2014
…t syntax -- for this purpose there will be separate pull request. As the result -- doesn't contain tests, they will be together with syntax. However, all tests are passed.

Introduce two new opcodes:
* IF_ARRLEN_MIN min, then part length, else part length
* IF_ARRLEN_MAX max, then part length, else part length

Introduce new AST node -- `range`, that contains expression and the minimum and maximum number of its repetition.
If `node.min` is `null` or isn't positive -- check of the minimum length isn't made.
If `node.max` is `null`, check of the maximum length isn't made.

Unlike previous pull request (pegjs#209), there are:
* no logic for reduce range expression to `optional`, `zero or more` and `one or more` expressions -- this must be made by special compiler pass;
* lengths are hardcoded in bytecode, instead of are read from a stack;
* no support for delimiters -- they will be in next pull request.
@Mingun Mingun deleted the issue_30 branch May 17, 2014 19:23
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

Successfully merging this pull request may close these issues.

None yet

3 participants