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.
11067 11068 11069 11070 11071 11072 |
# File 'lib/syntax_tree.rb', line 11067 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
11065 11066 11067 |
# File 'lib/syntax_tree.rb', line 11065 def comments @comments end |
#left ⇒ Object (readonly)
- StringConcat | StringLiteral
-
the left side of the concatenation
11056 11057 11058 |
# File 'lib/syntax_tree.rb', line 11056 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
11062 11063 11064 |
# File 'lib/syntax_tree.rb', line 11062 def location @location end |
#right ⇒ Object (readonly)
- StringLiteral
-
the right side of the concatenation
11059 11060 11061 |
# File 'lib/syntax_tree.rb', line 11059 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
11074 11075 11076 |
# File 'lib/syntax_tree.rb', line 11074 def child_nodes [left, right] end |
#format(q) ⇒ Object
11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 |
# File 'lib/syntax_tree.rb', line 11078 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
11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 |
# File 'lib/syntax_tree.rb', line 11089 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
11103 11104 11105 11106 11107 11108 11109 11110 11111 |
# File 'lib/syntax_tree.rb', line 11103 def to_json(*opts) { type: :string_concat, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |