Class: Treetop::Compiler::ParsingRule
- Inherits:
-
Runtime::SyntaxNode
show all
- Defined in:
- lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb
Instance Attribute Summary
#input, #interval, #parent
Instance Method Summary
collapse
#<=>, #dot_id, #elements, #empty?, #extension_modules, #initialize, #inspect, #inspect_children, #inspect_self, #nonterminal?, #terminal?, #text_value, #write_dot, #write_dot_file
Instance Method Details
#compile(builder) ⇒ Object
5
6
7
8
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 5
def compile(builder)
compile_inline_module_declarations(builder)
generate_method_definition(builder)
end
|
#compile_inline_module_declarations(builder) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 10
def compile_inline_module_declarations(builder)
parsing_expression.inline_modules.each_with_index do |inline_module, i|
inline_module.compile(i, builder, self)
builder.newline
end
end
|
#generate_cache_lookup(builder) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 34
def generate_cache_lookup(builder)
builder.if_ "node_cache[:#{name}].has_key?(index)" do
cache_address = "node_cache[:#{name}][index]"
builder.assign 'cached', cache_address
builder.if_ "cached" do
builder << "#{cache_address} = cached = SyntaxNode.new(input, index...(index + 1)) if cached == true"
builder << '@index = cached.interval.end'
end
builder << 'return cached'
end
end
|
#generate_cache_storage(builder, result_var) ⇒ Object
47
48
49
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 47
def generate_cache_storage(builder, result_var)
builder.assign "node_cache[:#{name}][start_index]", result_var
end
|
#generate_method_definition(builder) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 17
def generate_method_definition(builder)
builder.reset_addresses
expression_address = builder.next_address
result_var = "r#{expression_address}"
builder.method_declaration(method_name) do
builder.assign 'start_index', 'index'
generate_cache_lookup(builder)
builder.newline
parsing_expression.compile(expression_address, builder)
builder.newline
generate_cache_storage(builder, result_var)
builder.newline
builder << result_var
end
end
|
#method_name ⇒ Object
51
52
53
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 51
def method_name
"_nt_#{name}"
end
|
#name ⇒ Object
55
56
57
|
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_rule.rb', line 55
def name
nonterminal.text_value
end
|