Class: SyntaxTree::Kw
- Inherits:
-
Object
- Object
- SyntaxTree::Kw
- Defined in:
- lib/syntax_tree.rb
Overview
Kw represents the use of a keyword. It can be almost anywhere in the syntax tree, so you end up seeing it quite a lot.
if value
end
In the above example, there would be two Kw nodes: one for the if and one for the end. Note that anything that matches the list of keywords in Ruby will use a Kw, so if you use a keyword in a symbol literal for instance:
:if
then the contents of the symbol node will contain a Kw node.
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 keyword.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ Kw
constructor
A new instance of Kw.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ Kw
Returns a new instance of Kw.
7470 7471 7472 7473 7474 |
# File 'lib/syntax_tree.rb', line 7470 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
7468 7469 7470 |
# File 'lib/syntax_tree.rb', line 7468 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7465 7466 7467 |
# File 'lib/syntax_tree.rb', line 7465 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the keyword
7462 7463 7464 |
# File 'lib/syntax_tree.rb', line 7462 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7476 7477 7478 |
# File 'lib/syntax_tree.rb', line 7476 def child_nodes [] end |
#format(q) ⇒ Object
7480 7481 7482 |
# File 'lib/syntax_tree.rb', line 7480 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 |
# File 'lib/syntax_tree.rb', line 7484 def pretty_print(q) q.group(2, "(", ")") do q.text("kw") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
7495 7496 7497 |
# File 'lib/syntax_tree.rb', line 7495 def to_json(*opts) { type: :kw, value: value, loc: location, cmts: comments }.to_json(*opts) end |