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

#pretty_print, #to_json

Constructor Details

#initialize(statement:, location:, comments: []) ⇒ PinnedBegin

Returns a new instance of PinnedBegin.



1494
1495
1496
1497
1498
# File 'lib/syntax_tree/node.rb', line 1494

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



1492
1493
1494
# File 'lib/syntax_tree/node.rb', line 1492

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1489
1490
1491
# File 'lib/syntax_tree/node.rb', line 1489

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



1500
1501
1502
# File 'lib/syntax_tree/node.rb', line 1500

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

#child_nodesObject Also known as: deconstruct



1504
1505
1506
# File 'lib/syntax_tree/node.rb', line 1504

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



1510
1511
1512
# File 'lib/syntax_tree/node.rb', line 1510

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

#format(q) ⇒ Object



1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
# File 'lib/syntax_tree/node.rb', line 1514

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