Class: Yoda::AST::Vnode Abstract

Inherits:
Object
  • Object
show all
Includes:
MethodTraversable, NamespaceTraversable, Traversable, CommentAssociation, CommentPositional, Positional
Defined in:
lib/yoda/ast/vnode.rb

Overview

This class is abstract.

Direct Known Subclasses

EmptyVnode, NameVnode, Node, RootVnode, ValueVnode

Defined Under Namespace

Modules: CommentAssociation, CommentPositional, Positional

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommentPositional

#comments_by_vnode, #positionally_nearest_comment, #positionally_nearest_commenting_node

Methods included from Positional

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

Methods included from 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(parent: nil, comments_by_node: {}) ⇒ Vnode

Returns a new instance of Vnode.

Parameters:

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


17
18
19
20
# File 'lib/yoda/ast/vnode.rb', line 17

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

Instance Attribute Details

#comments_by_nodeHash{Parser::AST::Node => Array<Parser::Source::Comment>} (readonly)

Returns:

  • (Hash{Parser::AST::Node => Array<Parser::Source::Comment>})


13
14
15
# File 'lib/yoda/ast/vnode.rb', line 13

def comments_by_node
  @comments_by_node
end

#parentVnode? (readonly)

Returns:



10
11
12
# File 'lib/yoda/ast/vnode.rb', line 10

def parent
  @parent
end

Instance Method Details

#childrenArray<Vnode>

Returns:



34
35
36
# File 'lib/yoda/ast/vnode.rb', line 34

def children
  fail NotImplementedError
end

#constant?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/yoda/ast/vnode.rb', line 48

def constant?
  false
end

#empty?boolean

Returns:

  • (boolean)


39
40
41
# File 'lib/yoda/ast/vnode.rb', line 39

def empty?
  false
end

#identifierString

Returns:

  • (String)


58
59
60
# File 'lib/yoda/ast/vnode.rb', line 58

def identifier
  "#{type}:#{object_id}"
end

#inspectString

Returns:

  • (String)


63
64
65
# File 'lib/yoda/ast/vnode.rb', line 63

def inspect
  "(#{[identifier, inspect_content].join(' ')})"
end

#inspect_contentString

Returns:

  • (String)


68
69
70
# File 'lib/yoda/ast/vnode.rb', line 68

def inspect_content
  children.map(&:inspect).join(' ')
end

#nestingArray<Vnode>

Returns all nodes between root and self.

Returns:

  • (Array<Vnode>)

    all nodes between root and self.



23
24
25
# File 'lib/yoda/ast/vnode.rb', line 23

def nesting
  @nesting ||= (parent&.nesting || []) + [self]
end

#present?boolean

Returns:

  • (boolean)


44
45
46
# File 'lib/yoda/ast/vnode.rb', line 44

def present?
  !empty?
end

#try(method_name, *args) ⇒ Object



72
73
74
# File 'lib/yoda/ast/vnode.rb', line 72

def try(method_name, *args)
  respond_to?(method_name) ? send(method_name, *args) : nil
end

#typeSymbol

Returns:

  • (Symbol)


53
54
55
# File 'lib/yoda/ast/vnode.rb', line 53

def type
  fail NotImplementedError
end

#wrap_child(child_node) ⇒ Vnode

Parameters:

  • (Parser::AST::Node)

Returns:



29
30
31
# File 'lib/yoda/ast/vnode.rb', line 29

def wrap_child(child_node)
  AST.wrap(child_node, parent: self, comments_by_node: comments_by_node)
end