Class: SyntaxTree::StringConcat
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
- Heredoc | StringConcat | StringLiteral
-
the left side of the concatenation.
-
#right ⇒ Object
readonly
- StringLiteral
-
the right side of the concatenation.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(left: nil, right: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:) ⇒ StringConcat
constructor
A new instance of StringConcat.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(left:, right:, location:) ⇒ StringConcat
Returns a new instance of StringConcat.
10151 10152 10153 10154 10155 10156 |
# File 'lib/syntax_tree/node.rb', line 10151 def initialize(left:, right:, location:) @left = left @right = right @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10149 10150 10151 |
# File 'lib/syntax_tree/node.rb', line 10149 def comments @comments end |
#left ⇒ Object (readonly)
- Heredoc | StringConcat | StringLiteral
-
the left side of the
concatenation
10143 10144 10145 |
# File 'lib/syntax_tree/node.rb', line 10143 def left @left end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
10146 10147 10148 |
# File 'lib/syntax_tree/node.rb', line 10146 def right @right end |
Instance Method Details
#===(other) ⇒ Object
10195 10196 10197 |
# File 'lib/syntax_tree/node.rb', line 10195 def ===(other) other.is_a?(StringConcat) && left === other.left && right === other.right end |
#accept(visitor) ⇒ Object
10158 10159 10160 |
# File 'lib/syntax_tree/node.rb', line 10158 def accept(visitor) visitor.visit_string_concat(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
10162 10163 10164 |
# File 'lib/syntax_tree/node.rb', line 10162 def child_nodes [left, right] end |
#copy(left: nil, right: nil, location: nil) ⇒ Object
10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 |
# File 'lib/syntax_tree/node.rb', line 10166 def copy(left: nil, right: nil, location: nil) node = StringConcat.new( left: left || self.left, right: right || self.right, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
10180 10181 10182 |
# File 'lib/syntax_tree/node.rb', line 10180 def deconstruct_keys(_keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 |
# File 'lib/syntax_tree/node.rb', line 10184 def format(q) q.group do q.format(left) q.text(" \\") q.indent do q.breakable_force q.format(right) end end end |