@@ -1191,11 +1191,7 @@ def to_json(*opts)
1191
1191
# :call-seq:
1192
1192
# on_assoc_new: (untyped key, untyped value) -> Assoc
1193
1193
def on_assoc_new ( key , value )
1194
- Assoc . new (
1195
- key : key ,
1196
- value : value ,
1197
- location : key . location . to ( value . location )
1198
- )
1194
+ Assoc . new ( key : key , value : value , location : key . location . to ( value . location ) )
1199
1195
end
1200
1196
1201
1197
# AssocSplat represents double-splatting a value into a hash (either a hash
@@ -1236,48 +1232,9 @@ def on_assoc_splat(value)
1236
1232
AssocSplat . new ( value : value , location : operator . location . to ( value . location ) )
1237
1233
end
1238
1234
1239
- # AssocListFromArgs represents the key-value pairs of a hash literal. Its
1240
- # parent node is always a hash.
1241
- #
1242
- # { key1: value1, key2: value2 }
1243
- #
1244
- class AssocListFromArgs
1245
- # [Array[ AssocNew | AssocSplat ]]
1246
- attr_reader :assocs
1247
-
1248
- # [Location] the location of this node
1249
- attr_reader :location
1250
-
1251
- def initialize ( assocs :, location :)
1252
- @assocs = assocs
1253
- @location = location
1254
- end
1255
-
1256
- def pretty_print ( q )
1257
- q . group ( 2 , '(' , ')' ) do
1258
- q . text ( 'assoclist_from_args' )
1259
- q . breakable
1260
- q . group ( 2 , '(' , ')' ) { q . seplist ( assocs ) { |assoc | q . pp ( assoc ) } }
1261
- end
1262
- end
1263
-
1264
- def to_json ( *opts )
1265
- { type : :assoclist_from_args , assocs : assocs , loc : location } . to_json (
1266
- *opts
1267
- )
1268
- end
1269
- end
1270
-
1271
- # :call-seq:
1272
- # on_assoclist_from_args: (
1273
- # Array[AssocNew | AssocSplat] assocs
1274
- # ) -> AssocListFromArgs
1275
- def on_assoclist_from_args ( assocs )
1276
- AssocListFromArgs . new (
1277
- assocs : assocs ,
1278
- location : assocs [ 0 ] . location . to ( assocs [ -1 ] . location )
1279
- )
1280
- end
1235
+ # def on_assoclist_from_args(assocs)
1236
+ # assocs
1237
+ # end
1281
1238
1282
1239
# Backref represents a global variable referencing a matched value. It comes
1283
1240
# in the form of a $ followed by a positive integer.
@@ -3977,53 +3934,41 @@ def on_gvar(value)
3977
3934
# { key => value }
3978
3935
#
3979
3936
class HashLiteral
3980
- # [nil | AssocListFromArgs] the contents of the hash
3981
- attr_reader :contents
3937
+ # [Array[ AssocNew | AssocSplat ]] the optional contents of the hash
3938
+ attr_reader :assocs
3982
3939
3983
3940
# [Location] the location of this node
3984
3941
attr_reader :location
3985
3942
3986
- def initialize ( contents :, location :)
3987
- @contents = contents
3943
+ def initialize ( assocs :, location :)
3944
+ @assocs = assocs
3988
3945
@location = location
3989
3946
end
3990
3947
3991
3948
def pretty_print ( q )
3992
3949
q . group ( 2 , '(' , ')' ) do
3993
3950
q . text ( 'hash' )
3994
3951
3995
- q . breakable
3996
- q . pp ( contents )
3952
+ if assocs . any?
3953
+ q . breakable
3954
+ q . group ( 2 , '(' , ')' ) { q . seplist ( assocs ) { |assoc | q . pp ( assoc ) } }
3955
+ end
3997
3956
end
3998
3957
end
3999
3958
4000
3959
def to_json ( *opts )
4001
- { type : :hash , cnts : contents , loc : location } . to_json ( *opts )
3960
+ { type : :hash , assocs : assocs , loc : location } . to_json ( *opts )
4002
3961
end
4003
3962
end
4004
3963
4005
3964
# :call-seq:
4006
- # on_hash: ((nil | AssocListFromArgs) contents ) -> HashLiteral
4007
- def on_hash ( contents )
3965
+ # on_hash: ((nil | Array[AssocNew | AssocSplat]) assocs ) -> HashLiteral
3966
+ def on_hash ( assocs )
4008
3967
lbrace = find_token ( LBrace )
4009
3968
rbrace = find_token ( RBrace )
4010
3969
4011
- if contents
4012
- # Here we're going to expand out the location information for the contents
4013
- # node so that it can grab up any remaining comments inside the hash.
4014
- location =
4015
- Location . new (
4016
- start_line : contents . location . start_line ,
4017
- start_char : lbrace . location . end_char ,
4018
- end_line : contents . location . end_line ,
4019
- end_char : rbrace . location . start_char
4020
- )
4021
-
4022
- contents = contents . class . new ( assocs : contents . assocs , location : location )
4023
- end
4024
-
4025
3970
HashLiteral . new (
4026
- contents : contents ,
3971
+ assocs : assocs || [ ] ,
4027
3972
location : lbrace . location . to ( rbrace . location )
4028
3973
)
4029
3974
end
@@ -5270,11 +5215,7 @@ def to_json(*opts)
5270
5215
# ) -> MLHS
5271
5216
def on_mlhs_add ( mlhs , part )
5272
5217
location =
5273
- if mlhs . parts . empty?
5274
- part . location
5275
- else
5276
- mlhs . location . to ( part . location )
5277
- end
5218
+ mlhs . parts . empty? ? part . location : mlhs . location . to ( part . location )
5278
5219
5279
5220
MLHS . new ( parts : mlhs . parts << part , location : location )
5280
5221
end
@@ -5460,112 +5401,42 @@ def on_mrhs_new
5460
5401
# :call-seq:
5461
5402
# on_mrhs_add: (MRHS mrhs, untyped part) -> MRHS
5462
5403
def on_mrhs_add ( mrhs , part )
5463
- if mrhs . is_a? ( MRHSNewFromArgs )
5464
- MRHS . new (
5465
- parts : [ *mrhs . arguments . parts , part ] ,
5466
- location : mrhs . location . to ( part . location )
5467
- )
5468
- elsif mrhs . parts . empty?
5469
- MRHS . new ( parts : [ part ] , location : mrhs . location )
5470
- else
5471
- MRHS . new ( parts : mrhs . parts << part , loc : mrhs . location . to ( part . location ) )
5472
- end
5473
- end
5474
-
5475
- # MRHSAddStar represents using the splat operator to expand out a value on the
5476
- # right hand side of a multiple assignment.
5477
- #
5478
- # values = first, *rest
5479
- #
5480
- class MRHSAddStar
5481
- # [MRHS | MRHSNewFromArgs] the values before the splatted expression
5482
- attr_reader :mrhs
5483
-
5484
- # [untyped] the splatted expression
5485
- attr_reader :star
5486
-
5487
- # [Location] the location of this node
5488
- attr_reader :location
5489
-
5490
- def initialize ( mrhs :, star :, location :)
5491
- @mrhs = mrhs
5492
- @star = star
5493
- @location = location
5494
- end
5495
-
5496
- def pretty_print ( q )
5497
- q . group ( 2 , '(' , ')' ) do
5498
- q . text ( 'mrhs_add_star' )
5499
-
5500
- q . breakable
5501
- q . pp ( mrhs )
5502
-
5503
- q . breakable
5504
- q . pp ( star )
5404
+ location =
5405
+ if mrhs . parts . empty?
5406
+ mrhs . location
5407
+ else
5408
+ mrhs . location . to ( part . location )
5505
5409
end
5506
- end
5507
5410
5508
- def to_json ( *opts )
5509
- { type : :mrhs_add_star , mrhs : mrhs , star : star , loc : location } . to_json (
5510
- *opts
5511
- )
5512
- end
5411
+ MRHS . new ( parts : mrhs . parts << part , location : location )
5513
5412
end
5514
5413
5515
5414
# :call-seq:
5516
- # on_mrhs_add_star: (
5517
- # (MRHS | MRHSNewFromArgs) mrhs,
5518
- # untyped star
5519
- # ) -> MRHSAddStar
5520
- def on_mrhs_add_star ( mrhs , star )
5415
+ # on_mrhs_add_star: (MRHS mrhs, untyped value) -> MRHS
5416
+ def on_mrhs_add_star ( mrhs , value )
5521
5417
beginning = find_token ( Op , '*' )
5522
- ending = star || beginning
5418
+ ending = value || beginning
5523
5419
5524
- MRHSAddStar . new (
5525
- mrhs : mrhs ,
5526
- star : star ,
5527
- location : beginning . location . to ( ending . location )
5528
- )
5529
- end
5530
-
5531
- # MRHSNewFromArgs represents the shorthand of a multiple assignment that
5532
- # allows you to assign values using just commas as opposed to assigning from
5533
- # an array.
5534
- #
5535
- # values = first, second, third
5536
- #
5537
- class MRHSNewFromArgs
5538
- # [Args] the arguments being used in the assignment
5539
- attr_reader :arguments
5540
-
5541
- # [Location] the location of this node
5542
- attr_reader :location
5543
-
5544
- def initialize ( arguments :, location :)
5545
- @arguments = arguments
5546
- @location = location
5547
- end
5548
-
5549
- def pretty_print ( q )
5550
- q . group ( 2 , '(' , ')' ) do
5551
- q . text ( 'mrhs_new_from_args' )
5420
+ arg_star =
5421
+ ArgStar . new (
5422
+ value : value ,
5423
+ location : beginning . location . to ( ending . location )
5424
+ )
5552
5425
5553
- q . breakable
5554
- q . pp ( arguments )
5426
+ location =
5427
+ if mrhs . parts . empty?
5428
+ arg_star . location
5429
+ else
5430
+ mrhs . location . to ( arg_star . location )
5555
5431
end
5556
- end
5557
5432
5558
- def to_json ( *opts )
5559
- { type : :mrhs_new_from_args , args : arguments , loc : location } . to_json (
5560
- *opts
5561
- )
5562
- end
5433
+ MRHS . new ( parts : mrhs . parts << arg_star , location : location )
5563
5434
end
5564
5435
5565
5436
# :call-seq:
5566
- # on_mrhs_new_from_args: (Args arguments) -> MRHSNewFromArgs
5437
+ # on_mrhs_new_from_args: (Args arguments) -> MRHS
5567
5438
def on_mrhs_new_from_args ( arguments )
5568
- MRHSNewFromArgs . new ( arguments : arguments , location : arguments . location )
5439
+ MRHS . new ( parts : arguments . parts , location : arguments . location )
5569
5440
end
5570
5441
5571
5442
# Next represents using the +next+ keyword.
0 commit comments