Skip to content

abstract class Crystal::ASTNode
inherits Reference

Base class for nodes in the grammar.

Direct known subclasses

Crystal::Alias Crystal::Annotation Crystal::AnnotationDef Crystal::Arg Crystal::ArrayLiteral Crystal::Asm Crystal::AsmOperand Crystal::Assign Crystal::AssignWithRestriction Crystal::BinaryOp Crystal::Block Crystal::BoolLiteral Crystal::Call Crystal::Case Crystal::Cast Crystal::CharLiteral Crystal::ClassDef Crystal::ClassVar Crystal::ControlExpression Crystal::CStructOrUnionDef Crystal::Def Crystal::EnumDef Crystal::ExceptionHandler Crystal::Expressions Crystal::Extend Crystal::ExternalVar Crystal::FileNode Crystal::FunDef Crystal::Generic Crystal::Global Crystal::HashLiteral Crystal::If Crystal::ImplicitObj Crystal::Include Crystal::InstanceVar Crystal::IsA Crystal::LibDef Crystal::Macro Crystal::MacroExpression Crystal::MacroFor Crystal::MacroId Crystal::MacroIf Crystal::MacroLiteral Crystal::MacroVar Crystal::MagicConstant Crystal::Metaclass Crystal::MetaMacroVar Crystal::MetaVar Crystal::ModuleDef Crystal::MultiAssign Crystal::NamedArgument Crystal::NamedTupleLiteral Crystal::NilableCast Crystal::NilLiteral Crystal::Nop Crystal::NumberLiteral Crystal::OffsetOf Crystal::OpAssign Crystal::Path Crystal::Primitive Crystal::ProcLiteral Crystal::ProcNotation Crystal::ProcPointer Crystal::RangeLiteral Crystal::ReadInstanceVar Crystal::RegexLiteral Crystal::Require Crystal::Rescue Crystal::RespondsTo Crystal::Select Crystal::Self Crystal::StringInterpolation Crystal::StringLiteral Crystal::SymbolLiteral Crystal::TupleLiteral Crystal::TypeDeclaration Crystal::TypeDef Crystal::TypeFilteredNode Crystal::TypeNode Crystal::TypeOf Crystal::UnaryExpression Crystal::Underscore Crystal::UninitializedVar Crystal::Union Crystal::Unless Crystal::Unreachable Crystal::Until Crystal::Var Crystal::VisibilityModifier Crystal::When Crystal::While Crystal::Yield Crystal::YieldBlockBinder

Methods

#accept(visitor)

View source

#accept_children(visitor)

View source

#add_observer(observer)

View source

#at(node : ASTNode)

Sets this node's location and end location to those of node, and returns self

View source

#at(location : Location?)

Updates this node's location and returns self

View source

#at_end(node : ASTNode)

Sets this node's end location to those of node and returns self

View source

#at_end(end_location : Location?)

Updates this node's end location and returns self

View source

#bind(from = nil

View source

#bind_to(node : ASTNode)

View source

#bind_to(nodes : Array)

View source

#class_desc : String

View source

#class_name

View source

#clone

Returns a deep copy of this node. Copied nodes retain the location and end location of the original nodes.

View source

#dependencies : Array(ASTNode)

#dependencies=(dependencies : Array(ASTNode))

View source

#dependencies? : Array(ASTNode)?

#doc

Returns the doc comment attached to this node. Not every node supports having doc comments, so by default this returns nil.

View source

#doc=(doc)

Attaches a doc comment to this node. Not every node supports having doc comments, so by default this does nothing and some subclasses implement this.

View source

#enclosing_call : Call?

View source

#enclosing_call=(enclosing_call : Call?)

View source

#end_location : Location?

The location where this node ends, or nil if the location is not known.

View source

#end_location=(end_location : Location?)

The location where this node ends, or nil if the location is not known.

View source

#false?

View source

#false_literal?

View source

#filtered_by(filter)

View source

#find_owner_trace(program, owner)

View source

#freeze_type : Type?

View source

#freeze_type=(freeze_type : Type?)

View source

#inspect(io : IO) : Nil

Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
View source

#interpret(method : String, args : Array(ASTNode), named_args : Hash(String, ASTNode)?, block : Crystal::Block?, interpreter : Crystal::MacroInterpreter, name_loc : Location?)

View source

#interpret_argless_method

View source

#interpret_check_args_size(method, args, size)

View source

#interpret_compare(other)

View source

#interpret_one_arg_method

View source

#interpret_two_args_method

View source

#location : Location?

The location where this node starts, or nil if the location is not known.

View source

#location=(location : Location?)

The location where this node starts, or nil if the location is not known.

View source

#map_type(type)

View source

#name_location

View source

#name_size

View source

#no_returns?

View source

#nop?

View source

#notify_observers

View source

#observers : Array(ASTNode)?

View source

#observers=(observers : Array(ASTNode)?)

View source

#pretty_print(pp)

View source

#propagate

View source

#raise(message, inner = nil, exception_type = Crystal::TypeException)

View source

#raise_frozen_type(freeze_type, invalid_type, from)

View source

#remove_enclosing_call(enclosing_call)

View source

#remove_observer(observer)

View source

#restrict_type_to_freeze_type(freeze_type, type)

Computes the type resulting from assigning type to freeze_type, in the case where freeze_type is not nil.

Special cases are listed inside the method body.

View source

#restriction_of?(other : Underscore, owner, strict = false)

View source

#restriction_of?(other, owner, strict = false)

View source

#restriction_of?(other : Type, owner, strict = false)

View source

#restriction_of?(other : ASTNode, owner, strict = false)

View source

#set_enclosing_call(enclosing_call)

View source

#set_type(type : Type)

View source

#set_type(type : Nil)

View source

#set_type_from(type, from)

View source

#simple_literal?

View source

#single_expression

It yields itself for any node, but Expressions yields first node if it holds only a node.

View source

#single_expression?

It yields nil always. (It is overridden by Expressions to implement #single_expression.)

View source

#stringify

View source

#symbolize

View source

#to_macro_id

View source

#to_s(io : IO, macro_expansion_pragmas = nil, emit_doc = false) : Nil

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>
View source

#to_string(context)

View source

#transform(transformer)

View source

#true_literal?

View source

#truthy?

View source

#type

View source

#type(*, with_literals = false)

View source

#type=(type)

View source

#type?

View source

#unbind_all

View source

#unbind_from(nodes : Array(ASTNode))

View source

#unbind_from(nodes : Nil)

View source

#unbind_from(node : ASTNode)

View source

#update(from = nil)

View source

#visibility

View source

#visibility=(visibility : Visibility)

View source

#warning(message, inner = nil, exception_type = Crystal::TypeException)

View source

#wrong_number_of(elements, given, expected)

View source

#wrong_number_of(elements, subject, given, expected)

View source

#wrong_number_of_arguments(subject, given, expected)

View source

#wrong_number_of_message(elements, given, expected)

View source

#wrong_number_of_message(elements, subject, given, expected)

View source

#zero?

View source