Class: SyntaxTree::Ident
- Inherits:
-
Object
- Object
- SyntaxTree::Ident
- Defined in:
- lib/syntax_tree.rb
Overview
Ident represents an identifier anywhere in code. It can represent a very large number of things, depending on where it is in the syntax tree.
value
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 identifier.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Ident
constructor
A new instance of Ident.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Ident
Returns a new instance of Ident.
6387 6388 6389 6390 6391 |
# File 'lib/syntax_tree.rb', line 6387 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
6385 6386 6387 |
# File 'lib/syntax_tree.rb', line 6385 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
6382 6383 6384 |
# File 'lib/syntax_tree.rb', line 6382 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the identifier
6379 6380 6381 |
# File 'lib/syntax_tree.rb', line 6379 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
6393 6394 6395 |
# File 'lib/syntax_tree.rb', line 6393 def child_nodes [] end |
#format(q) ⇒ Object
6397 6398 6399 |
# File 'lib/syntax_tree.rb', line 6397 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 |
# File 'lib/syntax_tree.rb', line 6401 def pretty_print(q) q.group(2, "(", ")") do q.text("ident") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
6412 6413 6414 6415 6416 6417 6418 6419 |
# File 'lib/syntax_tree.rb', line 6412 def to_json(*opts) { type: :ident, value: value.force_encoding("UTF-8"), loc: location, cmts: comments }.to_json(*opts) end |