Class: SyntaxTree::Paren
- Inherits:
-
Object
- Object
- SyntaxTree::Paren
- Defined in:
- lib/syntax_tree.rb
Overview
Paren represents using balanced parentheses in a couple places in a Ruby program. In general parentheses can be used anywhere a Ruby expression can be used.
(1 + 2)
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#contents ⇒ Object
readonly
- untyped
-
the expression inside the parentheses.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#lparen ⇒ Object
readonly
- LParen
-
the left parenthesis that opened this statement.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
constructor
A new instance of Paren.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(lparen:, contents:, location:, comments: []) ⇒ Paren
8728 8729 8730 8731 8732 8733 |
# File 'lib/syntax_tree.rb', line 8728 def initialize(lparen:, contents:, location:, comments: []) @lparen = lparen @contents = contents @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8726 8727 8728 |
# File 'lib/syntax_tree.rb', line 8726 def comments @comments end |
#contents ⇒ Object (readonly)
- untyped
-
the expression inside the parentheses
8720 8721 8722 |
# File 'lib/syntax_tree.rb', line 8720 def contents @contents end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8723 8724 8725 |
# File 'lib/syntax_tree.rb', line 8723 def location @location end |
#lparen ⇒ Object (readonly)
- LParen
-
the left parenthesis that opened this statement
8717 8718 8719 |
# File 'lib/syntax_tree.rb', line 8717 def lparen @lparen end |
Instance Method Details
#child_nodes ⇒ Object
8735 8736 8737 |
# File 'lib/syntax_tree.rb', line 8735 def child_nodes [lparen, contents] end |
#format(q) ⇒ Object
8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 |
# File 'lib/syntax_tree.rb', line 8739 def format(q) q.group do q.format(lparen) if !contents.is_a?(Params) || !contents.empty? q.indent do q.breakable("") q.format(contents) end end q.breakable("") q.text(")") end end |
#pretty_print(q) ⇒ Object
8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 |
# File 'lib/syntax_tree.rb', line 8755 def pretty_print(q) q.group(2, "(", ")") do q.text("paren") q.breakable q.pp(contents) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8766 8767 8768 8769 8770 8771 8772 8773 8774 |
# File 'lib/syntax_tree.rb', line 8766 def to_json(*opts) { type: :paren, lparen: lparen, cnts: contents, loc: location, cmts: comments }.to_json(*opts) end |