@@ -47,6 +47,8 @@ public enum TriviaPiece {
47
47
case docBlockComment( String )
48
48
/// Any skipped garbage text.
49
49
case garbageText( String )
50
+ /// A script command, starting with '#!'.
51
+ case shebang( String )
50
52
}
51
53
52
54
extension TriviaPiece : TextOutputStreamable {
@@ -83,6 +85,8 @@ extension TriviaPiece: TextOutputStreamable {
83
85
target. write ( text)
84
86
case let . garbageText( text) :
85
87
target. write ( text)
88
+ case let . shebang( text) :
89
+ target. write ( text)
86
90
}
87
91
}
88
92
}
@@ -115,6 +119,8 @@ extension TriviaPiece: CustomDebugStringConvertible {
115
119
return " docBlockComment( \( name) ) "
116
120
case . garbageText( let name) :
117
121
return " garbageText( \( name) ) "
122
+ case . shebang( let name) :
123
+ return " shebang( \( name) ) "
118
124
}
119
125
}
120
126
}
@@ -249,6 +255,11 @@ public struct Trivia {
249
255
public static func garbageText( _ text: String ) -> Trivia {
250
256
return [ . garbageText( text) ]
251
257
}
258
+
259
+ /// Returns a piece of trivia for Shebang.
260
+ public static func shebang( _ text: String ) -> Trivia {
261
+ return [ . shebang( text) ]
262
+ }
252
263
}
253
264
254
265
extension Trivia : Equatable { }
@@ -314,6 +325,8 @@ extension TriviaPiece {
314
325
return SourceLength ( of: text)
315
326
case let . garbageText( text) :
316
327
return SourceLength ( of: text)
328
+ case let . shebang( text) :
329
+ return SourceLength ( of: text)
317
330
}
318
331
}
319
332
}
@@ -346,6 +359,8 @@ extension TriviaPiece {
346
359
return . docBlockComment( . fromBuffer( textBuffer) )
347
360
case 12 :
348
361
return . garbageText( . fromBuffer( textBuffer) )
362
+ case 125 :
363
+ return . shebang( . fromBuffer( textBuffer) )
349
364
default :
350
365
fatalError ( " unexpected trivia piece kind \( piece. kind) " )
351
366
}
@@ -377,6 +392,8 @@ extension TriviaPiece {
377
392
return true
378
393
case 12 :
379
394
return true
395
+ case 125 :
396
+ return true
380
397
default :
381
398
fatalError ( " unexpected trivia piece kind \( kind) " )
382
399
}
@@ -409,6 +426,8 @@ internal enum TriviaPieceKind: CTriviaKind {
409
426
case docBlockComment = 11
410
427
/// Any skipped garbage text.
411
428
case garbageText = 12
429
+ /// A script command, starting with '#!'.
430
+ case shebang = 125
412
431
413
432
static func fromRawValue( _ rawValue: CTriviaKind ) -> TriviaPieceKind {
414
433
return TriviaPieceKind ( rawValue: rawValue) !
@@ -471,6 +490,12 @@ extension TriviaPiece {
471
490
return text. utf8. withContiguousStorageIfAvailable ( { ( buf: UnsafeBufferPointer < UInt8 > ) in
472
491
return body ( . init( kind: . garbageText, length: length, customText: buf) )
473
492
} ) !
493
+ case var . shebang( text) :
494
+ text. makeContiguousUTF8 ( )
495
+ let length = text. utf8. count
496
+ return text. utf8. withContiguousStorageIfAvailable ( { ( buf: UnsafeBufferPointer < UInt8 > ) in
497
+ return body ( . init( kind: . shebang, length: length, customText: buf) )
498
+ } ) !
474
499
}
475
500
}
476
501
}
0 commit comments