Class: SyntaxTree::Ident
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 (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ 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.
5930 5931 5932 5933 5934 |
# File 'lib/syntax_tree/node.rb', line 5930 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
5928 5929 5930 |
# File 'lib/syntax_tree/node.rb', line 5928 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
5925 5926 5927 |
# File 'lib/syntax_tree/node.rb', line 5925 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the identifier
5922 5923 5924 |
# File 'lib/syntax_tree/node.rb', line 5922 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
5936 5937 5938 |
# File 'lib/syntax_tree/node.rb', line 5936 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
5942 5943 5944 |
# File 'lib/syntax_tree/node.rb', line 5942 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
5946 5947 5948 |
# File 'lib/syntax_tree/node.rb', line 5946 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 |
# File 'lib/syntax_tree/node.rb', line 5950 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
5961 5962 5963 5964 5965 5966 5967 5968 |
# File 'lib/syntax_tree/node.rb', line 5961 def to_json(*opts) { type: :ident, value: value.force_encoding("UTF-8"), loc: location, cmts: comments }.to_json(*opts) end |