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

Bounded repetitions #46

Closed
goodmami opened this issue Jan 21, 2024 · 0 comments
Closed

Bounded repetitions #46

goodmami opened this issue Jan 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@goodmami
Copy link
Owner

A simple but useful extension is for bounded repetitions. The main issue is the syntax to use for it.
One obvious choice is {count} or {start,end} as in regex. A counterpoint to this is that {...} is used for semantic actions by some parsing frameworks, but I don't anticipate Pe using those.

The behavior would follow regular expressions. Example:

>>> pe.match(".{1,3}", "abcdefg")
<Match object; span=(0, 3), match='abc'>
>>> pe.match(".{2}", "abcdefg")
<Match object; span=(0, 2), match='ab'>
>>> pe.match(".{2,}", "abcdefg")
<Match object; span=(0, 7), match='abcdefg'>
>>> pe.match(".{,2}", "abcdefg")
<Match object; span=(0, 2), match='ab'>

In the {start,end} case, either operand can be omitted to indicate an open range, from 0 to infinity. Thus, .{,} is equivalent to .*, and .{1,} is equivalent to .+.

@goodmami goodmami added the enhancement New feature or request label Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant