ammar / regexp_parser

A regular expression parser library for Ruby
MIT License
143 stars 22 forks source link

Incorrect `#to_s` output for reluctant interval #16

Closed backus closed 8 years ago

backus commented 8 years ago
2.3.0 :504 > regex = /a{3}?/
 => /a{3}?/
2.3.0 :505 > Regexp::Parser.parse(regex).to_re == regex
 => false
2.3.0 :506 > Regexp::Parser.parse(regex).to_re
 => /a{3}/

It looks like the issue is the quantifier being set with incorrect text:

2.3.0 :508 > Regexp::Parser.parse(regex).first
 => #<Regexp::Expression::Literal:0x007fedbbdc4398 @type=:literal, @token=:literal, @text="a", @ts=0, @level=0, @set_level=0, @conditional_level=0, @options=nil, @quantifier=#<Regexp::Expression::Quantifier:0x007fedbbdc4118 @token=:interval, @text="{3}", @mode=:reluctant, @min=3, @max=3>>
2.3.0 :509 > Regexp::Parser.parse(regex).first.quantifier
 => #<Regexp::Expression::Quantifier:0x007fedbbd75608 @token=:interval, @text="{3}", @mode=:reluctant, @min=3, @max=3>
2.3.0 :510 > Regexp::Parser.parse(regex).first.quantifier.text
 => "{3}"