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

Returns a new instance of PinnedBegin.



1558
1559
1560
1561
1562
# File 'lib/syntax_tree/node.rb', line 1558

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



1556
1557
1558
# File 'lib/syntax_tree/node.rb', line 1556

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1553
1554
1555
# File 'lib/syntax_tree/node.rb', line 1553

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



1564
1565
1566
# File 'lib/syntax_tree/node.rb', line 1564

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

#child_nodesObject Also known as: deconstruct



1568
1569
1570
# File 'lib/syntax_tree/node.rb', line 1568

def child_nodes
  [statement]
end

#deconstruct_keys(_keys) ⇒ Object



1574
1575
1576
# File 'lib/syntax_tree/node.rb', line 1574

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

#format(q) ⇒ Object



1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
# File 'lib/syntax_tree/node.rb', line 1578

def format(q)
  q.group do
    q.text("^(")
    q.nest(1) do
      q.indent do
        q.breakable("")
        q.format(statement)
      end
      q.breakable("")
      q.text(")")
    end
  end
end