Class: SyntaxTree::Unary
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Unary
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Unary represents a unary method being called on an expression, as in ! or ~.
!value
Instance Attribute Summary collapse
Attributes inherited from Node
#location
Instance Method Summary
collapse
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(operator:, statement:, location:) ⇒ Unary
11171
11172
11173
11174
11175
11176
|
# File 'lib/syntax_tree/node.rb', line 11171
def initialize(operator:, statement:, location:)
@operator = operator
@statement = statement
@location = location
@comments = []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11169
11170
11171
|
# File 'lib/syntax_tree/node.rb', line 11169
def
@comments
end
|
#operator ⇒ Object
- String
-
the operator being used
11163
11164
11165
|
# File 'lib/syntax_tree/node.rb', line 11163
def operator
@operator
end
|
#statement ⇒ Object
- Node
-
the statement on which to operate
11166
11167
11168
|
# File 'lib/syntax_tree/node.rb', line 11166
def statement
@statement
end
|
Instance Method Details
#===(other) ⇒ Object
11214
11215
11216
11217
|
# File 'lib/syntax_tree/node.rb', line 11214
def ===(other)
other.is_a?(Unary) && operator === other.operator &&
statement === other.statement
end
|
#accept(visitor) ⇒ Object
11178
11179
11180
|
# File 'lib/syntax_tree/node.rb', line 11178
def accept(visitor)
visitor.visit_unary(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11182
11183
11184
|
# File 'lib/syntax_tree/node.rb', line 11182
def child_nodes
[statement]
end
|
#copy(operator: nil, statement: nil, location: nil) ⇒ Object
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
|
# File 'lib/syntax_tree/node.rb', line 11186
def copy(operator: nil, statement: nil, location: nil)
node =
Unary.new(
operator: operator || self.operator,
statement: statement || self.statement,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
11200
11201
11202
11203
11204
11205
11206
11207
|
# File 'lib/syntax_tree/node.rb', line 11200
def deconstruct_keys(_keys)
{
operator: operator,
statement: statement,
location: location,
comments:
}
end
|
11209
11210
11211
11212
|
# File 'lib/syntax_tree/node.rb', line 11209
def format(q)
q.text(operator)
q.format(statement)
end
|