module RegexpExamples::ParseRepeaterHelper

A collection of related helper methods, utilised by the ‘Parser` class

Protected Instance Methods

parse_plus_repeater(group) click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 12
def parse_plus_repeater(group)
  @current_position += 1
  parse_reluctant_or_possessive_repeater
  PlusRepeater.new(group)
end
parse_question_mark_repeater(group) click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 25
def parse_question_mark_repeater(group)
  @current_position += 1
  parse_reluctant_or_possessive_repeater
  QuestionMarkRepeater.new(group)
end
parse_range_repeater(group) click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 31
def parse_range_repeater(group)
  match = rest_of_string.match(/\A\{(\d+)?(,)?(\d+)?\}/)
  @current_position += match[0].size
  min = match[1].to_i if match[1]
  has_comma = !match[2].nil?
  max = match[3].to_i if match[3]
  repeater = RangeRepeater.new(group, min, has_comma, max)
  parse_reluctant_or_possessive_range_repeater(repeater, min, has_comma, max)
end
parse_reluctant_or_possessive_range_repeater(repeater, min, has_comma, max) click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 41
def parse_reluctant_or_possessive_range_repeater(repeater, min, has_comma, max)
  # .{1}? should be equivalent to (?:.{1})?, i.e. NOT a "non-greedy quantifier"
  if min && !has_comma && !max && next_char == '?'
    repeater = parse_question_mark_repeater(repeater)
  else
    parse_reluctant_or_possessive_repeater
  end
  repeater
end
parse_reluctant_or_possessive_repeater() click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 18
def parse_reluctant_or_possessive_repeater
  if next_char =~ /[?+]/
    # Don't treat these repeaters any differently when generating examples
    @current_position += 1
  end
end
parse_star_repeater(group) click to toggle source
# File lib/regexp-examples/parser_helpers/parse_repeater_helper.rb, line 6
def parse_star_repeater(group)
  @current_position += 1
  parse_reluctant_or_possessive_repeater
  StarRepeater.new(group)
end