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.



8059
8060
8061
8062
8063
# File 'lib/syntax_tree.rb', line 8059

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



8057
8058
8059
# File 'lib/syntax_tree.rb', line 8057

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8054
8055
8056
# File 'lib/syntax_tree.rb', line 8054

def location
  @location
end

#valueObject (readonly)

String

the left bracket



8051
8052
8053
# File 'lib/syntax_tree.rb', line 8051

def value
  @value
end

Instance Method Details

#child_nodesObject



8065
8066
8067
# File 'lib/syntax_tree.rb', line 8065

def child_nodes
  []
end

#format(q) ⇒ Object



8069
8070
8071
# File 'lib/syntax_tree.rb', line 8069

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

#pretty_print(q) ⇒ Object



8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
# File 'lib/syntax_tree.rb', line 8073

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



8084
8085
8086
8087
8088
# File 'lib/syntax_tree.rb', line 8084

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