Class: Gherkin::RbParser
- Inherits:
-
Object
show all
- Defined in:
- lib/gherkin/rb_parser.rb
Defined Under Namespace
Classes: Machine
Instance Method Summary
collapse
Constructor Details
#initialize(listener, raise_on_error, machine_name) ⇒ RbParser
Initialize the parser. machine_name
refers to a state machine table.
4
5
6
7
8
9
|
# File 'lib/gherkin/rb_parser.rb', line 4
def initialize(listener, raise_on_error, machine_name)
@listener = listener
@raise_on_error = raise_on_error
@machines = []
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
12
13
14
15
16
17
|
# File 'lib/gherkin/rb_parser.rb', line 12
def method_missing(method, *args)
if(event(method.to_s, args[-1]))
@listener.send(method, *args)
end
end
|
Instance Method Details
#event(ev, line) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/gherkin/rb_parser.rb', line 19
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
43
44
45
|
# File 'lib/gherkin/rb_parser.rb', line 43
def expected
machine.expected
end
|
#force_state(state) ⇒ Object
47
48
49
|
# File 'lib/gherkin/rb_parser.rb', line 47
def force_state(state)
machine.instance_variable_set('@state', state)
end
|
#machine ⇒ Object
39
40
41
|
# File 'lib/gherkin/rb_parser.rb', line 39
def machine
@machines[-1]
end
|
#pop_machine ⇒ Object
35
36
37
|
# File 'lib/gherkin/rb_parser.rb', line 35
def pop_machine
@machines.pop
end
|
#push_machine(name) ⇒ Object
31
32
33
|
# File 'lib/gherkin/rb_parser.rb', line 31
def push_machine(name)
@machines.push(Machine.new(self, name))
end
|