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.



8115
8116
8117
8118
8119
# File 'lib/syntax_tree.rb', line 8115

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



8113
8114
8115
# File 'lib/syntax_tree.rb', line 8113

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8110
8111
8112
# File 'lib/syntax_tree.rb', line 8110

def location
  @location
end

#valueObject (readonly)

String

the left parenthesis



8107
8108
8109
# File 'lib/syntax_tree.rb', line 8107

def value
  @value
end

Instance Method Details

#child_nodesObject



8121
8122
8123
# File 'lib/syntax_tree.rb', line 8121

def child_nodes
  []
end

#format(q) ⇒ Object



8125
8126
8127
# File 'lib/syntax_tree.rb', line 8125

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

#pretty_print(q) ⇒ Object



8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
# File 'lib/syntax_tree.rb', line 8129

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



8140
8141
8142
8143
8144
# File 'lib/syntax_tree.rb', line 8140

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