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.
10204
10205
10206
10207
10208
|
# File 'lib/syntax_tree/node.rb', line 10204
def initialize(statements:, location:)
@statements = statements
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10202
10203
10204
|
# File 'lib/syntax_tree/node.rb', line 10202
def
end
|
#statements ⇒ Object
- Statements
-
the expressions to be interpolated
10199
10200
10201
|
# File 'lib/syntax_tree/node.rb', line 10199
def statements
@statements
end
|
Instance Method Details
#===(other) ⇒ Object
10261
10262
10263
|
# File 'lib/syntax_tree/node.rb', line 10261
def ===(other)
other.is_a?(StringEmbExpr) && statements === other.statements
end
|
#accept(visitor) ⇒ Object
10210
10211
10212
|
# File 'lib/syntax_tree/node.rb', line 10210
def accept(visitor)
visitor.visit_string_embexpr(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
10214
10215
10216
|
# File 'lib/syntax_tree/node.rb', line 10214
def child_nodes
[statements]
end
|
#copy(statements: nil, location: nil) ⇒ Object
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
|
# File 'lib/syntax_tree/node.rb', line 10218
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
10231
10232
10233
|
# File 'lib/syntax_tree/node.rb', line 10231
def deconstruct_keys(_keys)
{ statements: statements, location: location, comments: }
end
|
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
|
# File 'lib/syntax_tree/node.rb', line 10235
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
|