Class: SyntaxTree::StringEmbExpr
- Inherits:
-
Object
- Object
- SyntaxTree::StringEmbExpr
- Defined in:
- lib/syntax_tree.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
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#statements ⇒ Object
readonly
- Statements
-
the expressions to be interpolated.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
constructor
A new instance of StringEmbExpr.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(statements:, location:, comments: []) ⇒ StringEmbExpr
Returns a new instance of StringEmbExpr.
11348 11349 11350 11351 11352 |
# File 'lib/syntax_tree.rb', line 11348 def initialize(statements:, location:, comments: []) @statements = statements @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11346 11347 11348 |
# File 'lib/syntax_tree.rb', line 11346 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11343 11344 11345 |
# File 'lib/syntax_tree.rb', line 11343 def location @location end |
#statements ⇒ Object (readonly)
- Statements
-
the expressions to be interpolated
11340 11341 11342 |
# File 'lib/syntax_tree.rb', line 11340 def statements @statements end |
Instance Method Details
#child_nodes ⇒ Object
11354 11355 11356 |
# File 'lib/syntax_tree.rb', line 11354 def child_nodes [statements] end |
#format(q) ⇒ Object
11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 |
# File 'lib/syntax_tree.rb', line 11358 def format(q) if location.start_line == location.end_line # If the contents of this embedded expression were originally on the # same line in the source, then we're going to leave them in place and # assume that's the way the developer wanted this expression # represented. doc = q.group(0, '#{', "}") { q.format(statements) } RemoveBreaks.call(doc) else q.group do q.text('#{') q.indent do q.breakable("") q.format(statements) end q.breakable("") q.text("}") end end end |
#pretty_print(q) ⇒ Object
11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 |
# File 'lib/syntax_tree.rb', line 11379 def pretty_print(q) q.group(2, "(", ")") do q.text("string_embexpr") q.breakable q.pp(statements) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
11390 11391 11392 11393 11394 11395 11396 11397 |
# File 'lib/syntax_tree.rb', line 11390 def to_json(*opts) { type: :string_embexpr, stmts: statements, loc: location, cmts: comments }.to_json(*opts) end |