Class: SyntaxTree::LBracket

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

Overview

LBracket represents the use of a left bracket, i.e., [.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LBracket.



7854
7855
7856
7857
7858
# File 'lib/syntax_tree.rb', line 7854

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



7852
7853
7854
# File 'lib/syntax_tree.rb', line 7852

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7849
7850
7851
# File 'lib/syntax_tree.rb', line 7849

def location
  @location
end

#valueObject (readonly)

String

the left bracket



7846
7847
7848
# File 'lib/syntax_tree.rb', line 7846

def value
  @value
end

Instance Method Details

#format(q) ⇒ Object



7860
7861
7862
# File 'lib/syntax_tree.rb', line 7860

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

#pretty_print(q) ⇒ Object



7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
# File 'lib/syntax_tree.rb', line 7864

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



7875
7876
7877
7878
7879
# File 'lib/syntax_tree.rb', line 7875

def to_json(*opts)
  { type: :lbracket, value: value, loc: location, cmts: comments }.to_json(
    *opts
  )
end