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
10087 10088 10089 10090 10091 10092 |
# File 'lib/syntax_tree/node.rb', line 10087 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
10085 10086 10087 |
# File 'lib/syntax_tree/node.rb', line 10085 def comments @comments end |
#left ⇒ Object (readonly)
- Heredoc | StringConcat | StringLiteral
-
the left side of the
concatenation
10079 10080 10081 |
# File 'lib/syntax_tree/node.rb', line 10079 def left @left end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
10082 10083 10084 |
# File 'lib/syntax_tree/node.rb', line 10082 def right @right end |
Instance Method Details
#===(other) ⇒ Object
10131 10132 10133 |
# File 'lib/syntax_tree/node.rb', line 10131 def ===(other) other.is_a?(StringConcat) && left === other.left && right === other.right end |
#accept(visitor) ⇒ Object
10094 10095 10096 |
# File 'lib/syntax_tree/node.rb', line 10094 def accept(visitor) visitor.visit_string_concat(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
10098 10099 10100 |
# File 'lib/syntax_tree/node.rb', line 10098 def child_nodes [left, right] end |
#copy(left: nil, right: nil, location: nil) ⇒ Object
10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 |
# File 'lib/syntax_tree/node.rb', line 10102 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
10116 10117 10118 |
# File 'lib/syntax_tree/node.rb', line 10116 def deconstruct_keys(_keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 |
# File 'lib/syntax_tree/node.rb', line 10120 def format(q) q.group do q.format(left) q.text(" \\") q.indent do q.breakable_force q.format(right) end end end |