From 3f78eec44ab2f06f05c699cbd90714716e13ebd7 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Sep 2023 11:14:38 -0400 Subject: [PATCH] [ruby/yarp] Constants on keyword rest parameters https://github.com/ruby/yarp/commit/5e1a8fbc54 --- test/yarp/errors_test.rb | 10 +++++----- test/yarp/snapshots/methods.txt | 4 ++-- test/yarp/snapshots/non_alphanumeric_methods.txt | 2 +- test/yarp/snapshots/procs.txt | 4 ++-- test/yarp/snapshots/seattlerb/block_arg_kwsplat.txt | 2 +- test/yarp/snapshots/seattlerb/block_args_kwargs.txt | 2 +- test/yarp/snapshots/seattlerb/defn_kwarg_env.txt | 2 +- test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat.txt | 2 +- .../snapshots/seattlerb/defn_kwarg_kwsplat_anon.txt | 2 +- test/yarp/snapshots/seattlerb/defn_powarg.txt | 2 +- test/yarp/snapshots/seattlerb/iter_kwarg_kwsplat.txt | 2 +- .../snapshots/unparser/corpus/literal/since/32.txt | 2 +- test/yarp/snapshots/whitequark/args.txt | 6 +++--- test/yarp/snapshots/whitequark/blockargs.txt | 8 ++++++-- .../whitequark/forwarded_argument_with_kwrestarg.txt | 2 +- test/yarp/snapshots/whitequark/forwarded_kwrestarg.txt | 2 +- .../forwarded_kwrestarg_with_additional_kwarg.txt | 2 +- .../kwoptarg_with_kwrestarg_and_forwarded_args.txt | 2 +- test/yarp/snapshots/whitequark/kwrestarg_named.txt | 2 +- test/yarp/snapshots/whitequark/kwrestarg_unnamed.txt | 2 +- yarp/config.yml | 6 ++++-- yarp/yarp.c | 5 +++-- 22 files changed, 40 insertions(+), 33 deletions(-) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index d4f46440b5..f4f3eab12f 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -742,7 +742,7 @@ module YARP [], nil, [KeywordParameterNode(:b, Location(), nil)], - KeywordRestParameterNode(Location(), Location()), + KeywordRestParameterNode(:rest, Location(), Location()), nil ), nil, @@ -789,7 +789,7 @@ module YARP [RequiredParameterNode(:a)], nil, [KeywordParameterNode(:b, Location(), nil)], - KeywordRestParameterNode(Location(), Location()), + KeywordRestParameterNode(:args, Location(), Location()), nil ), nil, @@ -818,7 +818,7 @@ module YARP [RequiredParameterNode(:a)], nil, [KeywordParameterNode(:b, Location(), nil)], - KeywordRestParameterNode(Location(), Location()), + KeywordRestParameterNode(:args, Location(), Location()), nil ), nil, @@ -847,7 +847,7 @@ module YARP [RequiredParameterNode(:a)], nil, [KeywordParameterNode(:b, Location(), nil)], - KeywordRestParameterNode(Location(), Location()), + KeywordRestParameterNode(:args, Location(), Location()), nil ), nil, @@ -1065,7 +1065,7 @@ module YARP expected = DefNode( Location(), nil, - ParametersNode([RequiredParameterNode(:a), RequiredParameterNode(:b)], [], [], nil, [], KeywordRestParameterNode(Location(), Location()), nil), + ParametersNode([RequiredParameterNode(:a), RequiredParameterNode(:b)], [], [], nil, [], KeywordRestParameterNode(:a, Location(), Location()), nil), nil, [:a, :b], Location(), diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt index 390522bae4..ae808aba0d 100644 --- a/test/yarp/snapshots/methods.txt +++ b/test/yarp/snapshots/methods.txt @@ -262,7 +262,7 @@ ProgramNode(0...1194)( [], nil, [], - KeywordRestParameterNode(250...253)((250...252), (252...253)), + KeywordRestParameterNode(250...253)(:b, (252...253), (250...252)), nil ), nil, @@ -283,7 +283,7 @@ ProgramNode(0...1194)( [], nil, [], - KeywordRestParameterNode(266...268)((266...268), nil), + KeywordRestParameterNode(266...268)(nil, nil, (266...268)), nil ), nil, diff --git a/test/yarp/snapshots/non_alphanumeric_methods.txt b/test/yarp/snapshots/non_alphanumeric_methods.txt index a8e9cd798f..cf87adc48c 100644 --- a/test/yarp/snapshots/non_alphanumeric_methods.txt +++ b/test/yarp/snapshots/non_alphanumeric_methods.txt @@ -115,7 +115,7 @@ ProgramNode(0...434)( [], nil, [], - KeywordRestParameterNode(110...113)((110...112), (112...113)), + KeywordRestParameterNode(110...113)(:b, (112...113), (110...112)), nil ), nil, diff --git a/test/yarp/snapshots/procs.txt b/test/yarp/snapshots/procs.txt index e825afd8e4..3f6f1d7470 100644 --- a/test/yarp/snapshots/procs.txt +++ b/test/yarp/snapshots/procs.txt @@ -119,7 +119,7 @@ ProgramNode(0...266)( RestParameterNode(145...147)((145...146), (146...147)), [KeywordParameterNode(149...151)(:d, (149...151), nil), KeywordParameterNode(153...155)(:e, (153...155), nil)], - KeywordRestParameterNode(157...160)((157...159), (159...160)), + KeywordRestParameterNode(157...160)(:f, (159...160), (157...159)), BlockParameterNode(162...164)(:g, (163...164), (162...163)) ), [], @@ -146,7 +146,7 @@ ProgramNode(0...266)( RestParameterNode(187...189)((187...188), (188...189)), [KeywordParameterNode(191...193)(:d, (191...193), nil), KeywordParameterNode(195...197)(:e, (195...197), nil)], - KeywordRestParameterNode(199...202)((199...201), (201...202)), + KeywordRestParameterNode(199...202)(:f, (201...202), (199...201)), BlockParameterNode(204...206)(:g, (205...206), (204...205)) ), [], diff --git a/test/yarp/snapshots/seattlerb/block_arg_kwsplat.txt b/test/yarp/snapshots/seattlerb/block_arg_kwsplat.txt index 36b7c9f83c..196b4d250f 100644 --- a/test/yarp/snapshots/seattlerb/block_arg_kwsplat.txt +++ b/test/yarp/snapshots/seattlerb/block_arg_kwsplat.txt @@ -17,7 +17,7 @@ ProgramNode(0...11)( [], nil, [], - KeywordRestParameterNode(5...8)((5...7), (7...8)), + KeywordRestParameterNode(5...8)(:b, (7...8), (5...7)), nil ), [], diff --git a/test/yarp/snapshots/seattlerb/block_args_kwargs.txt b/test/yarp/snapshots/seattlerb/block_args_kwargs.txt index f54b1bc55f..8db4d3f0ea 100644 --- a/test/yarp/snapshots/seattlerb/block_args_kwargs.txt +++ b/test/yarp/snapshots/seattlerb/block_args_kwargs.txt @@ -17,7 +17,7 @@ ProgramNode(0...23)( [], nil, [], - KeywordRestParameterNode(5...13)((5...7), (7...13)), + KeywordRestParameterNode(5...13)(:kwargs, (7...13), (5...7)), nil ), [], diff --git a/test/yarp/snapshots/seattlerb/defn_kwarg_env.txt b/test/yarp/snapshots/seattlerb/defn_kwarg_env.txt index 5872579ee6..4364d66188 100644 --- a/test/yarp/snapshots/seattlerb/defn_kwarg_env.txt +++ b/test/yarp/snapshots/seattlerb/defn_kwarg_env.txt @@ -10,7 +10,7 @@ ProgramNode(0...45)( [], nil, [], - KeywordRestParameterNode(9...18)((9...11), (11...18)), + KeywordRestParameterNode(9...18)(:testing, (11...18), (9...11)), nil ), StatementsNode(20...41)( diff --git a/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat.txt b/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat.txt index bc4cb7d8a9..040bca4c5d 100644 --- a/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat.txt +++ b/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat.txt @@ -10,7 +10,7 @@ ProgramNode(0...20)( [], nil, [KeywordParameterNode(6...10)(:b, (6...8), IntegerNode(9...10)())], - KeywordRestParameterNode(12...15)((12...14), (14...15)), + KeywordRestParameterNode(12...15)(:c, (14...15), (12...14)), nil ), nil, diff --git a/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat_anon.txt b/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat_anon.txt index 009b3f0fca..080b3ed2ab 100644 --- a/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat_anon.txt +++ b/test/yarp/snapshots/seattlerb/defn_kwarg_kwsplat_anon.txt @@ -10,7 +10,7 @@ ProgramNode(0...19)( [], nil, [KeywordParameterNode(6...10)(:b, (6...8), IntegerNode(9...10)())], - KeywordRestParameterNode(12...14)((12...14), nil), + KeywordRestParameterNode(12...14)(nil, nil, (12...14)), nil ), nil, diff --git a/test/yarp/snapshots/seattlerb/defn_powarg.txt b/test/yarp/snapshots/seattlerb/defn_powarg.txt index a6d63f56cb..6965fca97e 100644 --- a/test/yarp/snapshots/seattlerb/defn_powarg.txt +++ b/test/yarp/snapshots/seattlerb/defn_powarg.txt @@ -10,7 +10,7 @@ ProgramNode(0...17)( [], nil, [], - KeywordRestParameterNode(6...12)((6...8), (8...12)), + KeywordRestParameterNode(6...12)(:opts, (8...12), (6...8)), nil ), nil, diff --git a/test/yarp/snapshots/seattlerb/iter_kwarg_kwsplat.txt b/test/yarp/snapshots/seattlerb/iter_kwarg_kwsplat.txt index b068be0913..5ade32c483 100644 --- a/test/yarp/snapshots/seattlerb/iter_kwarg_kwsplat.txt +++ b/test/yarp/snapshots/seattlerb/iter_kwarg_kwsplat.txt @@ -17,7 +17,7 @@ ProgramNode(0...17)( [], nil, [KeywordParameterNode(5...9)(:b, (5...7), IntegerNode(8...9)())], - KeywordRestParameterNode(11...14)((11...13), (13...14)), + KeywordRestParameterNode(11...14)(:c, (13...14), (11...13)), nil ), [], diff --git a/test/yarp/snapshots/unparser/corpus/literal/since/32.txt b/test/yarp/snapshots/unparser/corpus/literal/since/32.txt index 31397bf468..fd07f07237 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/since/32.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/since/32.txt @@ -10,7 +10,7 @@ ProgramNode(0...90)( [], nil, [], - KeywordRestParameterNode(18...20)((18...20), nil), + KeywordRestParameterNode(18...20)(nil, nil, (18...20)), nil ), StatementsNode(24...41)( diff --git a/test/yarp/snapshots/whitequark/args.txt b/test/yarp/snapshots/whitequark/args.txt index 8d5ce21dcb..12d18fdaff 100644 --- a/test/yarp/snapshots/whitequark/args.txt +++ b/test/yarp/snapshots/whitequark/args.txt @@ -340,7 +340,7 @@ ProgramNode(0...690)( (269...273), IntegerNode(274...275)() )], - KeywordRestParameterNode(277...282)((277...279), (279...282)), + KeywordRestParameterNode(277...282)(:baz, (279...282), (277...279)), BlockParameterNode(284...286)(:b, (285...286), (284...285)) ), nil, @@ -361,7 +361,7 @@ ProgramNode(0...690)( [], nil, [], - KeywordRestParameterNode(300...305)((300...302), (302...305)), + KeywordRestParameterNode(300...305)(:baz, (302...305), (300...302)), BlockParameterNode(307...309)(:b, (308...309), (307...308)) ), nil, @@ -382,7 +382,7 @@ ProgramNode(0...690)( [], RestParameterNode(322...323)((322...323), nil), [], - KeywordRestParameterNode(325...327)((325...327), nil), + KeywordRestParameterNode(325...327)(nil, nil, (325...327)), nil ), nil, diff --git a/test/yarp/snapshots/whitequark/blockargs.txt b/test/yarp/snapshots/whitequark/blockargs.txt index 56bf4f49ca..4c51e4e1a8 100644 --- a/test/yarp/snapshots/whitequark/blockargs.txt +++ b/test/yarp/snapshots/whitequark/blockargs.txt @@ -75,7 +75,7 @@ ProgramNode(0...550)( [], nil, [], - KeywordRestParameterNode(32...37)((32...34), (34...37)), + KeywordRestParameterNode(32...37)(:baz, (34...37), (32...34)), BlockParameterNode(39...41)(:b, (40...41), (39...40)) ), [], @@ -850,7 +850,11 @@ ProgramNode(0...550)( (430...434), IntegerNode(435...436)() )], - KeywordRestParameterNode(438...443)((438...440), (440...443)), + KeywordRestParameterNode(438...443)( + :baz, + (440...443), + (438...440) + ), BlockParameterNode(445...447)(:b, (446...447), (445...446)) ), [], diff --git a/test/yarp/snapshots/whitequark/forwarded_argument_with_kwrestarg.txt b/test/yarp/snapshots/whitequark/forwarded_argument_with_kwrestarg.txt index a751f923c1..da165e8e71 100644 --- a/test/yarp/snapshots/whitequark/forwarded_argument_with_kwrestarg.txt +++ b/test/yarp/snapshots/whitequark/forwarded_argument_with_kwrestarg.txt @@ -10,7 +10,7 @@ ProgramNode(0...45)( [], nil, [], - KeywordRestParameterNode(18...20)((18...20), nil), + KeywordRestParameterNode(18...20)(nil, nil, (18...20)), nil ), StatementsNode(23...40)( diff --git a/test/yarp/snapshots/whitequark/forwarded_kwrestarg.txt b/test/yarp/snapshots/whitequark/forwarded_kwrestarg.txt index 0fcac6a298..51d8720fe6 100644 --- a/test/yarp/snapshots/whitequark/forwarded_kwrestarg.txt +++ b/test/yarp/snapshots/whitequark/forwarded_kwrestarg.txt @@ -10,7 +10,7 @@ ProgramNode(0...25)( [], nil, [], - KeywordRestParameterNode(8...10)((8...10), nil), + KeywordRestParameterNode(8...10)(nil, nil, (8...10)), nil ), StatementsNode(13...20)( diff --git a/test/yarp/snapshots/whitequark/forwarded_kwrestarg_with_additional_kwarg.txt b/test/yarp/snapshots/whitequark/forwarded_kwrestarg_with_additional_kwarg.txt index 65f75e723a..e0d078128b 100644 --- a/test/yarp/snapshots/whitequark/forwarded_kwrestarg_with_additional_kwarg.txt +++ b/test/yarp/snapshots/whitequark/forwarded_kwrestarg_with_additional_kwarg.txt @@ -10,7 +10,7 @@ ProgramNode(0...41)( [], nil, [], - KeywordRestParameterNode(8...10)((8...10), nil), + KeywordRestParameterNode(8...10)(nil, nil, (8...10)), nil ), StatementsNode(13...36)( diff --git a/test/yarp/snapshots/whitequark/kwoptarg_with_kwrestarg_and_forwarded_args.txt b/test/yarp/snapshots/whitequark/kwoptarg_with_kwrestarg_and_forwarded_args.txt index c9e8989ef3..bd1c1e6e54 100644 --- a/test/yarp/snapshots/whitequark/kwoptarg_with_kwrestarg_and_forwarded_args.txt +++ b/test/yarp/snapshots/whitequark/kwoptarg_with_kwrestarg_and_forwarded_args.txt @@ -10,7 +10,7 @@ ProgramNode(0...28)( [], nil, [KeywordParameterNode(6...12)(:a, (6...8), NilNode(9...12)())], - KeywordRestParameterNode(14...16)((14...16), nil), + KeywordRestParameterNode(14...16)(nil, nil, (14...16)), nil ), StatementsNode(19...24)( diff --git a/test/yarp/snapshots/whitequark/kwrestarg_named.txt b/test/yarp/snapshots/whitequark/kwrestarg_named.txt index 591c59dfba..2dd4c0225e 100644 --- a/test/yarp/snapshots/whitequark/kwrestarg_named.txt +++ b/test/yarp/snapshots/whitequark/kwrestarg_named.txt @@ -10,7 +10,7 @@ ProgramNode(0...17)( [], nil, [], - KeywordRestParameterNode(6...11)((6...8), (8...11)), + KeywordRestParameterNode(6...11)(:foo, (8...11), (6...8)), nil ), nil, diff --git a/test/yarp/snapshots/whitequark/kwrestarg_unnamed.txt b/test/yarp/snapshots/whitequark/kwrestarg_unnamed.txt index 57bf8cc8b4..3fa1dcd7fe 100644 --- a/test/yarp/snapshots/whitequark/kwrestarg_unnamed.txt +++ b/test/yarp/snapshots/whitequark/kwrestarg_unnamed.txt @@ -10,7 +10,7 @@ ProgramNode(0...14)( [], nil, [], - KeywordRestParameterNode(6...8)((6...8), nil), + KeywordRestParameterNode(6...8)(nil, nil, (6...8)), nil ), nil, diff --git a/yarp/config.yml b/yarp/config.yml index 91d6d81cb5..b24490a333 100644 --- a/yarp/config.yml +++ b/yarp/config.yml @@ -1574,10 +1574,12 @@ nodes: end - name: KeywordRestParameterNode fields: - - name: operator_loc - type: location + - name: name + type: constant? - name: name_loc type: location? + - name: operator_loc + type: location comment: | Represents a keyword rest parameter to a method, block, or lambda definition. diff --git a/yarp/yarp.c b/yarp/yarp.c index 6596b87620..7f9f3b5589 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -3088,8 +3088,9 @@ yp_keyword_rest_parameter_node_create(yp_parser_t *parser, const yp_token_t *ope .end = (name->type == YP_TOKEN_NOT_PROVIDED ? operator->end : name->end) }, }, - .operator_loc = YP_LOCATION_TOKEN_VALUE(operator), - .name_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(name) + .name = yp_parser_optional_constant_id_token(parser, name), + .name_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(name), + .operator_loc = YP_LOCATION_TOKEN_VALUE(operator) }; return node;