Class: SyntaxTree::PinnedBegin

Inherits:
Node
  • Object
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, #pretty_print, #to_json

Constructor Details

#initialize(statement:, location:) ⇒ PinnedBegin

Returns a new instance of PinnedBegin.



1917
1918
1919
1920
1921
# File 'lib/syntax_tree/node.rb', line 1917

def initialize(statement:, location:)
  @statement = statement
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1915
1916
1917
# File 'lib/syntax_tree/node.rb', line 1915

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1912
1913
1914
# File 'lib/syntax_tree/node.rb', line 1912

def statement
  @statement
end

Instance Method Details

#===(other) ⇒ Object



1962
1963
1964
# File 'lib/syntax_tree/node.rb', line 1962

def ===(other)
  other.is_a?(PinnedBegin) && statement === other.statement
end

#accept(visitor) ⇒ Object



1923
1924
1925
# File 'lib/syntax_tree/node.rb', line 1923

def accept(visitor)
  visitor.visit_pinned_begin(self)
end

#child_nodesObject Also known as: deconstruct



1927
1928
1929
# File 'lib/syntax_tree/node.rb', line 1927

def child_nodes
  [statement]
end

#copy(statement: nil, location: nil) ⇒ Object



1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
# File 'lib/syntax_tree/node.rb', line 1931

def copy(statement: nil, location: nil)
  node =
    PinnedBegin.new(
      statement: statement || self.statement,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



1944
1945
1946
# File 'lib/syntax_tree/node.rb', line 1944

def deconstruct_keys(_keys)
  { statement: statement, location: location, comments: comments }
end

#format(q) ⇒ Object



1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
# File 'lib/syntax_tree/node.rb', line 1948

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