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
Returns a new instance of QWords.
9654 9655 9656 9657 9658 9659 |
# File 'lib/syntax_tree.rb', line 9654 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
9643 9644 9645 |
# File 'lib/syntax_tree.rb', line 9643 def beginning @beginning end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
9652 9653 9654 |
# File 'lib/syntax_tree.rb', line 9652 def comments @comments end |
#elements ⇒ Object (readonly)
- Array[ TStringContent ]
-
the elements of the array
9646 9647 9648 |
# File 'lib/syntax_tree.rb', line 9646 def elements @elements end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
9649 9650 9651 |
# File 'lib/syntax_tree.rb', line 9649 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
9661 9662 9663 |
# File 'lib/syntax_tree.rb', line 9661 def child_nodes [] end |
#format(q) ⇒ Object
9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 |
# File 'lib/syntax_tree.rb', line 9665 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
9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 |
# File 'lib/syntax_tree.rb', line 9684 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
9695 9696 9697 9698 9699 |
# File 'lib/syntax_tree.rb', line 9695 def to_json(*opts) { type: :qwords, elems: elements, loc: location, cmts: comments }.to_json( *opts ) end |