Class: SyntaxTree::Not
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::Not
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
Not represents the unary not method being called on an expression.
not 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(statement:, parentheses:, location:) ⇒ Not
11040
11041
11042
11043
11044
11045
|
# File 'lib/syntax_tree/node.rb', line 11040
def initialize(statement:, parentheses:, location:)
@statement = statement
@parentheses = parentheses
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11038
11039
11040
|
# File 'lib/syntax_tree/node.rb', line 11038
def
end
|
#parentheses ⇒ Object
Also known as:
parentheses?
- boolean
-
whether or not parentheses were used
11034
11035
11036
|
# File 'lib/syntax_tree/node.rb', line 11034
def parentheses
@parentheses
end
|
#statement ⇒ Object
- nil | Node
-
the statement on which to operate
11031
11032
11033
|
# File 'lib/syntax_tree/node.rb', line 11031
def statement
@statement
end
|
Instance Method Details
#===(other) ⇒ Object
11102
11103
11104
11105
|
# File 'lib/syntax_tree/node.rb', line 11102
def ===(other)
other.is_a?(Not) && statement === other.statement &&
parentheses === other.parentheses
end
|
#accept(visitor) ⇒ Object
11047
11048
11049
|
# File 'lib/syntax_tree/node.rb', line 11047
def accept(visitor)
visitor.visit_not(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
11051
11052
11053
|
# File 'lib/syntax_tree/node.rb', line 11051
def child_nodes
[statement]
end
|
#copy(statement: nil, parentheses: nil, location: nil) ⇒ Object
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
|
# File 'lib/syntax_tree/node.rb', line 11055
def copy(statement: nil, parentheses: nil, location: nil)
node =
Not.new(
statement: statement || self.statement,
parentheses: parentheses || self.parentheses,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
11069
11070
11071
11072
11073
11074
11075
11076
|
# File 'lib/syntax_tree/node.rb', line 11069
def deconstruct_keys(_keys)
{
statement: statement,
parentheses: parentheses,
location: location,
comments:
}
end
|
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
|
# File 'lib/syntax_tree/node.rb', line 11078
def format(q)
q.text("not")
if parentheses
q.text("(")
q.format(statement) if statement
q.text(")")
else
grandparent = q.grandparent
ternary =
(grandparent.is_a?(IfNode) || grandparent.is_a?(UnlessNode)) &&
Ternaryable.call(q, grandparent)
if ternary
q.if_break { q.text(" ") }.if_flat { q.text("(") }
q.format(statement) if statement
q.if_flat { q.text(")") } if ternary
else
q.text(" ")
q.format(statement) if statement
end
end
end
|