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, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(statement:, location:) ⇒ PinnedBegin

Returns a new instance of PinnedBegin.



1969
1970
1971
1972
1973
# File 'lib/syntax_tree/node.rb', line 1969

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1967
1968
1969
# File 'lib/syntax_tree/node.rb', line 1967

def comments
  @comments
end

#statementObject (readonly)

Node

the expression being pinned



1964
1965
1966
# File 'lib/syntax_tree/node.rb', line 1964

def statement
  @statement
end

Instance Method Details

#===(other) ⇒ Object



2014
2015
2016
# File 'lib/syntax_tree/node.rb', line 2014

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

#accept(visitor) ⇒ Object



1975
1976
1977
# File 'lib/syntax_tree/node.rb', line 1975

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

#child_nodesObject Also known as: deconstruct



1979
1980
1981
# File 'lib/syntax_tree/node.rb', line 1979

def child_nodes
  [statement]
end

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



1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
# File 'lib/syntax_tree/node.rb', line 1983

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



1996
1997
1998
# File 'lib/syntax_tree/node.rb', line 1996

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

#format(q) ⇒ Object



2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
# File 'lib/syntax_tree/node.rb', line 2000

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