Class: SyntaxTree::Ident

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Ident represents an identifier anywhere in code. It can represent a very large number of things, depending on where it is in the syntax tree.

value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ Ident

Returns a new instance of Ident.



6768
6769
6770
6771
6772
# File 'lib/syntax_tree.rb', line 6768

def initialize(value:, location:, comments: [])
  @value = value
  @location = location
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6766
6767
6768
# File 'lib/syntax_tree.rb', line 6766

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6763
6764
6765
# File 'lib/syntax_tree.rb', line 6763

def location
  @location
end

#valueObject (readonly)

String

the value of the identifier



6760
6761
6762
# File 'lib/syntax_tree.rb', line 6760

def value
  @value
end

Instance Method Details

#child_nodesObject



6774
6775
6776
# File 'lib/syntax_tree.rb', line 6774

def child_nodes
  []
end

#format(q) ⇒ Object



6778
6779
6780
# File 'lib/syntax_tree.rb', line 6778

def format(q)
  q.text(value)
end

#pretty_print(q) ⇒ Object



6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
# File 'lib/syntax_tree.rb', line 6782

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("ident")

    q.breakable
    q.pp(value)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



6793
6794
6795
6796
6797
6798
6799
6800
# File 'lib/syntax_tree.rb', line 6793

def to_json(*opts)
  {
    type: :ident,
    value: value.force_encoding("UTF-8"),
    loc: location,
    cmts: comments
  }.to_json(*opts)
end