Class: RegularExpression::AST::Group

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expressions, quantifier: Quantifier::Once.new) ⇒ Group

Returns a new instance of Group.



75
76
77
78
# File 'lib/regular_expression/ast.rb', line 75

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

Instance Attribute Details

#expressionsObject (readonly)



72
73
74
# File 'lib/regular_expression/ast.rb', line 72

def expressions
  @expressions
end

#quantifierObject (readonly)

Quantifier



73
74
75
# File 'lib/regular_expression/ast.rb', line 73

def quantifier
  @quantifier
end

Instance Method Details

#to_dot(parent) ⇒ Object



80
81
82
83
84
85
# File 'lib/regular_expression/ast.rb', line 80

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

  expressions.each { |expression| expression.to_dot(node) }
  quantifier.to_dot(node)
end

#to_nfa(start, finish) ⇒ Object



87
88
89
90
91
# File 'lib/regular_expression/ast.rb', line 87

def to_nfa(start, finish)
  quantifier.quantify(start, finish) do |qstart, qfinish|
    expressions.each { |expression| expression.to_nfa(qstart, qfinish) }
  end
end