lib/regexp-examples/parser.rb in regexp-examples-1.0.2 vs lib/regexp-examples/parser.rb in regexp-examples-1.1.0

- old
+ new

@@ -1,27 +1,22 @@ module RegexpExamples IllegalSyntaxError = Class.new(StandardError) class Parser attr_reader :regexp_string - def initialize(regexp_string, regexp_options, config_options={}) + def initialize(regexp_string, regexp_options) @regexp_string = regexp_string @ignorecase = !(regexp_options & Regexp::IGNORECASE).zero? @multiline = !(regexp_options & Regexp::MULTILINE).zero? @extended = !(regexp_options & Regexp::EXTENDED).zero? @num_groups = 0 @current_position = 0 - ResultCountLimiters.configure!( - config_options[:max_repeater_variance], - config_options[:max_group_results] - ) end def parse repeaters = [] - while @current_position < regexp_string.length + until end_of_regexp group = parse_group(repeaters) - break if group.is_a? MultiGroupEnd if group.is_a? OrGroup return [OneTimeRepeater.new(group)] end @current_position += 1 repeaters << parse_repeater(group) @@ -33,12 +28,10 @@ def parse_group(repeaters) case next_char when '(' group = parse_multi_group - when ')' - group = parse_multi_end_group when '[' group = parse_char_group when '.' group = parse_dot_group when '|' @@ -239,14 +232,10 @@ @multiline = false if (off.include? "m") @extended = true if (on.include? "x") @extended = false if (off.include? "x") end - def parse_multi_end_group - MultiGroupEnd.new - end - def parse_char_group @current_position += 1 # Skip past opening "[" chargroup_parser = ChargroupParser.new(rest_of_string) parsed_chars = chargroup_parser.result @current_position += (chargroup_parser.length - 1) # Step back to closing "]" @@ -342,9 +331,13 @@ regexp_string[@current_position..-1] end def next_char regexp_string[@current_position] + end + + def end_of_regexp + next_char == ")" || @current_position >= regexp_string.length end end end