class Yadriggy::ASTnode
The common ancestor class of AST nodes.
Attributes
@return [ASTnode] the parent node.
The user type (or non-terminal symbol) corresponding to this node. This is effective only after checking syntax by {Syntax#check}.
@return [Symbol|nil] the user type.
Public Instance Methods
@param [ASTnode] node adds a child node. @return [void]
# File lib/yadriggy/ast.rb, line 57 def add_child(node) node.parent = self unless node.nil? end
@param [Array<ASTnode>] nodes adds child nodes. @return [void]
# File lib/yadriggy/ast.rb, line 63 def add_children(nodes) nodes.map {|e| e.parent = self unless e.nil? } end
The value of the name represented by this AST node if the value is immutable. Otherwise, {Yadriggy::Undef}.
# File lib/yadriggy/ast_value.rb, line 11 def const_value() Undef end
The immutable value of the name represented by this AST node when it is evaluated in the context of `clazz`. If the value is mutable, {Yadriggy::Undef}.
@param [Module] clazz the context.
# File lib/yadriggy/ast_value.rb, line 18 def const_value_in_class(clazz) const_value end
Gets the class including this AST node. @return [Module] the context.
# File lib/yadriggy/ast_value.rb, line 35 def get_context_class c = root.context if c.is_a?(Proc) c.binding.receiver.class else # c is Method or UnboundMethod c.owner end end
Gets the receiver object. @return [Object] the receiver object that this proc or method
is bound to.
# File lib/yadriggy/ast_value.rb, line 47 def get_receiver_object c = root.context if c.is_a?(Proc) c.binding.receiver elsif c.is_a?(Method) c.receiver else nil end end
Checks whether the object is a `Proc` or a method. @param [Object] p the tested object. @return [Booelan] true if `p` is a `Proc`, `Method`, or lambda object.
# File lib/yadriggy/ast_value.rb, line 61 def is_proc?(p) p.is_a?(Proc) || p.is_a?(Method) end
Overrides the printer printer.
# File lib/yadriggy/ast.rb, line 51 def pretty_print(pp) Yadriggy::simpler_pretty_print(pp, self, '@parent') end
@return [ASTnode] the root node.
# File lib/yadriggy/ast.rb, line 68 def root parent&.root || self end
@return [Array] a tuple of the file name, the line number,
and the column of this AST node.
# File lib/yadriggy/ast_location.rb, line 20 def source_location g = GetLocation.new g.evaluate(self) if g.unknown? && !self.parent.nil? self.parent.source_location else g.result(root.file_name) end end
@return [String] the human-readable location of this AST node.
# File lib/yadriggy/ast_location.rb, line 13 def source_location_string loc = source_location "#{loc[0]}:#{loc[1]}" end
The runtime value of the variable, method name, etc. represented by this AST node. The default behavior returns {Yadriggy::Undef}. Subclasses override this method.
# File lib/yadriggy/ast_value.rb, line 25 def value() Undef end
The runtime value of this AST node when it is evaluated in the context of `clazz`.
@param [Module] clazz the context.
# File lib/yadriggy/ast_value.rb, line 31 def value_in_class(clazz) value end