Class: SyntaxTree::Label
- Inherits:
-
Object
- Object
- SyntaxTree::Label
- Defined in:
- lib/syntax_tree.rb
Overview
Label represents the use of an identifier to associate with an object. You can find it in a hash key, as in:
{ key: value }
In this case “key:” would be the body of the label. You can also find it in pattern matching, as in:
case value
in key:
end
In this case “key:” would be the body of the label.
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 value of the label.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Label
constructor
A new instance of Label.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Label
Returns a new instance of Label.
7669 7670 7671 7672 7673 |
# File 'lib/syntax_tree.rb', line 7669 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
7667 7668 7669 |
# File 'lib/syntax_tree.rb', line 7667 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7664 7665 7666 |
# File 'lib/syntax_tree.rb', line 7664 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the label
7661 7662 7663 |
# File 'lib/syntax_tree.rb', line 7661 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7675 7676 7677 |
# File 'lib/syntax_tree.rb', line 7675 def child_nodes [] end |
#format(q) ⇒ Object
7679 7680 7681 |
# File 'lib/syntax_tree.rb', line 7679 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 |
# File 'lib/syntax_tree.rb', line 7683 def pretty_print(q) q.group(2, "(", ")") do q.text("label") q.breakable q.text(":") q.text(value[0...-1]) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
7695 7696 7697 7698 7699 |
# File 'lib/syntax_tree.rb', line 7695 def to_json(*opts) { type: :label, value: value, loc: location, cmts: comments }.to_json( *opts ) end |