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.
7099 7100 7101 7102 7103 |
# File 'lib/syntax_tree.rb', line 7099 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
7097 7098 7099 |
# File 'lib/syntax_tree.rb', line 7097 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
7094 7095 7096 |
# File 'lib/syntax_tree.rb', line 7094 def location @location end |
#value ⇒ Object (readonly)
- String
-
the value of the keyword
7091 7092 7093 |
# File 'lib/syntax_tree.rb', line 7091 def value @value end |
Instance Method Details
#child_nodes ⇒ Object
7105 7106 7107 |
# File 'lib/syntax_tree.rb', line 7105 def child_nodes [] end |
#format(q) ⇒ Object
7109 7110 7111 |
# File 'lib/syntax_tree.rb', line 7109 def format(q) q.text(value) end |
#pretty_print(q) ⇒ Object
7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 |
# File 'lib/syntax_tree.rb', line 7113 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
7124 7125 7126 |
# File 'lib/syntax_tree.rb', line 7124 def to_json(*opts) { type: :kw, value: value, loc: location, cmts: comments }.to_json(*opts) end |