Class: Resyma::Core::ParseTree
- Inherits:
-
Object
- Object
- Resyma::Core::ParseTree
- Defined in:
- lib/resyma/core/parsetree/definition.rb,
lib/resyma/parsetree.rb,
lib/resyma/core/parsetree/builder.rb,
lib/resyma/core/parsetree/traversal.rb
Overview
Parse tree with fields used by the matching algorithm
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#children ⇒ Object
Returns the value of attribute children.
-
#field ⇒ Object
Returns the value of attribute field.
-
#index ⇒ Object
Returns the value of attribute index.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Instance Method Summary collapse
- #build(parent = nil) ⇒ Object
- #clear! ⇒ Object
-
#depth_first_each {|A| ... } ⇒ nil
Depth-firstly traverse the tree.
-
#initialize(symbol, children, parent, index, is_leaf, ast = nil) ⇒ ParseTree
constructor
Create an instance of parse tree.
- #leaf? ⇒ Boolean
- #root? ⇒ Boolean
- #to_literal ⇒ Object
-
#to_ruby(bd = binding, filename = "(resyma)", lino = 1) ⇒ Object
Evaluate current parse tree using default evaluator.
Constructor Details
#initialize(symbol, children, parent, index, is_leaf, ast = nil) ⇒ ParseTree
Create an instance of parse tree
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/resyma/core/parsetree/definition.rb', line 51 def initialize(symbol, children, parent, index, is_leaf, ast = nil) @symbol = symbol @children = children @parent = parent @index = index @field = Field.clean_field @is_leaf = is_leaf @ast = ast @cache = {} end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def ast @ast end |
#cache ⇒ Object
Returns the value of attribute cache.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def cache @cache end |
#children ⇒ Object
Returns the value of attribute children.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def children @children end |
#field ⇒ Object
Returns the value of attribute field.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def field @field end |
#index ⇒ Object
Returns the value of attribute index.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def index @index end |
#parent ⇒ Object
Returns the value of attribute parent.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def parent @parent end |
#symbol ⇒ Object
Returns the value of attribute symbol.
35 36 37 |
# File 'lib/resyma/core/parsetree/definition.rb', line 35 def symbol @symbol end |
Instance Method Details
#build(parent = nil) ⇒ Object
6 7 8 9 |
# File 'lib/resyma/core/parsetree/builder.rb', line 6 def build(parent = nil) @parent = parent self end |
#clear! ⇒ Object
62 63 64 65 66 |
# File 'lib/resyma/core/parsetree/definition.rb', line 62 def clear! @field = Field.clean_field @cache = {} @children.each(&:clear!) unless leaf? end |
#depth_first_each {|A| ... } ⇒ nil
Depth-firstly traverse the tree
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/resyma/core/parsetree/traversal.rb', line 13 def depth_first_each(&block) yield self return if leaf? @children.each do |child| child.depth_first_each(&block) end nil end |
#leaf? ⇒ Boolean
72 73 74 |
# File 'lib/resyma/core/parsetree/definition.rb', line 72 def leaf? @is_leaf end |
#root? ⇒ Boolean
68 69 70 |
# File 'lib/resyma/core/parsetree/definition.rb', line 68 def root? @parent.nil? end |
#to_literal ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/resyma/parsetree.rb', line 154 def to_literal unless leaf? raise TypeError, "Cannot convert a non-leaf node(i.e. non-token) to literal" end children.first end |