-
Notifications
You must be signed in to change notification settings - Fork 22
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
Support informal delimiter literals #64
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great!
i've checked some more edge cases and found no issues. maybe we should add one example to spec/parser/quantifiers_spec.rb
to document that leading zeros are correctly ignored as in MRI:
include_examples 'quantifier', /a{004}+b/, '{004}+', :possessive, :interval, 4, 4
lib/regexp_parser/scanner/scanner.rl
Outdated
quantifier_exact = range_open . (digit+) . range_close . quantifier_mode?; | ||
quantifier_minimum = range_open . (digit+) . ',' . range_close . quantifier_mode?; | ||
quantifier_maximum = range_open . ',' . (digit+) . range_close . quantifier_mode?; | ||
quantifier_range = range_open . (digit+) . ',' . (digit+) . | ||
range_close . quantifier_mode?; | ||
|
||
quantifier_interval = quantifier_exact | quantifier_minimum | | ||
quantifier_maximum | quantifier_range; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly more concise:
quantifier_exact = range_open . (digit+) . range_close . quantifier_mode?; | |
quantifier_minimum = range_open . (digit+) . ',' . range_close . quantifier_mode?; | |
quantifier_maximum = range_open . ',' . (digit+) . range_close . quantifier_mode?; | |
quantifier_range = range_open . (digit+) . ',' . (digit+) . | |
range_close . quantifier_mode?; | |
quantifier_interval = quantifier_exact | quantifier_minimum | | |
quantifier_maximum | quantifier_range; | |
quantity_exact = (digit+); | |
quantity_minimum = (digit+) . ','; | |
quantity_maximum = ',' . (digit+); | |
quantity_range = (digit+) . ',' . (digit+); | |
quantifier_interval = range_open . ( quantity_exact | quantity_minimum | | |
quantity_maximum | quantity_range ) . range_close . | |
quantitfier_mode?; | |
but this is more a matter of taste, ragel probably optimises away the redundancy (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it a lot. The intention is clearer. There's a typo in the name of the mode pattern so I will make the change manually.
Thank you for the review. Very helpful.
Good call. I will add it. I will wrap this up and push out a new release (1.8) this afternoon. |
On second thought, I'll consider this a bug fix, and release as 1.7.1. |
Interprets the
{
,}
, and]
delimiters as literals depending on the context.Notes
quantifier_interval
pattern by replacing the optional matchers with 4 fixed patterns.premature_end_error
final state handler fromquantifier_interval
to permit valid literal sequences.Closes #63