Class: SyntaxTree::StringEmbExpr
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::StringEmbExpr
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
StringEmbExpr represents interpolated content. It can be contained within a couple of different parent nodes, including regular expressions, strings, and dynamic symbols.
"string #{expression}"
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(statements:, location:) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
10235
10236
10237
10238
10239
|
# File 'lib/syntax_tree/node.rb', line 10235
def initialize(statements:, location:)
@statements = statements
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10233
10234
10235
|
# File 'lib/syntax_tree/node.rb', line 10233
def
end
|
#statements ⇒ Object
- Statements
-
the expressions to be interpolated
10230
10231
10232
|
# File 'lib/syntax_tree/node.rb', line 10230
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
10292
10293
10294
|
# File 'lib/syntax_tree/node.rb', line 10292
def ===(other)
other.is_a?(StringEmbExpr) && statements === other.statements
end
|
#accept(visitor) ⇒ Object
10241
10242
10243
|
# File 'lib/syntax_tree/node.rb', line 10241
def accept(visitor)
visitor.visit_string_embexpr(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10245
10246
10247
|
# File 'lib/syntax_tree/node.rb', line 10245
def child_nodes
[statements]
end
|
#copy(statements: nil, location: nil) ⇒ Object
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
|
# File 'lib/syntax_tree/node.rb', line 10249
def copy(statements: nil, location: nil)
node =
StringEmbExpr.new(
statements: statements || self.statements,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
10262
10263
10264
|
# File 'lib/syntax_tree/node.rb', line 10262
def deconstruct_keys(_keys)
{ statements: statements, location: location, comments: }
end
|
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
|
# File 'lib/syntax_tree/node.rb', line 10266
def format(q)
if location.start_line == location.end_line
q.remove_breaks(
q.group do
q.text('#{')
q.format(statements)
q.text("}")
end
)
else
q.group do
q.text('#{')
q.indent do
q.breakable_empty
q.format(statements)
end
q.breakable_empty
q.text("}")
end
end
end
|