Class: SyntaxTree::QSymbols
Overview
QSymbols represents a symbol literal array without interpolation.
i[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- QSymbolsBeg
-
the token that opens this array literal.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#elements ⇒ Object
readonly
- Array[ TStringContent ]
-
the elements of the array.
Attributes inherited from Node
Instance Method Summary collapse
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(beginning: nil, elements: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:) ⇒ QSymbols
constructor
A new instance of QSymbols.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(beginning:, elements:, location:) ⇒ QSymbols
Returns a new instance of QSymbols.
8619 8620 8621 8622 8623 8624 |
# File 'lib/syntax_tree/node.rb', line 8619 def initialize(beginning:, elements:, location:) @beginning = beginning @elements = elements @location = location @comments = [] end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- QSymbolsBeg
-
the token that opens this array literal
8611 8612 8613 |
# File 'lib/syntax_tree/node.rb', line 8611 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8617 8618 8619 |
# File 'lib/syntax_tree/node.rb', line 8617 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
8614 8615 8616 |
# File 'lib/syntax_tree/node.rb', line 8614 def elements @elements end |
Instance Method Details
#===(other) ⇒ Object
8679 8680 8681 8682 |
# File 'lib/syntax_tree/node.rb', line 8679 def ===(other) other.is_a?(QSymbols) && beginning === other.beginning && ArrayMatch.call(elements, other.elements) end |
#accept(visitor) ⇒ Object
8626 8627 8628 |
# File 'lib/syntax_tree/node.rb', line 8626 def accept(visitor) visitor.visit_qsymbols(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
8630 8631 8632 |
# File 'lib/syntax_tree/node.rb', line 8630 def child_nodes [] end |
#copy(beginning: nil, elements: nil, location: nil) ⇒ Object
8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 |
# File 'lib/syntax_tree/node.rb', line 8634 def copy(beginning: nil, elements: nil, location: nil) node = QSymbols.new( beginning: beginning || self.beginning, elements: elements || self.elements, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
8648 8649 8650 8651 8652 8653 8654 8655 |
# File 'lib/syntax_tree/node.rb', line 8648 def deconstruct_keys(_keys) { beginning: beginning, elements: elements, location: location, comments: comments } end |
#format(q) ⇒ Object
8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 |
# File 'lib/syntax_tree/node.rb', line 8657 def format(q) opening, closing = "%i[", "]" 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 |