Class: SyntaxTree::Words
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Words
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Words represents a string literal array with interpolation.
%W[one two three]
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(beginning:, elements:, location:) ⇒ Words
12089
12090
12091
12092
12093
12094
|
# File 'lib/syntax_tree/node.rb', line 12089
def initialize(beginning:, elements:, location:)
@beginning = beginning
@elements = elements
@location = location
= []
end
|
Instance Attribute Details
#beginning ⇒ Object
- WordsBeg
-
the token that opens this array literal
12081
12082
12083
|
# File 'lib/syntax_tree/node.rb', line 12081
def beginning
@beginning
end
|
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
12087
12088
12089
|
# File 'lib/syntax_tree/node.rb', line 12087
def
end
|
#elements ⇒ Object
- Array[ Word ]
-
the elements of this array
12084
12085
12086
|
# File 'lib/syntax_tree/node.rb', line 12084
def elements
@elements
end
|
Instance Method Details
#===(other) ⇒ Object
12145
12146
12147
12148
|
# File 'lib/syntax_tree/node.rb', line 12145
def ===(other)
other.is_a?(Words) && beginning === other.beginning &&
ArrayMatch.call(elements, other.elements)
end
|
#accept(visitor) ⇒ Object
12096
12097
12098
|
# File 'lib/syntax_tree/node.rb', line 12096
def accept(visitor)
visitor.visit_words(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
12100
12101
12102
|
# File 'lib/syntax_tree/node.rb', line 12100
def child_nodes
[]
end
|
#copy(beginning: nil, elements: nil, location: nil) ⇒ Object
12104
12105
12106
12107
12108
12109
12110
|
# File 'lib/syntax_tree/node.rb', line 12104
def copy(beginning: nil, elements: nil, location: nil)
Words.new(
beginning: beginning || self.beginning,
elements: elements || self.elements,
location: location || self.location
)
end
|
#deconstruct_keys(_keys) ⇒ Object
12114
12115
12116
12117
12118
12119
12120
12121
|
# File 'lib/syntax_tree/node.rb', line 12114
def deconstruct_keys(_keys)
{
beginning: beginning,
elements: elements,
location: location,
comments:
}
end
|
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
|
# File 'lib/syntax_tree/node.rb', line 12123
def format(q)
opening, closing = "%W[", "]"
if elements.any? { |element| element.match?(/[\[\]]/) }
opening = beginning.value
closing = Quotes.matching(opening[2])
end
q.text(opening)
q.group do
q.indent do
q.breakable_empty
q.seplist(
elements,
ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
) { |element| q.format(element) }
end
q.breakable_empty
end
q.text(closing)
end
|