Class: RegularExpression::AST::Root
- Inherits:
-
Object
- Object
- RegularExpression::AST::Root
- Defined in:
- lib/regular_expression/ast.rb
Instance Attribute Summary collapse
-
#at_start ⇒ Object
readonly
bool.
- #expressions ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(expressions, at_start: false) ⇒ Root
constructor
A new instance of Root.
- #to_dot(graph) ⇒ Object
- #to_nfa ⇒ Object
Constructor Details
#initialize(expressions, at_start: false) ⇒ Root
Returns a new instance of Root.
17 18 19 20 |
# File 'lib/regular_expression/ast.rb', line 17 def initialize(expressions, at_start: false) @expressions = expressions @at_start = at_start end |
Instance Attribute Details
#at_start ⇒ Object (readonly)
bool
15 16 17 |
# File 'lib/regular_expression/ast.rb', line 15 def at_start @at_start end |
#expressions ⇒ Object (readonly)
14 15 16 |
# File 'lib/regular_expression/ast.rb', line 14 def expressions @expressions end |
Instance Method Details
#to_dot(graph) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/regular_expression/ast.rb', line 22 def to_dot(graph) label = "Root" label = "#{label} (at start)" if at_start node = graph.add_node(object_id, label: label) expressions.each { |expression| expression.to_dot(node) } end |
#to_nfa ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/regular_expression/ast.rb', line 30 def to_nfa start = NFA::StartState.new current = start if at_start current = NFA::State.new start.add_transition(NFA::Transition::BeginAnchor.new(current)) end finish = NFA::FinishState.new expressions.each do |expression| expression.to_nfa(current, finish) end start end |