Class: SyntaxTree::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Command represents a method call with arguments and no parentheses. Note that Command nodes only happen when there is no explicit receiver for this method.

method argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message:, arguments:, location:, comments: []) ⇒ Command

Returns a new instance of Command.



3418
3419
3420
3421
3422
3423
# File 'lib/syntax_tree.rb', line 3418

def initialize(message:, arguments:, location:, comments: [])
  @message = message
  @arguments = arguments
  @location = location
  @comments = comments
end

Instance Attribute Details

#argumentsObject (readonly)

Args

the arguments being sent with the message



3410
3411
3412
# File 'lib/syntax_tree.rb', line 3410

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3416
3417
3418
# File 'lib/syntax_tree.rb', line 3416

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3413
3414
3415
# File 'lib/syntax_tree.rb', line 3413

def location
  @location
end

#messageObject (readonly)

Const | Ident

the message being sent to the implicit receiver



3407
3408
3409
# File 'lib/syntax_tree.rb', line 3407

def message
  @message
end

Instance Method Details

#child_nodesObject



3425
3426
3427
# File 'lib/syntax_tree.rb', line 3425

def child_nodes
  [message, arguments]
end

#format(q) ⇒ Object



3429
3430
3431
3432
3433
3434
3435
# File 'lib/syntax_tree.rb', line 3429

def format(q)
  q.group do
    q.format(message)
    q.text(" ")
    q.nest(message.value.length + 1) { q.format(arguments) }
  end
end

#pretty_print(q) ⇒ Object



3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
# File 'lib/syntax_tree.rb', line 3437

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

    q.breakable
    q.pp(message)

    q.breakable
    q.pp(arguments)

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

#to_json(*opts) ⇒ Object



3451
3452
3453
3454
3455
3456
3457
3458
3459
# File 'lib/syntax_tree.rb', line 3451

def to_json(*opts)
  {
    type: :command,
    message: message,
    args: arguments,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end