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.



7927
7928
7929
7930
7931
# File 'lib/syntax_tree.rb', line 7927

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



7925
7926
7927
# File 'lib/syntax_tree.rb', line 7925

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7922
7923
7924
# File 'lib/syntax_tree.rb', line 7922

def location
  @location
end

#valueObject (readonly)

String

the left bracket



7919
7920
7921
# File 'lib/syntax_tree.rb', line 7919

def value
  @value
end

Instance Method Details

#child_nodesObject



7933
7934
7935
# File 'lib/syntax_tree.rb', line 7933

def child_nodes
  []
end

#format(q) ⇒ Object



7937
7938
7939
# File 'lib/syntax_tree.rb', line 7937

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

#pretty_print(q) ⇒ Object



7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
# File 'lib/syntax_tree.rb', line 7941

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



7952
7953
7954
7955
7956
# File 'lib/syntax_tree.rb', line 7952

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