Class: SyntaxTree::Op
- Inherits:
-
Object
- Object
- SyntaxTree::Op
- Defined in:
- lib/syntax_tree.rb
Overview
Op represents an operator literal in the source.
1 + 2
In the example above, the Op node represents the + operator.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the operator.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Op
constructor
A new instance of Op.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Op
Returns a new instance of Op.
8606 8607 8608 8609 8610 |
# File 'lib/syntax_tree.rb', line 8606 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
8604 8605 8606 |
# File 'lib/syntax_tree.rb', line 8604 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
8601 8602 8603 |
# File 'lib/syntax_tree.rb', line 8601 def location @location end |
#value ⇒ Object (readonly)
- String
-
the operator
8598 8599 8600 |
# File 'lib/syntax_tree.rb', line 8598 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
8612 8613 8614 |
# File 'lib/syntax_tree.rb', line 8612 def child_nodes [] end |
#format(q) ⇒ Object
8616 8617 8618 |
# File 'lib/syntax_tree.rb', line 8616 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 |
# File 'lib/syntax_tree.rb', line 8620 def pretty_print(q) q.group(2, "(", ")") do q.text("op") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
8631 8632 8633 |
# File 'lib/syntax_tree.rb', line 8631 def to_json(*opts) { type: :op, value: value, loc: location, cmts: comments }.to_json(*opts) end |