Parent

Gherkin::Parser::Parser::Machine

Public Class Methods

new(parser, name) click to toggle source
    # File lib/gherkin/parser/parser.rb, line 86
86:         def initialize(parser, name)
87:           @parser = parser
88:           @name = name
89:           @transition_map = transition_map(name)
90:           @state = name
91:         end

Public Instance Methods

event(ev, line) click to toggle source
     # File lib/gherkin/parser/parser.rb, line 93
 93:         def event(ev, line)
 94:           states = @transition_map[@state]
 95:           raise "Unknown state: #{@state.inspect} for machine #{@name}" if states.nil?
 96:           new_state = states[ev]
 97:           case new_state
 98:           when "E"
 99:             yield @state, expected
100:           when /push\((.+)\)/
101:             @parser.push_machine($1)
102:             @parser.event(ev, line)
103:           when "pop()"
104:             @parser.pop_machine()
105:             @parser.event(ev, line)
106:           else
107:             raise "Unknown transition: #{ev.inspect} among #{states.inspect} for machine #{@name}" if new_state.nil?
108:             @state = new_state
109:           end
110:         end
expected() click to toggle source
     # File lib/gherkin/parser/parser.rb, line 112
112:         def expected
113:           allowed = @transition_map[@state].find_all { |_, action| action != "E" }
114:           allowed.collect { |state| state[0] }.sort - ['eof']
115:         end

Private Instance Methods

build_transition_map(name) click to toggle source
     # File lib/gherkin/parser/parser.rb, line 125
125:         def build_transition_map(name)
126:           table = transition_table(name)
127:           events = table.shift[1..1]
128:           table.inject({}) do |machine, actions|
129:             state = actions.shift
130:             machine[state] = Hash[*events.zip(actions).flatten]
131:             machine
132:           end
133:         end
transition_map(name) click to toggle source
     # File lib/gherkin/parser/parser.rb, line 121
121:         def transition_map(name)
122:           @@transition_maps[name] ||= build_transition_map(name)
123:         end
transition_table(name) click to toggle source
     # File lib/gherkin/parser/parser.rb, line 135
135:         def transition_table(name)
136:           state_machine_reader = StateMachineReader.new
137:           lexer = Gherkin::I18n.new('en').lexer(state_machine_reader)
138:           machine = File.dirname(__FILE__) + "/#{name}.txt"
139:           lexer.scan(File.read(machine))
140:           state_machine_reader.rows
141:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.