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.



3668
3669
3670
3671
3672
3673
# File 'lib/syntax_tree.rb', line 3668

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



3660
3661
3662
# File 'lib/syntax_tree.rb', line 3660

def arguments
  @arguments
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



3666
3667
3668
# File 'lib/syntax_tree.rb', line 3666

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



3663
3664
3665
# File 'lib/syntax_tree.rb', line 3663

def location
  @location
end

#messageObject (readonly)

Const | Ident

the message being sent to the implicit receiver



3657
3658
3659
# File 'lib/syntax_tree.rb', line 3657

def message
  @message
end

Instance Method Details

#child_nodesObject



3675
3676
3677
# File 'lib/syntax_tree.rb', line 3675

def child_nodes
  [message, arguments]
end

#format(q) ⇒ Object



3679
3680
3681
3682
3683
3684
3685
# File 'lib/syntax_tree.rb', line 3679

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



3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
# File 'lib/syntax_tree.rb', line 3687

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



3701
3702
3703
3704
3705
3706
3707
3708
3709
# File 'lib/syntax_tree.rb', line 3701

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