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

Add minimum and maximum repetition rules #171

Merged
merged 5 commits into from
Jan 18, 2018

Conversation

scowcron
Copy link
Contributor

Currently, the .pest grammar files allowed the following repetition patterns:

  • a* - 0 or more
  • a+ - 1 or more
  • a{n} - exactly n
  • a{m,n} - from m to n

This PR adds two more forms:

  • a{,n} - up to n
  • a{n,} - at least n

This is largely syntactic sugar. Minimum matching can also be achieved using the pattern a{n} ~ a*, and maximum can be achieved using a{0,n} or a?{n}.

What the new forms bring to the table is a consistent, unified syntax for dealing with counted repetitions greater than 1.

Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Impeccable work! Should probably also rename unpack_repetitions to unroll_loops.

Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing apart from renaming the function: RepMin should also be added to the list of unbounded repetitions.

@scowcron
Copy link
Contributor Author

I'll be jumping on this in the next couple of days. Haven't looked too close to the validator code yet, but it definitely needs to address RepMin at a minimum.

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.

2 participants