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.



6725
6726
6727
6728
6729
# File 'lib/syntax_tree.rb', line 6725

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



6723
6724
6725
# File 'lib/syntax_tree.rb', line 6723

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



6720
6721
6722
# File 'lib/syntax_tree.rb', line 6720

def location
  @location
end

#valueObject (readonly)

String

the value of the identifier



6717
6718
6719
# File 'lib/syntax_tree.rb', line 6717

def value
  @value
end

Instance Method Details

#child_nodesObject



6731
6732
6733
# File 'lib/syntax_tree.rb', line 6731

def child_nodes
  []
end

#format(q) ⇒ Object



6735
6736
6737
# File 'lib/syntax_tree.rb', line 6735

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

#pretty_print(q) ⇒ Object



6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
# File 'lib/syntax_tree.rb', line 6739

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



6750
6751
6752
6753
6754
6755
6756
6757
# File 'lib/syntax_tree.rb', line 6750

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