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:, comments: []) ⇒ PinnedBegin



1608
1609
1610
1611
1612
# File 'lib/syntax_tree/node.rb', line 1608

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1606
1607
1608
# File 'lib/syntax_tree/node.rb', line 1606

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1603
1604
1605
# File 'lib/syntax_tree/node.rb', line 1603

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



1614
1615
1616
# File 'lib/syntax_tree/node.rb', line 1614

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

#child_nodesObject Also known as: deconstruct



1618
1619
1620
# File 'lib/syntax_tree/node.rb', line 1618

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



1624
1625
1626
# File 'lib/syntax_tree/node.rb', line 1624

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

#format(q) ⇒ Object



1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
# File 'lib/syntax_tree/node.rb', line 1628

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