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.
11199 11200 11201 11202 11203 11204 |
# File 'lib/syntax_tree.rb', line 11199 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
11197 11198 11199 |
# File 'lib/syntax_tree.rb', line 11197 def comments @comments end |
#left ⇒ Object (readonly)
- StringConcat | StringLiteral
-
the left side of the concatenation
11188 11189 11190 |
# File 'lib/syntax_tree.rb', line 11188 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11194 11195 11196 |
# File 'lib/syntax_tree.rb', line 11194 def location @location end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
11191 11192 11193 |
# File 'lib/syntax_tree.rb', line 11191 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
11206 11207 11208 |
# File 'lib/syntax_tree.rb', line 11206 def child_nodes [left, right] end |
#format(q) ⇒ Object
11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 |
# File 'lib/syntax_tree.rb', line 11210 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
11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 |
# File 'lib/syntax_tree.rb', line 11221 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
11235 11236 11237 11238 11239 11240 11241 11242 11243 |
# File 'lib/syntax_tree.rb', line 11235 def to_json(*opts) { type: :string_concat, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |