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.



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

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



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

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1958
1959
1960
# File 'lib/syntax_tree/node.rb', line 1958

def statement
  @statement
end

Instance Method Details

#===(other) ⇒ Object



2008
2009
2010
# File 'lib/syntax_tree/node.rb', line 2008

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



1973
1974
1975
# File 'lib/syntax_tree/node.rb', line 1973

def child_nodes
  [statement]
end

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



1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
# File 'lib/syntax_tree/node.rb', line 1977

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



1990
1991
1992
# File 'lib/syntax_tree/node.rb', line 1990

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

#format(q) ⇒ Object



1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
# File 'lib/syntax_tree/node.rb', line 1994

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