Class: Yoda::AST::Node

Inherits:
Vnode
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yoda/ast/node.rb

Instance Attribute Summary collapse

Attributes inherited from Vnode

#comments_by_node, #parent

Instance Method Summary collapse

Methods inherited from Vnode

#constant?, #empty?, #inspect, #inspect_content, #nesting, #present?, #try, #type, #wrap_child

Methods included from Vnode::CommentPositional

#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node

Methods included from Vnode::Positional

#location, #positionally_include?, #positionally_nearest_child, #range

Methods included from Vnode::CommentAssociation

#all_nodes_lazy, #associate_comments, #comments, #wrapping?

Methods included from Traversable

#query, #query_all, #query_ancestor, #query_ancestors

Methods included from MethodTraversable

#calc_current_location_method, #including_method, #method?

Methods included from NamespaceTraversable

#calc_current_location_namespace, #full_name, #namespace, #namespace?, #namespace_path, #root?

Constructor Details

#initialize(node, parent: nil, comments_by_node: {}) ⇒ Node

Returns a new instance of Node.

Parameters:

  • node (Parser::AST::Node)
  • parent (Vnode) (defaults to: nil)
  • comment_by_node (Hash{Parser::AST::Node => Array<Parser::Source::Comment>})


20
21
22
23
# File 'lib/yoda/ast/node.rb', line 20

def initialize(node, parent: nil, comments_by_node: {})
  @node = node
  super(parent: parent, comments_by_node: comments_by_node)
end

Instance Attribute Details

#nodeString (readonly)

Returns:

  • (String)


9
10
11
# File 'lib/yoda/ast/node.rb', line 9

def node
  @node
end

Instance Method Details

#childrenArray<Vnode>

Returns:



26
27
28
# File 'lib/yoda/ast/node.rb', line 26

def children
  @children ||= node.children.map(&method(:wrap_child))
end

#identifierString

Returns:

  • (String)


31
32
33
# File 'lib/yoda/ast/node.rb', line 31

def identifier
  "#{type}:#{source_map&.expression ? source_map_expression : object_id}"
end

#kindSymbol

Returns:

  • (Symbol)


41
42
43
# File 'lib/yoda/ast/node.rb', line 41

def kind
  node.type
end

#source_mapParser::Source::Map?

Returns:

  • (Parser::Source::Map, nil)


36
37
38
# File 'lib/yoda/ast/node.rb', line 36

def source_map
  node.location
end