Class: RegexpExamples::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/regexp-examples/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp_string, regexp_options) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
# File 'lib/regexp-examples/parser.rb', line 5

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
end

Instance Attribute Details

#regexp_stringObject (readonly)

Returns the value of attribute regexp_string.



4
5
6
# File 'lib/regexp-examples/parser.rb', line 4

def regexp_string
  @regexp_string
end

Instance Method Details

#parseObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/regexp-examples/parser.rb', line 14

def parse
  repeaters = []
  until end_of_regexp
    group = parse_group(repeaters)
    if group.is_a? OrGroup
      return [OneTimeRepeater.new(group)]
    end
    @current_position += 1
    repeaters << parse_repeater(group)
  end
  repeaters
end