Parent

Gherkin::Parser::Parser

Public Class Methods

new(listener, raise_on_error=true, machine_name='root') click to toggle source

Initialize the parser. machine_name refers to a state machine table.

# File lib/gherkin/parser/parser.rb, line 15
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

Public Instance Methods

event(ev, line) click to toggle source
# File lib/gherkin/parser/parser.rb, line 39
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
expected() click to toggle source
# File lib/gherkin/parser/parser.rb, line 63
def expected
  machine.expected
end
force_state(state) click to toggle source
# File lib/gherkin/parser/parser.rb, line 67
def force_state(state)
  machine.instance_variable_set('@state', state)
end
location(uri, offset) click to toggle source
# File lib/gherkin/parser/parser.rb, line 23
def location(uri, offset)
  @listener.location(uri, offset)
end
machine() click to toggle source
# File lib/gherkin/parser/parser.rb, line 59
def machine
  @machines[-1]
end
method_missing(method, *args) click to toggle source

Doesn’t yet fall back to super

# File lib/gherkin/parser/parser.rb, line 28
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
pop_machine() click to toggle source
# File lib/gherkin/parser/parser.rb, line 55
def pop_machine
  @machines.pop
end
push_machine(name) click to toggle source
# File lib/gherkin/parser/parser.rb, line 51
def push_machine(name)
  @machines.push(Machine.new(self, name))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.