Class: Treetop::Compiler::ParsingExpression

Inherits:
Runtime::SyntaxNode show all
Defined in:
lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb

Instance Attribute Summary collapse

Attributes inherited from Runtime::SyntaxNode

#input, #interval, #parent

Instance Method Summary collapse

Methods inherited from Runtime::SyntaxNode

#<=>, #dot_id, #elements, #empty?, #extension_modules, #initialize, #inspect, #inspect_children, #inspect_self, #nonterminal?, #terminal?, #text_value, #write_dot, #write_dot_file

Constructor Details

This class inherits a constructor from Treetop::Runtime::SyntaxNode

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



4
5
6
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 4

def address
  @address
end

#builderObject (readonly)

Returns the value of attribute builder.



4
5
6
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 4

def builder
  @builder
end

#parent_expressionObject (readonly)

Returns the value of attribute parent_expression.



4
5
6
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 4

def parent_expression
  @parent_expression
end

#subexpression_addressObject (readonly)

Returns the value of attribute subexpression_address.



4
5
6
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 4

def subexpression_address
  @subexpression_address
end

#var_symbolsObject (readonly)

Returns the value of attribute var_symbols.



4
5
6
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 4

def var_symbols
  @var_symbols
end

Instance Method Details

#accumulate_subexpression_resultObject



65
66
67
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 65

def accumulate_subexpression_result
  builder.accumulate accumulator_var, subexpression_result_var
end

#accumulator_varObject



45
46
47
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 45

def accumulator_var
  var(:accumulator)
end

#assign_failure(start_index_var) ⇒ Object



98
99
100
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 98

def assign_failure(start_index_var)
  assign_result("nil")
end

#assign_lazily_instantiated_nodeObject



102
103
104
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 102

def assign_lazily_instantiated_node
  assign_result("true")
end

#assign_result(value_ruby) ⇒ Object



69
70
71
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 69

def assign_result(value_ruby)
  builder.assign result_var, value_ruby
end

#begin_comment(expression) ⇒ Object



138
139
140
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 138

def begin_comment(expression)
  #builder << "# begin #{on_one_line(expression)}"
end

#compile(address, builder, parent_expression) ⇒ Object



6
7
8
9
10
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 6

def compile(address, builder, parent_expression)
  @address = address
  @builder = builder
  @parent_expression = parent_expression
end

#declared_module_nameObject



16
17
18
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 16

def declared_module_name
  parent_expression && parent_expression.node_class_name
end

#decorated?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 24

def decorated?
  parent_expression && (parent_expression.node_class_name || parent_expression.node_class_name || parent_expression.inline_module_name)
end

#end_comment(expression) ⇒ Object



142
143
144
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 142

def end_comment(expression)
  #builder << "# end #{on_one_line(expression)}"
end

#epsilon_nodeObject



94
95
96
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 94

def epsilon_node
  "instantiate_node(SyntaxNode,input, index...index)"
end

#expectedObject



150
151
152
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 150

def expected
  nil # Overridden for terminal parse failures
end

#extend_result(module_name) ⇒ Object



73
74
75
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 73

def extend_result(module_name)
  builder.extend result_var, module_name
end

#extend_result_with_declared_moduleObject



77
78
79
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 77

def extend_result_with_declared_module
  extend_result declared_module_name if declared_module_name
end

#extend_result_with_inline_module(parent_expression = nil) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 81

def extend_result_with_inline_module parent_expression = nil
  if parent_expression && parent_expression.parent_modules.size > 0
    parent_expression.parent_modules.each do |inline|
      extend_result inline.module_name
    end
  end
  extend_result inline_module_name if inline_module_name
end

#init_value(var_symbol) ⇒ Object



130
131
132
133
134
135
136
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 130

def init_value(var_symbol)
  case var_symbol
  when :accumulator then '[]'
  when :start_index then 'index'
  else nil
  end
end

#inline_module_nameObject



20
21
22
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 20

def inline_module_name
  parent_expression && parent_expression.inline_module_name
end

#node_class_nameObject



12
13
14
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 12

def node_class_name
  parent_expression && parent_expression.node_class_name || 'SyntaxNode'
end

#obtain_new_subexpression_addressObject



61
62
63
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 61

def obtain_new_subexpression_address
  @subexpression_address = builder.next_address
end

#on_one_line(expression) ⇒ Object



146
147
148
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 146

def on_one_line(expression)
  expression.text_value.tr("\n", ' ')
end

#optional_arg(arg) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 28

def optional_arg(arg)
  if arg
    ", #{arg}"
  else
    ''
  end
end

#reset_indexObject



90
91
92
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 90

def reset_index
  builder.assign '@index', start_index_var
end

#result_varObject



41
42
43
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 41

def result_var
  var(:result)
end

#start_index_varObject



49
50
51
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 49

def start_index_var
  var(:start_index)
end

#subexpression_result_varObject



53
54
55
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 53

def subexpression_result_var
  "r#{subexpression_address}"
end

#subexpression_success?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 57

def subexpression_success?
  subexpression_result_var
end

#use_vars(*var_symbols) ⇒ Object



36
37
38
39
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 36

def use_vars(*var_symbols)
  @var_symbols = var_symbols
  builder << var_initialization
end

#var(var_symbol) ⇒ Object



121
122
123
124
125
126
127
128
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 121

def var(var_symbol)
  case var_symbol
  when :result then "r#{address}"
  when :accumulator then "s#{address}"
  when :start_index then "i#{address}"
  else raise "Unknown var symbol #{var_symbol}."
  end
end

#var_initializationObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/puppet_x/wildfly/gems/treetop-1.6.8/lib/treetop/compiler/node_classes/parsing_expression.rb', line 106

def var_initialization
  left, right = [], []
  var_symbols.each do |symbol|
    if init_value(symbol)
      left << var(symbol)
      right << init_value(symbol)
    end
  end
  if left.empty?
    ""
  else
    left.join(', ') + ' = ' + right.join(', ')
  end
end