Class: SyntaxTree::LBrace

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

Overview

LBrace represents the use of a left brace, i.e., {.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LBrace.



7422
7423
7424
7425
7426
# File 'lib/syntax_tree.rb', line 7422

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



7420
7421
7422
# File 'lib/syntax_tree.rb', line 7420

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7417
7418
7419
# File 'lib/syntax_tree.rb', line 7417

def location
  @location
end

#valueObject (readonly)

String

the left brace



7414
7415
7416
# File 'lib/syntax_tree.rb', line 7414

def value
  @value
end

Instance Method Details

#child_nodesObject



7428
7429
7430
# File 'lib/syntax_tree.rb', line 7428

def child_nodes
  []
end

#format(q) ⇒ Object



7432
7433
7434
# File 'lib/syntax_tree.rb', line 7432

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

#pretty_print(q) ⇒ Object



7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
# File 'lib/syntax_tree.rb', line 7436

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



7447
7448
7449
7450
7451
# File 'lib/syntax_tree.rb', line 7447

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