class Gherkin::Parser::Parser
Public Class Methods
new(formatter, raise_on_error=true, machine_name='root', force_ruby=false, iso_code = 'en')
click to toggle source
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, iso_code = 'en') @formatter = formatter @listener = Listener::FormatterListener.new(@formatter) @raise_on_error = raise_on_error @machine_name = machine_name @machines = [] @lexer = Gherkin::Lexer::I18nLexer.new(self, force_ruby, iso_code) end
Public Instance Methods
errors()
click to toggle source
# File lib/gherkin/parser/parser.rb, line 43 def errors @lexer.errors end
event(ev, line)
click to toggle source
# File lib/gherkin/parser/parser.rb, line 55 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
expected()
click to toggle source
# File lib/gherkin/parser/parser.rb, line 79 def expected machine.expected end
force_state(state)
click to toggle source
# File lib/gherkin/parser/parser.rb, line 83 def force_state(state) machine.instance_variable_set('@state', state) end
i18n_language()
click to toggle source
# File lib/gherkin/parser/parser.rb, line 39 def i18n_language @lexer.i18n_language end
machine()
click to toggle source
# File lib/gherkin/parser/parser.rb, line 75 def machine @machines[-1] end
parse(gherkin, feature_uri, line_offset)
click to toggle source
# File lib/gherkin/parser/parser.rb, line 27 def parse(gherkin, feature_uri, line_offset) @formatter.uri(feature_uri) @line_offset = line_offset @feature_uri = feature_uri push_machine(@machine_name) begin @lexer.scan(gherkin) ensure pop_machine end end
pop_machine()
click to toggle source
# File lib/gherkin/parser/parser.rb, line 71 def pop_machine @machines.pop end
push_machine(name)
click to toggle source
# File lib/gherkin/parser/parser.rb, line 67 def push_machine(name) @machines.push(Machine.new(self, name)) end