Class: Gherkin::RbParser::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/rb_parser.rb

Defined Under Namespace

Classes: StateMachineReader

Instance Method Summary collapse

Constructor Details

#initialize(parser, name) ⇒ Machine

Returns a new instance of Machine.



52
53
54
55
56
57
# File 'lib/gherkin/rb_parser.rb', line 52

def initialize(parser, name)
  @parser = parser
  @name = name
  @transition_map = transition_map(name)
  @state = name
end

Instance Method Details

#event(ev, line) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/gherkin/rb_parser.rb', line 59

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

#expectedObject



78
79
80
81
# File 'lib/gherkin/rb_parser.rb', line 78

def expected
  allowed = @transition_map[@state].find_all { |_, action| action != "E" }
  allowed.collect { |state| state[0] }.sort - ['eof']
end