Class: Hoozuki::Node::Choice
- Inherits:
-
Object
- Object
- Hoozuki::Node::Choice
- Defined in:
- lib/hoozuki/node/choice.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
-
#initialize(children) ⇒ Choice
constructor
A new instance of Choice.
- #to_nfa(state) ⇒ Object
Constructor Details
#initialize(children) ⇒ Choice
Returns a new instance of Choice.
8 9 10 |
# File 'lib/hoozuki/node/choice.rb', line 8 def initialize(children) @children = children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/hoozuki/node/choice.rb', line 6 def children @children end |
Instance Method Details
#to_nfa(state) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hoozuki/node/choice.rb', line 12 def to_nfa(state) child_nfas = @children.map { |child| child.to_nfa(state) } start_state = state.new_state accepts = child_nfas.flat_map(&:accept).to_set nfa = Automaton::NFA.new(start_state, accepts) child_nfas.each do |child_nfa| nfa.merge_transitions(child_nfa) nfa.add_epsilon_transition(start_state, child_nfa.start) end nfa end |