Class: Gherkin::Parser::Parser
- Inherits:
-
Object
- Object
- Gherkin::Parser::Parser
show all
- Defined in:
- lib/gherkin/parser/parser.rb
Defined Under Namespace
Classes: Machine
Instance Method Summary
collapse
Constructor Details
#initialize(listener, raise_on_error = true, machine_name = 'root') ⇒ Parser
Initialize the parser. machine_name
refers to a state machine table.
14
15
16
17
18
19
20
|
# File 'lib/gherkin/parser/parser.rb', line 14
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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Doesn’t yet fall back to super
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/gherkin/parser/parser.rb', line 23
def method_missing(method, *args)
if(event(method.to_s, args[-1]))
@listener.send(method, *args)
end
if method == :eof
pop_machine
push_machine(@machine_name)
end
end
|
Instance Method Details
#event(ev, line) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gherkin/parser/parser.rb', line 34
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 ⇒ Object
58
59
60
|
# File 'lib/gherkin/parser/parser.rb', line 58
def expected
machine.expected
end
|
#force_state(state) ⇒ Object
62
63
64
|
# File 'lib/gherkin/parser/parser.rb', line 62
def force_state(state)
machine.instance_variable_set('@state', state)
end
|
#machine ⇒ Object
54
55
56
|
# File 'lib/gherkin/parser/parser.rb', line 54
def machine
@machines[-1]
end
|
#pop_machine ⇒ Object
50
51
52
|
# File 'lib/gherkin/parser/parser.rb', line 50
def pop_machine
@machines.pop
end
|
#push_machine(name) ⇒ Object
46
47
48
|
# File 'lib/gherkin/parser/parser.rb', line 46
def push_machine(name)
@machines.push(Machine.new(self, name))
end
|