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.



1446
1447
1448
1449
1450
# File 'lib/syntax_tree/node.rb', line 1446

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



1444
1445
1446
# File 'lib/syntax_tree/node.rb', line 1444

def comments
  @comments
end

#statementObject (readonly)

untyped

the expression being pinned



1441
1442
1443
# File 'lib/syntax_tree/node.rb', line 1441

def statement
  @statement
end

Instance Method Details

#accept(visitor) ⇒ Object



1452
1453
1454
# File 'lib/syntax_tree/node.rb', line 1452

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

#child_nodesObject Also known as: deconstruct



1456
1457
1458
# File 'lib/syntax_tree/node.rb', line 1456

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



1462
1463
1464
# File 'lib/syntax_tree/node.rb', line 1462

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

#format(q) ⇒ Object



1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
# File 'lib/syntax_tree/node.rb', line 1466

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