Class: SyntaxTree::Dot2
- Inherits:
-
Object
- Object
- SyntaxTree::Dot2
- Defined in:
- lib/syntax_tree.rb
Overview
Dot2 represents using the .. operator between two expressions. Usually this is to create a range object.
1..2
Sometimes this operator is used to create a flip-flop.
if value == 5 .. value == 10
end
One of the sides of the expression may be nil, but not both.
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#left ⇒ Object
readonly
- nil | untyped
-
the left side of the expression.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#right ⇒ Object
readonly
- nil | untyped
-
the right side of the expression.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(left:, right:, location:, comments: []) ⇒ Dot2
constructor
A new instance of Dot2.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(left:, right:, location:, comments: []) ⇒ Dot2
Returns a new instance of Dot2.
4913 4914 4915 4916 4917 4918 |
# File 'lib/syntax_tree.rb', line 4913 def initialize(left:, right:, location:, comments: []) @left = left @right = right @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4911 4912 4913 |
# File 'lib/syntax_tree.rb', line 4911 def comments @comments end |
#left ⇒ Object (readonly)
- nil | untyped
-
the left side of the expression
4902 4903 4904 |
# File 'lib/syntax_tree.rb', line 4902 def left @left end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
4908 4909 4910 |
# File 'lib/syntax_tree.rb', line 4908 def location @location end |
#right ⇒ Object (readonly)
- nil | untyped
-
the right side of the expression
4905 4906 4907 |
# File 'lib/syntax_tree.rb', line 4905 def right @right end |
Instance Method Details
#child_nodes ⇒ Object
4920 4921 4922 |
# File 'lib/syntax_tree.rb', line 4920 def child_nodes [left, right] end |
#format(q) ⇒ Object
4924 4925 4926 |
# File 'lib/syntax_tree.rb', line 4924 def format(q) DotFormatter.new("..", self).format(q) end |
#pretty_print(q) ⇒ Object
4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 |
# File 'lib/syntax_tree.rb', line 4928 def pretty_print(q) q.group(2, "(", ")") do q.text("dot2") if left q.breakable q.pp(left) end if right q.breakable q.pp(right) end q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
4946 4947 4948 4949 4950 4951 4952 4953 4954 |
# File 'lib/syntax_tree.rb', line 4946 def to_json(*opts) { type: :dot2, left: left, right: right, loc: location, cmts: comments }.to_json(*opts) end |