Class: Norikra::Query::ASTNode
- Inherits:
-
Object
- Object
- Norikra::Query::ASTNode
- Defined in:
- lib/norikra/query/ast.rb
Direct Known Subclasses
ASTEventPropNode, ASTLibFunctionNode, ASTSelectionElementNode, ASTStreamNode, ASTSubSelectNode
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #child ⇒ Object
- #fields(default_target = nil, known_targets_aliases = []) ⇒ Object
-
#find(type) ⇒ Object
only one, depth-first search.
-
#initialize(name, children) ⇒ ASTNode
constructor
A new instance of ASTNode.
-
#listup(type) ⇒ Object
search all nodes that has ‘type’.
- #nodetype?(*sym) ⇒ Boolean
- #to_a ⇒ Object
Constructor Details
#initialize(name, children) ⇒ ASTNode
Returns a new instance of ASTNode.
107 108 109 110 |
# File 'lib/norikra/query/ast.rb', line 107 def initialize(name, children) @name = name @children = children end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
105 106 107 |
# File 'lib/norikra/query/ast.rb', line 105 def children @children end |
#name ⇒ Object
Returns the value of attribute name.
105 106 107 |
# File 'lib/norikra/query/ast.rb', line 105 def name @name end |
Instance Method Details
#child ⇒ Object
120 121 122 |
# File 'lib/norikra/query/ast.rb', line 120 def child @children.first end |
#fields(default_target = nil, known_targets_aliases = []) ⇒ Object
146 147 148 |
# File 'lib/norikra/query/ast.rb', line 146 def fields(default_target=nil, known_targets_aliases=[]) @children.map{|c| c.nodetype?(:subquery) ? [] : c.fields(default_target, known_targets_aliases)}.reduce(&:+) || [] end |
#find(type) ⇒ Object
only one, depth-first search
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/norikra/query/ast.rb', line 124 def find(type) # only one, depth-first search return self if type.is_a?(String) && @name == type || nodetype?(type) @children.each do |c| next if type != :subquery && c.nodetype?(:subquery) r = c.find(type) return r if r end nil end |
#listup(type) ⇒ Object
search all nodes that has ‘type’
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/norikra/query/ast.rb', line 135 def listup(type) # search all nodes that has 'type' result = [] result.push(self) if type.is_a?(String) && @name == type || nodetype?(type) @children.each do |c| next if type != :subquery && c.nodetype?(:subquery) result.push(*c.listup(type)) end result end |
#nodetype?(*sym) ⇒ Boolean
112 113 114 |
# File 'lib/norikra/query/ast.rb', line 112 def nodetype?(*sym) false end |
#to_a ⇒ Object
116 117 118 |
# File 'lib/norikra/query/ast.rb', line 116 def to_a [@name] + @children.map{|c| c.children.size > 0 ? c.to_a : c.name} end |