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
- 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, #pretty_print, #to_json
Constructor Details
#initialize(left:, right:, location:) ⇒ StringConcat
Returns a new instance of StringConcat.
9960 9961 9962 9963 9964 9965 |
# File 'lib/syntax_tree/node.rb', line 9960 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
9958 9959 9960 |
# File 'lib/syntax_tree/node.rb', line 9958 def comments @comments end |
#left ⇒ Object (readonly)
- StringConcat | StringLiteral
-
the left side of the concatenation
9952 9953 9954 |
# File 'lib/syntax_tree/node.rb', line 9952 def left @left end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
9955 9956 9957 |
# File 'lib/syntax_tree/node.rb', line 9955 def right @right end |
Instance Method Details
#===(other) ⇒ Object
10004 10005 10006 |
# File 'lib/syntax_tree/node.rb', line 10004 def ===(other) other.is_a?(StringConcat) && left === other.left && right === other.right end |
#accept(visitor) ⇒ Object
9967 9968 9969 |
# File 'lib/syntax_tree/node.rb', line 9967 def accept(visitor) visitor.visit_string_concat(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
9971 9972 9973 |
# File 'lib/syntax_tree/node.rb', line 9971 def child_nodes [left, right] end |
#copy(left: nil, right: nil, location: nil) ⇒ Object
9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 |
# File 'lib/syntax_tree/node.rb', line 9975 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
9989 9990 9991 |
# File 'lib/syntax_tree/node.rb', line 9989 def deconstruct_keys(_keys) { left: left, right: right, location: location, comments: comments } end |
#format(q) ⇒ Object
9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 |
# File 'lib/syntax_tree/node.rb', line 9993 def format(q) q.group do q.format(left) q.text(" \\") q.indent do q.breakable_force q.format(right) end end end |