Class: SyntaxTree::PinnedBegin
- Inherits:
-
Node
- Object
- Node
- SyntaxTree::PinnedBegin
show all
- Defined in:
- lib/syntax_tree/node.rb
Overview
PinnedBegin represents a pinning a nested statement within pattern matching.
case value
in ^(statement)
end
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:, location:) ⇒ PinnedBegin
Returns a new instance of PinnedBegin.
1942
1943
1944
1945
1946
|
# File 'lib/syntax_tree/node.rb', line 1942
def initialize(statement:, location:)
@statement = statement
@location = location
= []
end
|
Instance Attribute Details
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
1940
1941
1942
|
# File 'lib/syntax_tree/node.rb', line 1940
def
end
|
#statement ⇒ Object
- Node
-
the expression being pinned
1937
1938
1939
|
# File 'lib/syntax_tree/node.rb', line 1937
def statement
@statement
end
|
Instance Method Details
#===(other) ⇒ Object
1987
1988
1989
|
# File 'lib/syntax_tree/node.rb', line 1987
def ===(other)
other.is_a?(PinnedBegin) && statement === other.statement
end
|
#accept(visitor) ⇒ Object
1948
1949
1950
|
# File 'lib/syntax_tree/node.rb', line 1948
def accept(visitor)
visitor.visit_pinned_begin(self)
end
|
#child_nodes ⇒ Object
Also known as:
deconstruct
1952
1953
1954
|
# File 'lib/syntax_tree/node.rb', line 1952
def child_nodes
[statement]
end
|
#copy(statement: nil, location: nil) ⇒ Object
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
|
# File 'lib/syntax_tree/node.rb', line 1956
def copy(statement: nil, location: nil)
node =
PinnedBegin.new(
statement: statement || self.statement,
location: location || self.location
)
node..concat(.map(&:copy))
node
end
|
#deconstruct_keys(_keys) ⇒ Object
1969
1970
1971
|
# File 'lib/syntax_tree/node.rb', line 1969
def deconstruct_keys(_keys)
{ statement: statement, location: location, comments: }
end
|
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
|
# File 'lib/syntax_tree/node.rb', line 1973
def format(q)
q.group do
q.text("^(")
q.nest(1) do
q.indent do
q.breakable_empty
q.format(statement)
end
q.breakable_empty
q.text(")")
end
end
end
|