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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PinnedBegin.



1861
1862
1863
1864
1865
# File 'lib/syntax_tree/node.rb', line 1861

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



1859
1860
1861
# File 'lib/syntax_tree/node.rb', line 1859

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1856
1857
1858
# File 'lib/syntax_tree/node.rb', line 1856

def location
  @location
end

#statementObject (readonly)

untyped

the expression being pinned



1853
1854
1855
# File 'lib/syntax_tree/node.rb', line 1853

def statement
  @statement
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



1867
1868
1869
# File 'lib/syntax_tree/node.rb', line 1867

def child_nodes
  [statement]
end

#deconstruct_keys(keys) ⇒ Object



1873
1874
1875
# File 'lib/syntax_tree/node.rb', line 1873

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

#format(q) ⇒ Object



1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
# File 'lib/syntax_tree/node.rb', line 1877

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

#pretty_print(q) ⇒ Object



1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
# File 'lib/syntax_tree/node.rb', line 1891

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("pinned_begin")

    q.breakable
    q.pp(statement)

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



1902
1903
1904
1905
1906
1907
1908
1909
# File 'lib/syntax_tree/node.rb', line 1902

def to_json(*opts)
  {
    type: :pinned_begin,
    stmt: statement,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end