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.



7983
7984
7985
7986
7987
# File 'lib/syntax_tree.rb', line 7983

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



7981
7982
7983
# File 'lib/syntax_tree.rb', line 7981

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



7978
7979
7980
# File 'lib/syntax_tree.rb', line 7978

def location
  @location
end

#valueObject (readonly)

String

the left parenthesis



7975
7976
7977
# File 'lib/syntax_tree.rb', line 7975

def value
  @value
end

Instance Method Details

#child_nodesObject



7989
7990
7991
# File 'lib/syntax_tree.rb', line 7989

def child_nodes
  []
end

#format(q) ⇒ Object



7993
7994
7995
# File 'lib/syntax_tree.rb', line 7993

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

#pretty_print(q) ⇒ Object



7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
# File 'lib/syntax_tree.rb', line 7997

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



8008
8009
8010
8011
8012
# File 'lib/syntax_tree.rb', line 8008

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