Class: SyntaxTree::StringConcat
- Inherits:
-
Object
- Object
- SyntaxTree::StringConcat
- Defined in:
- lib/syntax_tree.rb
Overview
StringConcat represents concatenating two strings together using a backward slash.
"first" \
"second"
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- StringConcat | StringLiteral
-
the left side of the concatenation.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#right ⇒ Object
readonly
- StringLiteral
-
the right side of the concatenation.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ StringConcat
constructor
A new instance of StringConcat.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ StringConcat
Returns a new instance of StringConcat.
10527 10528 10529 10530 10531 10532 |
# File 'lib/syntax_tree.rb', line 10527 def initialize(left:, right:, location:, comments: []) @left = left @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10525 10526 10527 |
# File 'lib/syntax_tree.rb', line 10525 def comments @comments end |
#left ⇒ Object (readonly)
- StringConcat | StringLiteral
-
the left side of the concatenation
10516 10517 10518 |
# File 'lib/syntax_tree.rb', line 10516 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10522 10523 10524 |
# File 'lib/syntax_tree.rb', line 10522 def location @location end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
10519 10520 10521 |
# File 'lib/syntax_tree.rb', line 10519 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
10534 10535 10536 |
# File 'lib/syntax_tree.rb', line 10534 def child_nodes [left, right] end |
#format(q) ⇒ Object
10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 |
# File 'lib/syntax_tree.rb', line 10538 def format(q) q.group do q.format(left) q.text(' \\') q.indent do q.breakable(force: true) q.format(right) end end end |
#pretty_print(q) ⇒ Object
10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 |
# File 'lib/syntax_tree.rb', line 10549 def pretty_print(q) q.group(2, "(", ")") do q.text("string_concat") q.breakable q.pp(left) q.breakable q.pp(right) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
10563 10564 10565 10566 10567 10568 10569 10570 10571 |
# File 'lib/syntax_tree.rb', line 10563 def to_json(*opts) { type: :string_concat, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |