@@ -1506,6 +1506,7 @@ def on_array(contents)
1506
1506
tstring_end = find_token ( TStringEnd )
1507
1507
1508
1508
contents . class . new (
1509
+ beginning : contents . beginning ,
1509
1510
elements : contents . elements ,
1510
1511
location : contents . location . to ( tstring_end . location )
1511
1512
)
@@ -9257,6 +9258,9 @@ def nearest_nodes(node, comment)
9257
9258
# %i[one two three]
9258
9259
#
9259
9260
class QSymbols
9261
+ # [QSymbolsBeg] the token that opens this array literal
9262
+ attr_reader :beginning
9263
+
9260
9264
# [Array[ TStringContent ]] the elements of the array
9261
9265
attr_reader :elements
9262
9266
@@ -9266,7 +9270,8 @@ class QSymbols
9266
9270
# [Array[ Comment | EmbDoc ]] the comments attached to this node
9267
9271
attr_reader :comments
9268
9272
9269
- def initialize ( elements :, location :, comments : [ ] )
9273
+ def initialize ( beginning :, elements :, location :, comments : [ ] )
9274
+ @beginning = beginning
9270
9275
@elements = elements
9271
9276
@location = location
9272
9277
@comments = comments
@@ -9277,7 +9282,14 @@ def child_nodes
9277
9282
end
9278
9283
9279
9284
def format ( q )
9280
- q . group ( 0 , "%i[" , "]" ) do
9285
+ opening , closing = "%i[" , "]"
9286
+
9287
+ if elements . any? { |element | element . match? ( /[\[ \] ]/ ) }
9288
+ opening = beginning . value
9289
+ closing = Quotes . matching ( opening [ 2 ] )
9290
+ end
9291
+
9292
+ q . group ( 0 , opening , closing ) do
9281
9293
q . indent do
9282
9294
q . breakable ( "" )
9283
9295
q . seplist ( elements , -> { q . breakable } ) do |element |
@@ -9313,6 +9325,7 @@ def to_json(*opts)
9313
9325
# on_qsymbols_add: (QSymbols qsymbols, TStringContent element) -> QSymbols
9314
9326
def on_qsymbols_add ( qsymbols , element )
9315
9327
QSymbols . new (
9328
+ beginning : qsymbols . beginning ,
9316
9329
elements : qsymbols . elements << element ,
9317
9330
location : qsymbols . location . to ( element . location )
9318
9331
)
@@ -9354,16 +9367,19 @@ def on_qsymbols_beg(value)
9354
9367
# :call-seq:
9355
9368
# on_qsymbols_new: () -> QSymbols
9356
9369
def on_qsymbols_new
9357
- qsymbols_beg = find_token ( QSymbolsBeg )
9370
+ beginning = find_token ( QSymbolsBeg )
9358
9371
9359
- QSymbols . new ( elements : [ ] , location : qsymbols_beg . location )
9372
+ QSymbols . new ( beginning : beginning , elements : [ ] , location : beginning . location )
9360
9373
end
9361
9374
9362
9375
# QWords represents a string literal array without interpolation.
9363
9376
#
9364
9377
# %w[one two three]
9365
9378
#
9366
9379
class QWords
9380
+ # [QWordsBeg] the token that opens this array literal
9381
+ attr_reader :beginning
9382
+
9367
9383
# [Array[ TStringContent ]] the elements of the array
9368
9384
attr_reader :elements
9369
9385
@@ -9373,7 +9389,8 @@ class QWords
9373
9389
# [Array[ Comment | EmbDoc ]] the comments attached to this node
9374
9390
attr_reader :comments
9375
9391
9376
- def initialize ( elements :, location :, comments : [ ] )
9392
+ def initialize ( beginning :, elements :, location :, comments : [ ] )
9393
+ @beginning = beginning
9377
9394
@elements = elements
9378
9395
@location = location
9379
9396
@comments = comments
@@ -9384,7 +9401,14 @@ def child_nodes
9384
9401
end
9385
9402
9386
9403
def format ( q )
9387
- q . group ( 0 , "%w[" , "]" ) do
9404
+ opening , closing = "%w[" , "]"
9405
+
9406
+ if elements . any? { |element | element . match? ( /[\[ \] ]/ ) }
9407
+ opening = beginning . value
9408
+ closing = Quotes . matching ( opening [ 2 ] )
9409
+ end
9410
+
9411
+ q . group ( 0 , opening , closing ) do
9388
9412
q . indent do
9389
9413
q . breakable ( "" )
9390
9414
q . seplist ( elements , -> { q . breakable } ) do |element |
@@ -9417,6 +9441,7 @@ def to_json(*opts)
9417
9441
# on_qwords_add: (QWords qwords, TStringContent element) -> QWords
9418
9442
def on_qwords_add ( qwords , element )
9419
9443
QWords . new (
9444
+ beginning : qwords . beginning ,
9420
9445
elements : qwords . elements << element ,
9421
9446
location : qwords . location . to ( element . location )
9422
9447
)
@@ -9458,9 +9483,9 @@ def on_qwords_beg(value)
9458
9483
# :call-seq:
9459
9484
# on_qwords_new: () -> QWords
9460
9485
def on_qwords_new
9461
- qwords_beg = find_token ( QWordsBeg )
9486
+ beginning = find_token ( QWordsBeg )
9462
9487
9463
- QWords . new ( elements : [ ] , location : qwords_beg . location )
9488
+ QWords . new ( beginning : beginning , elements : [ ] , location : beginning . location )
9464
9489
end
9465
9490
9466
9491
# RationalLiteral represents the use of a rational number literal.
@@ -11331,6 +11356,9 @@ def on_symbol_literal(value)
11331
11356
# %I[one two three]
11332
11357
#
11333
11358
class Symbols
11359
+ # [SymbolsBeg] the token that opens this array literal
11360
+ attr_reader :beginning
11361
+
11334
11362
# [Array[ Word ]] the words in the symbol array literal
11335
11363
attr_reader :elements
11336
11364
@@ -11340,7 +11368,8 @@ class Symbols
11340
11368
# [Array[ Comment | EmbDoc ]] the comments attached to this node
11341
11369
attr_reader :comments
11342
11370
11343
- def initialize ( elements :, location :, comments : [ ] )
11371
+ def initialize ( beginning :, elements :, location :, comments : [ ] )
11372
+ @beginning = beginning
11344
11373
@elements = elements
11345
11374
@location = location
11346
11375
@comments = comments
@@ -11351,7 +11380,14 @@ def child_nodes
11351
11380
end
11352
11381
11353
11382
def format ( q )
11354
- q . group ( 0 , "%I[" , "]" ) do
11383
+ opening , closing = "%I[" , "]"
11384
+
11385
+ if elements . any? { |element | element . match? ( /[\[ \] ]/ ) }
11386
+ opening = beginning . value
11387
+ closing = Quotes . matching ( opening [ 2 ] )
11388
+ end
11389
+
11390
+ q . group ( 0 , opening , closing ) do
11355
11391
q . indent do
11356
11392
q . breakable ( "" )
11357
11393
q . seplist ( elements , -> { q . breakable } ) do |element |
@@ -11387,6 +11423,7 @@ def to_json(*opts)
11387
11423
# on_symbols_add: (Symbols symbols, Word word) -> Symbols
11388
11424
def on_symbols_add ( symbols , word )
11389
11425
Symbols . new (
11426
+ beginning : symbols . beginning ,
11390
11427
elements : symbols . elements << word ,
11391
11428
location : symbols . location . to ( word . location )
11392
11429
)
@@ -11429,9 +11466,9 @@ def on_symbols_beg(value)
11429
11466
# :call-seq:
11430
11467
# on_symbols_new: () -> Symbols
11431
11468
def on_symbols_new
11432
- symbols_beg = find_token ( SymbolsBeg )
11469
+ beginning = find_token ( SymbolsBeg )
11433
11470
11434
- Symbols . new ( elements : [ ] , location : symbols_beg . location )
11471
+ Symbols . new ( beginning : beginning , elements : [ ] , location : beginning . location )
11435
11472
end
11436
11473
11437
11474
# TLambda represents the beginning of a lambda literal.
@@ -11682,6 +11719,10 @@ def initialize(value:, location:, comments: [])
11682
11719
@comments = comments
11683
11720
end
11684
11721
11722
+ def match? ( pattern )
11723
+ value . match? ( pattern )
11724
+ end
11725
+
11685
11726
def child_nodes
11686
11727
[ ]
11687
11728
end
@@ -13008,6 +13049,10 @@ def initialize(parts:, location:, comments: [])
13008
13049
@comments = comments
13009
13050
end
13010
13051
13052
+ def match? ( pattern )
13053
+ parts . any? { |part | part . is_a? ( TStringContent ) && part . match? ( pattern ) }
13054
+ end
13055
+
13011
13056
def child_nodes
13012
13057
parts
13013
13058
end
@@ -13057,6 +13102,9 @@ def on_word_new
13057
13102
# %W[one two three]
13058
13103
#
13059
13104
class Words
13105
+ # [WordsBeg] the token that opens this array literal
13106
+ attr_reader :beginning
13107
+
13060
13108
# [Array[ Word ]] the elements of this array
13061
13109
attr_reader :elements
13062
13110
@@ -13066,7 +13114,8 @@ class Words
13066
13114
# [Array[ Comment | EmbDoc ]] the comments attached to this node
13067
13115
attr_reader :comments
13068
13116
13069
- def initialize ( elements :, location :, comments : [ ] )
13117
+ def initialize ( beginning :, elements :, location :, comments : [ ] )
13118
+ @beginning = beginning
13070
13119
@elements = elements
13071
13120
@location = location
13072
13121
@comments = comments
@@ -13077,7 +13126,14 @@ def child_nodes
13077
13126
end
13078
13127
13079
13128
def format ( q )
13080
- q . group ( 0 , "%W[" , "]" ) do
13129
+ opening , closing = "%W[" , "]"
13130
+
13131
+ if elements . any? { |element | element . match? ( /[\[ \] ]/ ) }
13132
+ opening = beginning . value
13133
+ closing = Quotes . matching ( opening [ 2 ] )
13134
+ end
13135
+
13136
+ q . group ( 0 , opening , closing ) do
13081
13137
q . indent do
13082
13138
q . breakable ( "" )
13083
13139
q . seplist ( elements , -> { q . breakable } ) do |element |
@@ -13110,6 +13166,7 @@ def to_json(*opts)
13110
13166
# on_words_add: (Words words, Word word) -> Words
13111
13167
def on_words_add ( words , word )
13112
13168
Words . new (
13169
+ beginning : words . beginning ,
13113
13170
elements : words . elements << word ,
13114
13171
location : words . location . to ( word . location )
13115
13172
)
@@ -13152,9 +13209,9 @@ def on_words_beg(value)
13152
13209
# :call-seq:
13153
13210
# on_words_new: () -> Words
13154
13211
def on_words_new
13155
- words_beg = find_token ( WordsBeg )
13212
+ beginning = find_token ( WordsBeg )
13156
13213
13157
- Words . new ( elements : [ ] , location : words_beg . location )
13214
+ Words . new ( beginning : beginning , elements : [ ] , location : beginning . location )
13158
13215
end
13159
13216
13160
13217
# def on_words_sep(value)
0 commit comments