AST class for representing operators in the query. An operator node has an operator and operands that are represented as AST child nodes. Usually, operator nodes have one or two children. For logical operators, a distinct subclass exists to implement some tree simplification rules.
# File lib/scoped_search/query_language/ast.rb, line 71 def initialize(operator, children, root_node = false) # :nodoc @operator = operator @children = children raise ScopedSearch::QueryNotSupported, "Empty list of operands" if @children.empty? && !root_node end
Returns a child node by index, starting with 0.
# File lib/scoped_search/query_language/ast.rb, line 121 def [](child_nr) children[child_nr] end
# File lib/scoped_search/query_language/ast.rb, line 106 def empty? children.length == 0 end
# File lib/scoped_search/query_language/ast.rb, line 89 def eql?(node) # :nodoc node.kind_of?(OperatorNode) && node.operator == operator && node.children.eql?(children) end
Returns true if this is an infix operator
# File lib/scoped_search/query_language/ast.rb, line 111 def infix? children.length > 1 end
Return the left-hand side (LHS) operand for this operator.
# File lib/scoped_search/query_language/ast.rb, line 94 def lhs raise ScopedSearch::Exception, "Operator does not have a LHS" if prefix? raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 children[0] end
Returns true if this is a prefix operator
# File lib/scoped_search/query_language/ast.rb, line 116 def prefix? children.length == 1 end
Return the right-hand side (RHS) operand for this operator.
# File lib/scoped_search/query_language/ast.rb, line 101 def rhs raise ScopedSearch::Exception, "Operators with more than 2 children do not have LHS/RHS" if children.length > 2 children.length == 1 ? children[0] : children[1] end
Generated with the Darkfish Rdoc Generator 2.