Initialize the parser. machine_name
refers to a state machine
table.
# File lib/gherkin/parser/parser.rb, line 18 def initialize(formatter, raise_on_error=true, machine_name='root', force_ruby=false) @formatter = formatter @listener = Listener::FormatterListener.new(@formatter) @raise_on_error = raise_on_error @machine_name = machine_name @machines = [] push_machine(@machine_name) @lexer = Gherkin::Lexer::I18nLexer.new(self, force_ruby) end
# File lib/gherkin/parser/parser.rb, line 38 def errors @lexer.errors end
# File lib/gherkin/parser/parser.rb, line 53 def event(ev, line) l = line ? @line_offset+line : nil machine.event(ev, l) do |state, legal_events| if @raise_on_error raise ParseError.new(state, ev, legal_events, @feature_uri, l) else # Only used for testing @listener.syntax_error(state, ev, legal_events, @feature_uri, l) end end end
# File lib/gherkin/parser/parser.rb, line 77 def expected machine.expected end
# File lib/gherkin/parser/parser.rb, line 81 def force_state(state) machine.instance_variable_set('@state', state) end
# File lib/gherkin/parser/parser.rb, line 34 def i18n_language @lexer.i18n_language end
# File lib/gherkin/parser/parser.rb, line 73 def machine @machines[-1] end
Doesn't yet fall back to super
# File lib/gherkin/parser/parser.rb, line 43 def method_missing(method, *args) # TODO: Catch exception and call super event(method.to_s, args[-1]) @listener.__send__(method, *args) if method == :eof pop_machine push_machine(@machine_name) end end
# File lib/gherkin/parser/parser.rb, line 28 def parse(gherkin, feature_uri, line_offset) @formatter.uri(feature_uri) @line_offset = line_offset @lexer.scan(gherkin) end
# File lib/gherkin/parser/parser.rb, line 69 def pop_machine @machines.pop end
# File lib/gherkin/parser/parser.rb, line 65 def push_machine(name) @machines.push(Machine.new(self, name)) end