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.
7225 7226 7227 7228 7229 |
# File 'lib/syntax_tree.rb', line 7225 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
7223 7224 7225 |
# File 'lib/syntax_tree.rb', line 7223 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7220 7221 7222 |
# File 'lib/syntax_tree.rb', line 7220 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the label
7217 7218 7219 |
# File 'lib/syntax_tree.rb', line 7217 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7231 7232 7233 |
# File 'lib/syntax_tree.rb', line 7231 def child_nodes [] end |
#format(q) ⇒ Object
7235 7236 7237 |
# File 'lib/syntax_tree.rb', line 7235 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 |
# File 'lib/syntax_tree.rb', line 7239 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
7251 7252 7253 7254 7255 |
# File 'lib/syntax_tree.rb', line 7251 def to_json(*opts) { type: :label, value: value, loc: location, cmts: comments }.to_json( *opts ) end |