Class: SyntaxTree::QWords
- Inherits:
-
Object
- Object
- SyntaxTree::QWords
- Defined in:
- lib/syntax_tree.rb
Overview
QWords represents a string literal array without interpolation.
%w[one two three]
Instance Attribute Summary collapse
-
#beginning ⇒ Object
readonly
- QWordsBeg
-
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.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(beginning:, elements:, location:, comments: []) ⇒ QWords
constructor
A new instance of QWords.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(beginning:, elements:, location:, comments: []) ⇒ QWords
9578 9579 9580 9581 9582 9583 |
# File 'lib/syntax_tree.rb', line 9578 def initialize(beginning:, elements:, location:, comments: []) @beginning = beginning @elements = elements @location = location @comments = comments end |
Instance Attribute Details
#beginning ⇒ Object (readonly)
- QWordsBeg
-
the token that opens this array literal
9567 9568 9569 |
# File 'lib/syntax_tree.rb', line 9567 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9576 9577 9578 |
# File 'lib/syntax_tree.rb', line 9576 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
9570 9571 9572 |
# File 'lib/syntax_tree.rb', line 9570 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9573 9574 9575 |
# File 'lib/syntax_tree.rb', line 9573 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
9585 9586 9587 |
# File 'lib/syntax_tree.rb', line 9585 def child_nodes [] end |
#format(q) ⇒ Object
9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 |
# File 'lib/syntax_tree.rb', line 9589 def format(q) opening, closing = "%w[", "]" if elements.any? { |element| element.match?(/[\[\]]/) } opening = beginning.value closing = Quotes.matching(opening[2]) end q.group(0, opening, closing) do q.indent do q.breakable("") q.seplist(elements, -> { q.breakable }) do |element| q.format(element) end end q.breakable("") end end |
#pretty_print(q) ⇒ Object
9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 |
# File 'lib/syntax_tree.rb', line 9608 def pretty_print(q) q.group(2, "(", ")") do q.text("qwords") q.breakable q.group(2, "(", ")") { q.seplist(elements) { |element| q.pp(element) } } q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
9619 9620 9621 9622 9623 |
# File 'lib/syntax_tree.rb', line 9619 def to_json(*opts) { type: :qwords, elems: elements, loc: location, cmts: comments }.to_json( *opts ) end |