Class: SbuilderSexp::AbstactExpression
- Inherits:
-
Root
- Object
- Treetop::Runtime::SyntaxNode
- Root
- SbuilderSexp::AbstactExpression
- Defined in:
- lib/parser/parser_nodes.rb
Overview
Expression as a binary tree
Direct Known Subclasses
AbstractSetExpression, Expression, FieldBy, FunctionExpression, InfixExpression, OperatorExpression, ParenthesisExpression, PrefixExpression, RecordDefinition, RecordExcept, RecordField, SequenceExpression, SimpleExpression, UnitExpression
Instance Method Summary collapse
-
#expression_postfix ⇒ String
Non nil value to yield in post-order.
-
#expression_prefix ⇒ String
override in sub classes to make ‘traverse` method to yield `node_value` to block.
-
#expression_val ⇒ String
Non nil value to yield in in-order.
-
#expressions ⇒ AbstractExpression
Sub expressions in a binary tree.
- #has_rhs ⇒ Object
- #lhs_node ⇒ Object
-
#node_value ⇒ String|Integer|etc
From sub-classes with applicable value.
- #rhs_node ⇒ Object
-
#traverse(memo = "", &blk) ⇒ Object
walk down binary tree for the expresssion, and yield ‘expression_prefix’, ‘expxression_val’, and ‘expression_postfix’.
Methods inherited from Treetop::Runtime::SyntaxNode
#node_type, #recursive_inject, #recursive_inject_parent, #recursive_select, #value
Instance Method Details
#expression_postfix ⇒ String
Returns non nil value to yield in post-order.
141 142 143 |
# File 'lib/parser/parser_nodes.rb', line 141 def expression_postfix nil end |
#expression_prefix ⇒ String
override in sub classes to make ‘traverse` method to yield `node_value` to block. Block may use `node_value`, or use `node_type` to determine, how to access AST properties on `node`
131 132 133 |
# File 'lib/parser/parser_nodes.rb', line 131 def expression_prefix nil end |
#expression_val ⇒ String
Returns non nil value to yield in in-order.
136 137 138 |
# File 'lib/parser/parser_nodes.rb', line 136 def expression_val nil end |
#expressions ⇒ AbstractExpression
Returns sub expressions in a binary tree.
107 108 109 110 111 112 |
# File 'lib/parser/parser_nodes.rb', line 107 def expressions # expressions = recursive_select( SbuilderSexp::AbstactExpression ) expressions = elements && elements.select { |e| e.is_a?( SbuilderSexp::AbstactExpression ) } # raise "Parser error - compound expression should build binary tree" if expressions && expressios.length >2 end |
#has_rhs ⇒ Object
114 115 116 |
# File 'lib/parser/parser_nodes.rb', line 114 def has_rhs expressions && expressions.length > 1 end |
#lhs_node ⇒ Object
118 119 120 |
# File 'lib/parser/parser_nodes.rb', line 118 def lhs_node expressions && expressions[0] end |
#node_value ⇒ String|Integer|etc
Returns from sub-classes with applicable value.
102 103 104 |
# File 'lib/parser/parser_nodes.rb', line 102 def node_value expression_val end |
#rhs_node ⇒ Object
122 123 124 |
# File 'lib/parser/parser_nodes.rb', line 122 def rhs_node expressions[1] end |
#traverse(memo = "", &blk) ⇒ Object
walk down binary tree for the expresssion, and yield ‘expression_prefix’, ‘expxression_val’, and ‘expression_postfix’
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/parser/parser_nodes.rb', line 150 def traverse( memo="", &blk ) memo = yield memo, node_type, self, expression_prefix if blk && expression_prefix memo = lhs_node.traverse( memo, &blk ) if lhs_node memo = yield memo, node_type, self, expression_val if blk && expression_val memo = rhs_node.traverse( memo, &blk ) if has_rhs memo = yield memo, node_type, self, expression_postfix if blk && expression_postfix memo end |