Class: SyntaxTree::PinnedBegin

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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.



2362
2363
2364
2365
2366
# File 'lib/syntax_tree.rb', line 2362

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



2360
2361
2362
# File 'lib/syntax_tree.rb', line 2360

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



2357
2358
2359
# File 'lib/syntax_tree.rb', line 2357

def location
  @location
end

#statementObject (readonly)

untyped

the expression being pinned



2354
2355
2356
# File 'lib/syntax_tree.rb', line 2354

def statement
  @statement
end

Instance Method Details

#child_nodesObject



2368
2369
2370
# File 'lib/syntax_tree.rb', line 2368

def child_nodes
  [statement]
end

#format(q) ⇒ Object



2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
# File 'lib/syntax_tree.rb', line 2372

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



2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
# File 'lib/syntax_tree.rb', line 2386

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



2397
2398
2399
2400
2401
2402
2403
2404
# File 'lib/syntax_tree.rb', line 2397

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