Class: RegularExpression::AST::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/regular_expression/ast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, quantifier: Quantifier::Once.new) ⇒ Match

Returns a new instance of Match.



98
99
100
101
# File 'lib/regular_expression/ast.rb', line 98

def initialize(item, quantifier: Quantifier::Once.new)
  @item = item
  @quantifier = quantifier
end

Instance Attribute Details

#itemObject (readonly)

CharacterGroup | CharacterClass | Character | Period



95
96
97
# File 'lib/regular_expression/ast.rb', line 95

def item
  @item
end

#quantifierObject (readonly)

Quantifier



96
97
98
# File 'lib/regular_expression/ast.rb', line 96

def quantifier
  @quantifier
end

Instance Method Details

#to_dot(parent) ⇒ Object



103
104
105
106
107
108
# File 'lib/regular_expression/ast.rb', line 103

def to_dot(parent)
  node = parent.add_node(object_id, label: "Match")

  item.to_dot(node)
  quantifier.to_dot(node)
end

#to_nfa(start, finish) ⇒ Object



110
111
112
113
114
# File 'lib/regular_expression/ast.rb', line 110

def to_nfa(start, finish)
  quantifier.quantify(start, finish) do |qstart, qfinish|
    item.to_nfa(qstart, qfinish)
  end
end