Class: SyntaxTree::LParen

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

Overview

LParen represents the use of a left parenthesis, i.e., (.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LParen.



7505
7506
7507
7508
7509
# File 'lib/syntax_tree.rb', line 7505

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



7503
7504
7505
# File 'lib/syntax_tree.rb', line 7503

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7500
7501
7502
# File 'lib/syntax_tree.rb', line 7500

def location
  @location
end

#valueObject (readonly)

String

the left parenthesis



7497
7498
7499
# File 'lib/syntax_tree.rb', line 7497

def value
  @value
end

Instance Method Details

#child_nodesObject



7511
7512
7513
# File 'lib/syntax_tree.rb', line 7511

def child_nodes
  []
end

#format(q) ⇒ Object



7515
7516
7517
# File 'lib/syntax_tree.rb', line 7515

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

#pretty_print(q) ⇒ Object



7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
# File 'lib/syntax_tree.rb', line 7519

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



7530
7531
7532
7533
7534
# File 'lib/syntax_tree.rb', line 7530

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