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.
15
16
17
18
19
20
21
|
# 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
|
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
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/gherkin/parser/parser.rb', line 28
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
39
40
41
42
43
44
45
46
47
48
49
|
# 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 ⇒ Object
63
64
65
|
# File 'lib/gherkin/parser/parser.rb', line 63
def expected
machine.expected
end
|
#force_state(state) ⇒ Object
67
68
69
|
# File 'lib/gherkin/parser/parser.rb', line 67
def force_state(state)
machine.instance_variable_set('@state', state)
end
|
#location(uri, offset) ⇒ Object
23
24
25
|
# File 'lib/gherkin/parser/parser.rb', line 23
def location(uri, offset)
@listener.location(uri, offset)
end
|
#machine ⇒ Object
59
60
61
|
# File 'lib/gherkin/parser/parser.rb', line 59
def machine
@machines[-1]
end
|
#pop_machine ⇒ Object
55
56
57
|
# File 'lib/gherkin/parser/parser.rb', line 55
def pop_machine
@machines.pop
end
|
#push_machine(name) ⇒ Object
51
52
53
|
# File 'lib/gherkin/parser/parser.rb', line 51
def push_machine(name)
@machines.push(Machine.new(self, name))
end
|