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.
7801 7802 7803 7804 7805 |
# File 'lib/syntax_tree.rb', line 7801 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
7799 7800 7801 |
# File 'lib/syntax_tree.rb', line 7799 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7796 7797 7798 |
# File 'lib/syntax_tree.rb', line 7796 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the label
7793 7794 7795 |
# File 'lib/syntax_tree.rb', line 7793 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7807 7808 7809 |
# File 'lib/syntax_tree.rb', line 7807 def child_nodes [] end |
#format(q) ⇒ Object
7811 7812 7813 |
# File 'lib/syntax_tree.rb', line 7811 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 |
# File 'lib/syntax_tree.rb', line 7815 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
7827 7828 7829 7830 7831 |
# File 'lib/syntax_tree.rb', line 7827 def to_json(*opts) { type: :label, value: value, loc: location, cmts: comments }.to_json( *opts ) end |