Object
Initialize the parser. machine_name refers to a state machine table.
# File lib/gherkin/parser/parser.rb, line 18
18: def initialize(formatter, raise_on_error=true, machine_name='root', force_ruby=false)
19: @formatter = formatter
20: @listener = Listener::FormatterListener.new(@formatter)
21: @raise_on_error = raise_on_error
22: @machine_name = machine_name
23: @machines = []
24: push_machine(@machine_name)
25: @lexer = Gherkin::Lexer::I18nLexer.new(self, force_ruby)
26: end
# File lib/gherkin/parser/parser.rb, line 38
38: def errors
39: @lexer.errors
40: end
# File lib/gherkin/parser/parser.rb, line 53
53: def event(ev, line)
54: l = line ? @line_offset+line : nil
55: machine.event(ev, l) do |state, legal_events|
56: if @raise_on_error
57: raise ParseError.new(state, ev, legal_events, @feature_uri, l)
58: else
59: # Only used for testing
60: @listener.syntax_error(state, ev, legal_events, @feature_uri, l)
61: end
62: end
63: end
# File lib/gherkin/parser/parser.rb, line 77
77: def expected
78: machine.expected
79: end
# File lib/gherkin/parser/parser.rb, line 81
81: def force_state(state)
82: machine.instance_variable_set('@state', state)
83: end
# File lib/gherkin/parser/parser.rb, line 34
34: def i18n_language
35: @lexer.i18n_language
36: end
# File lib/gherkin/parser/parser.rb, line 73
73: def machine
74: @machines[1]
75: end
Doesn’t yet fall back to super
# File lib/gherkin/parser/parser.rb, line 43
43: def method_missing(method, *args)
44: # TODO: Catch exception and call super
45: event(method.to_s, args[1])
46: @listener.__send__(method, *args)
47: if method == :eof
48: pop_machine
49: push_machine(@machine_name)
50: end
51: end
# File lib/gherkin/parser/parser.rb, line 28
28: def parse(gherkin, feature_uri, line_offset)
29: @formatter.uri(feature_uri)
30: @line_offset = line_offset
31: @lexer.scan(gherkin)
32: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.