@@ -3056,9 +3056,7 @@ def format(q)
3056
3056
end
3057
3057
end
3058
3058
3059
- # Call represents a method call. This node doesn't contain the arguments being
3060
- # passed (if arguments are passed, this node will get nested under a
3061
- # MethodAddArg node).
3059
+ # Call represents a method call.
3062
3060
#
3063
3061
# receiver.message
3064
3062
#
@@ -3072,22 +3070,26 @@ class Call
3072
3070
# [:call | Backtick | Const | Ident | Op] the message being sent
3073
3071
attr_reader :message
3074
3072
3073
+ # [nil | ArgParen | Args] the arguments to the method call
3074
+ attr_reader :arguments
3075
+
3075
3076
# [Location] the location of this node
3076
3077
attr_reader :location
3077
3078
3078
3079
# [Array[ Comment | EmbDoc ]] the comments attached to this node
3079
3080
attr_reader :comments
3080
3081
3081
- def initialize ( receiver :, operator :, message :, location :, comments : [ ] )
3082
+ def initialize ( receiver :, operator :, message :, arguments : , location :, comments : [ ] )
3082
3083
@receiver = receiver
3083
3084
@operator = operator
3084
3085
@message = message
3086
+ @arguments = arguments
3085
3087
@location = location
3086
3088
@comments = comments
3087
3089
end
3088
3090
3089
3091
def child_nodes
3090
- [ receiver , ( operator if operator != :"::" ) , ( message if message != :call ) ]
3092
+ [ receiver , ( operator if operator != :"::" ) , ( message if message != :call ) , arguments ]
3091
3093
end
3092
3094
3093
3095
def format ( q )
@@ -3098,6 +3100,7 @@ def format(q)
3098
3100
q . breakable ( force : true ) if receiver . comments . any?
3099
3101
q . format ( CallOperatorFormatter . new ( operator ) )
3100
3102
q . format ( message ) if message != :call
3103
+ q . format ( arguments ) if arguments
3101
3104
end
3102
3105
end
3103
3106
end
@@ -3116,6 +3119,11 @@ def pretty_print(q)
3116
3119
q . breakable
3117
3120
q . pp ( message )
3118
3121
3122
+ if arguments
3123
+ q . breakable
3124
+ q . pp ( arguments )
3125
+ end
3126
+
3119
3127
q . pp ( Comment ::List . new ( comments ) )
3120
3128
end
3121
3129
end
@@ -3126,6 +3134,7 @@ def to_json(*opts)
3126
3134
receiver : receiver ,
3127
3135
op : operator ,
3128
3136
message : message ,
3137
+ args : arguments ,
3129
3138
loc : location ,
3130
3139
cmts : comments
3131
3140
} . to_json ( *opts )
@@ -3146,6 +3155,7 @@ def on_call(receiver, operator, message)
3146
3155
receiver : receiver ,
3147
3156
operator : operator ,
3148
3157
message : message ,
3158
+ arguments : nil ,
3149
3159
location : receiver . location . to ( ending . location )
3150
3160
)
3151
3161
end
@@ -5617,24 +5627,29 @@ class FCall
5617
5627
# [Const | Ident] the name of the method
5618
5628
attr_reader :value
5619
5629
5630
+ # [nil | ArgParen | Args] the arguments to the method call
5631
+ attr_reader :arguments
5632
+
5620
5633
# [Location] the location of this node
5621
5634
attr_reader :location
5622
5635
5623
5636
# [Array[ Comment | EmbDoc ]] the comments attached to this node
5624
5637
attr_reader :comments
5625
5638
5626
- def initialize ( value :, location :, comments : [ ] )
5639
+ def initialize ( value :, arguments : , location :, comments : [ ] )
5627
5640
@value = value
5641
+ @arguments = arguments
5628
5642
@location = location
5629
5643
@comments = comments
5630
5644
end
5631
5645
5632
5646
def child_nodes
5633
- [ value ]
5647
+ [ value , arguments ]
5634
5648
end
5635
5649
5636
5650
def format ( q )
5637
5651
q . format ( value )
5652
+ q . format ( arguments )
5638
5653
end
5639
5654
5640
5655
def pretty_print ( q )
@@ -5644,12 +5659,17 @@ def pretty_print(q)
5644
5659
q . breakable
5645
5660
q . pp ( value )
5646
5661
5662
+ if arguments
5663
+ q . breakable
5664
+ q . pp ( arguments )
5665
+ end
5666
+
5647
5667
q . pp ( Comment ::List . new ( comments ) )
5648
5668
end
5649
5669
end
5650
5670
5651
5671
def to_json ( *opts )
5652
- { type : :fcall , value : value , loc : location , cmts : comments } . to_json (
5672
+ { type : :fcall , value : value , args : arguments , loc : location , cmts : comments } . to_json (
5653
5673
*opts
5654
5674
)
5655
5675
end
@@ -5658,7 +5678,7 @@ def to_json(*opts)
5658
5678
# :call-seq:
5659
5679
# on_fcall: ((Const | Ident) value) -> FCall
5660
5680
def on_fcall ( value )
5661
- FCall . new ( value : value , location : value . location )
5681
+ FCall . new ( value : value , arguments : nil , location : value . location )
5662
5682
end
5663
5683
5664
5684
# Field is always the child of an assignment. It represents assigning to a
@@ -7847,94 +7867,34 @@ def on_massign(target, value)
7847
7867
)
7848
7868
end
7849
7869
7850
- # MethodAddArg represents a method call with arguments and parentheses.
7851
- #
7852
- # method(argument)
7853
- #
7854
- # MethodAddArg can also represent with a method on an object, as in:
7855
- #
7856
- # object.method(argument)
7857
- #
7858
- # Finally, MethodAddArg can represent calling a method with no receiver that
7859
- # ends in a ?. In this case, the parser knows it's a method call and not a
7860
- # local variable, so it uses a MethodAddArg node as opposed to a VCall node,
7861
- # as in:
7862
- #
7863
- # method?
7864
- #
7865
- class MethodAddArg
7866
- # [Call | FCall] the method call
7867
- attr_reader :call
7868
-
7869
- # [ArgParen | Args] the arguments to the method call
7870
- attr_reader :arguments
7871
-
7872
- # [Location] the location of this node
7873
- attr_reader :location
7874
-
7875
- # [Array[ Comment | EmbDoc ]] the comments attached to this node
7876
- attr_reader :comments
7877
-
7878
- def initialize ( call :, arguments :, location :, comments : [ ] )
7879
- @call = call
7880
- @arguments = arguments
7881
- @location = location
7882
- @comments = comments
7883
- end
7884
-
7885
- def child_nodes
7886
- [ call , arguments ]
7887
- end
7888
-
7889
- def format ( q )
7890
- q . format ( call )
7891
- q . text ( " " ) if !arguments . is_a? ( ArgParen ) && arguments . parts . any?
7892
- q . format ( arguments )
7893
- end
7894
-
7895
- def pretty_print ( q )
7896
- q . group ( 2 , "(" , ")" ) do
7897
- q . text ( "method_add_arg" )
7898
-
7899
- q . breakable
7900
- q . pp ( call )
7901
-
7902
- q . breakable
7903
- q . pp ( arguments )
7904
-
7905
- q . pp ( Comment ::List . new ( comments ) )
7906
- end
7907
- end
7908
-
7909
- def to_json ( *opts )
7910
- {
7911
- type : :method_add_arg ,
7912
- call : call ,
7913
- args : arguments ,
7914
- loc : location ,
7915
- cmts : comments
7916
- } . to_json ( *opts )
7917
- end
7918
- end
7919
-
7920
7870
# :call-seq:
7921
7871
# on_method_add_arg: (
7922
7872
# (Call | FCall) call,
7923
7873
# (ArgParen | Args) arguments
7924
- # ) -> MethodAddArg
7874
+ # ) -> Call | FCall
7925
7875
def on_method_add_arg ( call , arguments )
7926
7876
location = call . location
7927
- location = location . to ( arguments . location ) unless arguments . is_a? ( Args )
7877
+ location = location . to ( arguments . location ) if arguments . is_a? ( ArgParen )
7928
7878
7929
- MethodAddArg . new ( call : call , arguments : arguments , location : location )
7879
+ if call . is_a? ( FCall )
7880
+ FCall . new ( value : call . value , arguments : arguments , location : location )
7881
+ else
7882
+ Call . new (
7883
+ receiver : call . receiver ,
7884
+ operator : call . operator ,
7885
+ message : call . message ,
7886
+ arguments : arguments ,
7887
+ location : location
7888
+ )
7889
+ end
7930
7890
end
7931
7891
7932
7892
# MethodAddBlock represents a method call with a block argument.
7933
7893
#
7934
7894
# method {}
7935
7895
#
7936
7896
class MethodAddBlock
7937
- # [Call | Command | CommandCall | FCall | MethodAddArg ] the method call
7897
+ # [Call | Command | CommandCall | FCall] the method call
7938
7898
attr_reader :call
7939
7899
7940
7900
# [BraceBlock | DoBlock] the block being sent with the method call
@@ -7989,7 +7949,7 @@ def to_json(*opts)
7989
7949
7990
7950
# :call-seq:
7991
7951
# on_method_add_block: (
7992
- # (Call | Command | CommandCall | FCall | MethodAddArg ) call,
7952
+ # (Call | Command | CommandCall | FCall) call,
7993
7953
# (BraceBlock | DoBlock) block
7994
7954
# ) -> MethodAddBlock
7995
7955
def on_method_add_block ( call , block )
0 commit comments