Class: Gherkin::Parser::Parser::Machine
- Inherits:
-
Object
- Object
- Gherkin::Parser::Parser::Machine
- Defined in:
- lib/gherkin/parser/parser.rb
Defined Under Namespace
Classes: StateMachineReader
Instance Method Summary collapse
- #event(ev, line) ⇒ Object
- #expected ⇒ Object
-
#initialize(parser, name) ⇒ Machine
constructor
A new instance of Machine.
Constructor Details
#initialize(parser, name) ⇒ Machine
Returns a new instance of Machine.
86 87 88 89 90 91 |
# File 'lib/gherkin/parser/parser.rb', line 86 def initialize(parser, name) @parser = parser @name = name @transition_map = transition_map(name) @state = name end |
Instance Method Details
#event(ev, line) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gherkin/parser/parser.rb', line 93 def event(ev, line) states = @transition_map[@state] raise "Unknown state: #{@state.inspect} for machine #{@name}" if states.nil? new_state = states[ev] case new_state when "E" yield @state, expected when /push\((.+)\)/ @parser.push_machine($1) @parser.event(ev, line) when "pop()" @parser.pop_machine() @parser.event(ev, line) else raise "Unknown transition: #{ev.inspect} among #{states.inspect} for machine #{@name}" if new_state.nil? @state = new_state end end |
#expected ⇒ Object
112 113 114 115 |
# File 'lib/gherkin/parser/parser.rb', line 112 def expected allowed = @transition_map[@state].find_all { |_, action| action != "E" } allowed.collect { |state| state[0] }.sort - ['eof'] end |