class Gherkin::Parser::Parser
def event(ev, line)
def event(ev, line) machine.event(ev, line) do |state, expected| if @raise_on_error raise ParseError.new(state, ev, expected, line) else @listener.syntax_error(state, ev, expected, line) return false end end true end
def expected
def expected machine.expected end
def force_state(state)
def force_state(state) machine.instance_variable_set('@state', state) end
def initialize(listener, raise_on_error=true, machine_name='root')
def initialize(listener, raise_on_error=true, machine_name='root') @listener = listener @raise_on_error = raise_on_error @machines = [] @machine_name = machine_name push_machine(@machine_name) end
def machine
def machine @machines[-1] end
def method_missing(method, *args)
def method_missing(method, *args) # TODO: Catch exception and call super if(event(method.to_s, args[-1])) @listener.send(method, *args) end if method == :eof pop_machine push_machine(@machine_name) end end
def pop_machine
def pop_machine @machines.pop end
def push_machine(name)
def push_machine(name) @machines.push(Machine.new(self, name)) end