@@ -549,7 +549,7 @@ class ARef
549
549
# [untyped] the value being indexed
550
550
attr_reader :collection
551
551
552
- # [nil | Args | ArgsAddBlock ] the value being passed within the brackets
552
+ # [nil | Args] the value being passed within the brackets
553
553
attr_reader :index
554
554
555
555
# [Location] the location of this node
@@ -582,7 +582,7 @@ def to_json(*opts)
582
582
end
583
583
584
584
# :call-seq:
585
- # on_aref: (untyped collection, (nil | Args | ArgsAddBlock ) index) -> ARef
585
+ # on_aref: (untyped collection, (nil | Args) index) -> ARef
586
586
def on_aref ( collection , index )
587
587
find_token ( LBracket )
588
588
rbracket = find_token ( RBracket )
@@ -605,7 +605,7 @@ class ARefField
605
605
# [untyped] the value being indexed
606
606
attr_reader :collection
607
607
608
- # [nil | ArgsAddBlock ] the value being passed within the brackets
608
+ # [nil | Args ] the value being passed within the brackets
609
609
attr_reader :index
610
610
611
611
# [Location] the location of this node
@@ -640,7 +640,7 @@ def to_json(*opts)
640
640
# :call-seq:
641
641
# on_aref_field: (
642
642
# untyped collection,
643
- # (nil | ArgsAddBlock ) index
643
+ # (nil | Args ) index
644
644
# ) -> ARefField
645
645
def on_aref_field ( collection , index )
646
646
find_token ( LBracket )
@@ -662,15 +662,14 @@ def on_aref_field(collection, index)
662
662
#
663
663
# method(argument)
664
664
#
665
- # In the example above, there would be an ArgParen node around the
666
- # ArgsAddBlock node that represents the set of arguments being sent to the
667
- # method method. The argument child node can be +nil+ if no arguments were
668
- # passed, as in:
665
+ # In the example above, there would be an ArgParen node around the Args node
666
+ # that represents the set of arguments being sent to the method method. The
667
+ # argument child node can be +nil+ if no arguments were passed, as in:
669
668
#
670
669
# method()
671
670
#
672
671
class ArgParen
673
- # [nil | Args | ArgsAddBlock | ArgsForward] the arguments inside the
672
+ # [nil | Args | ArgsForward] the arguments inside the
674
673
# parentheses
675
674
attr_reader :arguments
676
675
@@ -697,7 +696,7 @@ def to_json(*opts)
697
696
698
697
# :call-seq:
699
698
# on_arg_paren: (
700
- # (nil | Args | ArgsAddBlock | ArgsForward) arguments
699
+ # (nil | Args | ArgsForward) arguments
701
700
# ) -> ArgParen
702
701
def on_arg_paren ( arguments )
703
702
lparen = find_token ( LParen )
@@ -767,61 +766,53 @@ def on_args_add(arguments, argument)
767
766
end
768
767
end
769
768
770
- # ArgsAddBlock represents a list of arguments and potentially a block
771
- # argument. ArgsAddBlock is commonly seen being passed to any method where you
772
- # use parentheses (wrapped in an ArgParen node). It’s also used to pass
773
- # arguments to the various control-flow keywords like +return+.
769
+ # ArgBlock represents using a block operator on an expression.
774
770
#
775
- # method(argument, &block )
771
+ # method(&expression )
776
772
#
777
- class ArgsAddBlock
778
- # [Args] the arguments before the optional block
779
- attr_reader :arguments
780
-
781
- # [nil | untyped] the optional block argument
782
- attr_reader :block
773
+ class ArgBlock
774
+ # [untyped] the expression being turned into a block
775
+ attr_reader :value
783
776
784
777
# [Location] the location of this node
785
778
attr_reader :location
786
779
787
- def initialize ( arguments :, block :, location :)
788
- @arguments = arguments
789
- @block = block
780
+ def initialize ( value :, location :)
781
+ @value = value
790
782
@location = location
791
783
end
792
784
793
785
def pretty_print ( q )
794
786
q . group ( 2 , '(' , ')' ) do
795
- q . text ( 'args_add_block' )
796
- q . breakable
797
- q . pp ( arguments )
787
+ q . text ( 'arg_block' )
788
+
798
789
q . breakable
799
- q . pp ( block )
790
+ q . pp ( value )
800
791
end
801
792
end
802
793
803
794
def to_json ( *opts )
804
- {
805
- type : :args_add_block ,
806
- args : arguments ,
807
- block : block ,
808
- loc : location
809
- } . to_json ( *opts )
795
+ { type : :arg_block , value : value , loc : location } . to_json ( *opts )
810
796
end
811
797
end
812
798
813
799
# :call-seq:
814
800
# on_args_add_block: (
815
801
# Args arguments,
816
802
# (false | untyped) block
817
- # ) -> ArgsAddBlock
803
+ # ) -> Args
818
804
def on_args_add_block ( arguments , block )
819
- ending = block || arguments
805
+ return arguments unless block
820
806
821
- ArgsAddBlock . new (
822
- arguments : arguments ,
823
- block : block || nil ,
824
- location : arguments . location . to ( ending . location )
807
+ arg_block =
808
+ ArgBlock . new (
809
+ value : block ,
810
+ location : find_token ( Op , '&' ) . location . to ( block . location )
811
+ )
812
+
813
+ Args . new (
814
+ parts : arguments . parts << arg_block ,
815
+ location : arguments . location . to ( arg_block . location )
825
816
)
826
817
end
827
818
@@ -1785,7 +1776,7 @@ def on_brace_block(block_var, statements)
1785
1776
# break 1
1786
1777
#
1787
1778
class Break
1788
- # [Args | ArgsAddBlock ] the arguments being sent to the keyword
1779
+ # [Args] the arguments being sent to the keyword
1789
1780
attr_reader :arguments
1790
1781
1791
1782
# [Location] the location of this node
@@ -1810,12 +1801,12 @@ def to_json(*opts)
1810
1801
end
1811
1802
1812
1803
# :call-seq:
1813
- # on_break: (( Args | ArgsAddBlock) arguments) -> Break
1804
+ # on_break: (Args arguments) -> Break
1814
1805
def on_break ( arguments )
1815
1806
keyword = find_token ( Kw , 'break' )
1816
1807
1817
1808
location = keyword . location
1818
- location = location . to ( arguments . location ) unless arguments . is_a? ( Args )
1809
+ location = location . to ( arguments . location ) if arguments . parts . any?
1819
1810
1820
1811
Break . new ( arguments : arguments , location : location )
1821
1812
end
@@ -2157,7 +2148,7 @@ class Command
2157
2148
# [Const | Ident] the message being sent to the implicit receiver
2158
2149
attr_reader :message
2159
2150
2160
- # [Args | ArgsAddBlock ] the arguments being sent with the message
2151
+ # [Args] the arguments being sent with the message
2161
2152
attr_reader :arguments
2162
2153
2163
2154
# [Location] the location of this node
@@ -2192,10 +2183,7 @@ def to_json(*opts)
2192
2183
end
2193
2184
2194
2185
# :call-seq:
2195
- # on_command: (
2196
- # (Const | Ident) message,
2197
- # (Args | ArgsAddBlock) arguments
2198
- # ) -> Command
2186
+ # on_command: ((Const | Ident) message, Args arguments) -> Command
2199
2187
def on_command ( message , arguments )
2200
2188
Command . new (
2201
2189
message : message ,
@@ -2219,7 +2207,7 @@ class CommandCall
2219
2207
# [Const | Ident | Op] the message being send
2220
2208
attr_reader :message
2221
2209
2222
- # [Args | ArgsAddBlock ] the arguments going along with the message
2210
+ # [Args] the arguments going along with the message
2223
2211
attr_reader :arguments
2224
2212
2225
2213
# [Location] the location of this node
@@ -2268,7 +2256,7 @@ def to_json(*opts)
2268
2256
# untyped receiver,
2269
2257
# (:"::" | Op | Period) operator,
2270
2258
# (Const | Ident | Op) message,
2271
- # ( Args | ArgsAddBlock) arguments
2259
+ # Args arguments
2272
2260
# ) -> CommandCall
2273
2261
def on_command_call ( receiver , operator , message , arguments )
2274
2262
ending = arguments || message
@@ -5068,7 +5056,7 @@ class MethodAddArg
5068
5056
# [Call | FCall] the method call
5069
5057
attr_reader :call
5070
5058
5071
- # [ArgParen | Args | ArgsAddBlock ] the arguments to the method call
5059
+ # [ArgParen | Args] the arguments to the method call
5072
5060
attr_reader :arguments
5073
5061
5074
5062
# [Location] the location of this node
@@ -5105,11 +5093,10 @@ def to_json(*opts)
5105
5093
# :call-seq:
5106
5094
# on_method_add_arg: (
5107
5095
# (Call | FCall) call,
5108
- # (ArgParen | Args | ArgsAddBlock ) arguments
5096
+ # (ArgParen | Args) arguments
5109
5097
# ) -> MethodAddArg
5110
5098
def on_method_add_arg ( call , arguments )
5111
5099
location = call . location
5112
-
5113
5100
location = location . to ( arguments . location ) unless arguments . is_a? ( Args )
5114
5101
5115
5102
MethodAddArg . new ( call : call , arguments : arguments , location : location )
@@ -5457,7 +5444,7 @@ def on_mrhs_new_from_args(arguments)
5457
5444
# next(value)
5458
5445
#
5459
5446
class Next
5460
- # [Args | ArgsAddBlock ] the arguments passed to the next keyword
5447
+ # [Args] the arguments passed to the next keyword
5461
5448
attr_reader :arguments
5462
5449
5463
5450
# [Location] the location of this node
@@ -5483,12 +5470,12 @@ def to_json(*opts)
5483
5470
end
5484
5471
5485
5472
# :call-seq:
5486
- # on_next: (( Args | ArgsAddBlock) arguments) -> Next
5473
+ # on_next: (Args arguments) -> Next
5487
5474
def on_next ( arguments )
5488
5475
keyword = find_token ( Kw , 'next' )
5489
5476
5490
5477
location = keyword . location
5491
- location = location . to ( arguments . location ) unless arguments . is_a? ( Args )
5478
+ location = location . to ( arguments . location ) if arguments . parts . any?
5492
5479
5493
5480
Next . new ( arguments : arguments , location : location )
5494
5481
end
@@ -6751,7 +6738,7 @@ def on_retry
6751
6738
# return value
6752
6739
#
6753
6740
class Return
6754
- # [Args | ArgsAddBlock ] the arguments being passed to the keyword
6741
+ # [Args] the arguments being passed to the keyword
6755
6742
attr_reader :arguments
6756
6743
6757
6744
# [Location] the location of this node
@@ -6777,7 +6764,7 @@ def to_json(*opts)
6777
6764
end
6778
6765
6779
6766
# :call-seq:
6780
- # on_return: (( Args | ArgsAddBlock) arguments) -> Return
6767
+ # on_return: (Args arguments) -> Return
6781
6768
def on_return ( arguments )
6782
6769
keyword = find_token ( Kw , 'return' )
6783
6770
@@ -7294,7 +7281,7 @@ def on_string_literal(string)
7294
7281
# super(value)
7295
7282
#
7296
7283
class Super
7297
- # [ArgParen | Args | ArgsAddBlock ] the arguments to the keyword
7284
+ # [ArgParen | Args] the arguments to the keyword
7298
7285
attr_reader :arguments
7299
7286
7300
7287
# [Location] the location of this node
@@ -7320,7 +7307,7 @@ def to_json(*opts)
7320
7307
end
7321
7308
7322
7309
# :call-seq:
7323
- # on_super: ((ArgParen | Args | ArgsAddBlock ) arguments) -> Super
7310
+ # on_super: ((ArgParen | Args) arguments) -> Super
7324
7311
def on_super ( arguments )
7325
7312
keyword = find_token ( Kw , 'super' )
7326
7313
@@ -8899,7 +8886,7 @@ def on_xstring_literal(xstring)
8899
8886
# yield value
8900
8887
#
8901
8888
class Yield
8902
- # [ArgsAddBlock | Paren] the arguments passed to the yield
8889
+ # [Args | Paren] the arguments passed to the yield
8903
8890
attr_reader :arguments
8904
8891
8905
8892
# [Location] the location of this node
@@ -8925,7 +8912,7 @@ def to_json(*opts)
8925
8912
end
8926
8913
8927
8914
# :call-seq:
8928
- # on_yield: ((ArgsAddBlock | Paren) arguments) -> Yield
8915
+ # on_yield: ((Args | Paren) arguments) -> Yield
8929
8916
def on_yield ( arguments )
8930
8917
keyword = find_token ( Kw , 'yield' )
8931
8918
0 commit comments