@@ -15,7 +15,7 @@ def parse
1515 repeaters = [ ]
1616 until end_of_regexp
1717 group = parse_group ( repeaters )
18- return [ OneTimeRepeater . new ( group ) ] if group . is_a? OrGroup
18+ return [ group ] if group . is_a? OrGroup
1919 @current_position += 1
2020 repeaters << parse_repeater ( group )
2121 end
@@ -148,7 +148,7 @@ def parse_after_backslash_group
148148 ) # Using "\r\n" as one character is little bit hacky...
149149 when next_char == 'g' # Subexpression call
150150 fail IllegalSyntaxError ,
151- 'Subexpression calls (\\g) cannot be supported, as they are not regular'
151+ 'Subexpression calls (\\g) cannot be supported, as they are not regular'
152152 when next_char =~ /[bB]/ # Anchors
153153 raise_anchors_exception!
154154 when next_char =~ /[AG]/ # Start of string
@@ -159,6 +159,7 @@ def parse_after_backslash_group
159159 end
160160 when next_char =~ /[zZ]/ # End of string
161161 if @current_position == ( regexp_string . length - 1 )
162+ # TODO: /\Z/ should be treated as /\n?/
162163 group = PlaceHolderGroup . new
163164 else
164165 raise_anchors_exception!
@@ -212,10 +213,10 @@ def parse_multi_group
212213 end
213214 when %w( ! = ) . include? ( match [ 2 ] ) # e.g. /(?=lookahead)/, /(?!neglookahead)/
214215 fail IllegalSyntaxError ,
215- 'Lookaheads are not regular; cannot generate examples'
216+ 'Lookaheads are not regular; cannot generate examples'
216217 when %w( ! = ) . include? ( match [ 3 ] ) # e.g. /(?<=lookbehind)/, /(?<!neglookbehind)/
217218 fail IllegalSyntaxError ,
218- 'Lookbehinds are not regular; cannot generate examples'
219+ 'Lookbehinds are not regular; cannot generate examples'
219220 else # e.g. /(?<name>namedgroup)/
220221 @current_position += ( match [ 3 ] . length + 3 )
221222 group_id = match [ 3 ]
@@ -237,12 +238,14 @@ def remember_old_regexp_options
237238 end
238239
239240 def regexp_options_toggle ( on , off )
240- @ignorecase = true if on . include? 'i'
241- @ignorecase = false if off . include? 'i'
242- @multiline = true if on . include? 'm'
243- @multiline = false if off . include? 'm'
244- @extended = true if on . include? 'x'
245- @extended = false if off . include? 'x'
241+ regexp_option_toggle ( on , off , '@ignorecase' , 'i' )
242+ regexp_option_toggle ( on , off , '@multiline' , 'm' )
243+ regexp_option_toggle ( on , off , '@extended' , 'x' )
244+ end
245+
246+ def regexp_option_toggle ( on , off , var , char )
247+ instance_variable_set ( var , true ) if on . include? char
248+ instance_variable_set ( var , false ) if off . include? char
246249 end
247250
248251 def parse_char_group
@@ -327,7 +330,7 @@ def parse_reluctant_or_possessive_range_repeater(repeater, min, has_comma, max)
327330
328331 def raise_anchors_exception!
329332 fail IllegalSyntaxError ,
330- "Anchors ('#{ next_char } ') cannot be supported, as they are not regular"
333+ "Anchors ('#{ next_char } ') cannot be supported, as they are not regular"
331334 end
332335
333336 def parse_one_time_repeater ( group )
0 commit comments