class RubyVM::AbstractSyntaxTree::Node
RubyVM::AbstractSyntaxTree::Node instances are created by parse methods in RubyVM::AbstractSyntaxTree.
This class is MRI specific.
Public Instance Methods
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 580
def all_tokens: () -> Array[[Integer, Symbol, String, [Integer, Integer, Integer, Integer]]]?
Returns all tokens for the input script regardless the receiver node. Returns nil if keep_tokens is not enabled when parse method is called.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true) root.all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...] root.children[-1].all_tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 591
def children: () -> Array[untyped]
Returns AST nodes under this one. Each kind of node has different children, depending on what kind of node it is.
The returned array may contain other nodes or nil.
() → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 522
def first_column: () -> Integer
The column number in the source code where this AST’s text began.
() → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 514
def first_lineno: () -> Integer
The line number in the source code where this AST’s text began.
() → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 538
def last_column: () -> Integer
The column number in the source code where this AST’s text ended.
() → Integer
Source
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 530
def last_lineno: () -> Integer
The line number in the source code where this AST’s text ended.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 547
def locations: () -> Array[Location]
Returns location objects associated with the AST node. The returned array contains RubyVM::AbstractSyntaxTree::Location.
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/stdlib/pp/0/pp.rbs, line 282
def pretty_print_children: (PP q, ?Array[untyped] names) -> void
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 567
def tokens: () -> Array[[Integer, Symbol, String, [Integer, Integer, Integer, Integer]]]?
Returns tokens corresponding to the location of the node. Returns nil if keep_tokens is not enabled when parse method is called.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2", keep_tokens: true) root.tokens # => [[0, :tIDENTIFIER, "x", [1, 0, 1, 1]], [1, :tSP, " ", [1, 1, 1, 2]], ...] root.tokens.map{_1[2]}.join # => "x = 1 + 2"
Token is an array of:
-
id
-
token type
-
source code text
-
location [
first_lineno,first_column,last_lineno,last_column]
# File vendor/bundle/ruby/4.0.0/gems/rbs-4.0.3/core/ruby_vm.rbs, line 506
def type: () -> Symbol
Returns the type of this node as a symbol.
root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2") root.type # => :SCOPE lasgn = root.children[2] lasgn.type # => :LASGN call = lasgn.children[1] call.type # => :OPCALL