@@ -82,7 +82,9 @@ struct Lexer {
8282
8383 let peek = peek
8484
85- if current. isLetter {
85+ // The x' is actually the start of a blob literal which
86+ // will be handled later in the switch
87+ if current. isLetter, !( current == " x " && peek == " ' " ) {
8688 return parseWord ( )
8789 }
8890
@@ -140,7 +142,14 @@ struct Lexer {
140142 case ( " | " , _) : return consumeSingle ( of: . pipe)
141143 case ( " ^ " , _) : return consumeSingle ( of: . carrot)
142144 case ( " ~ " , _) : return consumeSingle ( of: . tilde)
143- case ( " ' " , _) : return parseString ( )
145+ case ( " ' " , _) :
146+ let ( contents, location) = parseStringContents ( )
147+ return Token ( kind: . string( contents) , location: location)
148+ case ( " x " , " ' " ) :
149+ let start = startLocation ( )
150+ advance ( ) // past the x
151+ let ( contents, _) = parseStringContents ( )
152+ return Token ( kind: . blob( contents) , location: location ( from: start) )
144153 case ( " \" " , _) : return parseEscapedIdentifier ( closing: " \" " )
145154 case ( " [ " , _) : return parseEscapedIdentifier ( closing: " ] " )
146155 case ( " ` " , _) : return parseEscapedIdentifier ( closing: " ` " )
@@ -331,7 +340,9 @@ struct Lexer {
331340 return Token ( kind: . hex( value) , location: location)
332341 }
333342
334- private mutating func parseString( ) -> Token {
343+ /// Gets the raw string between two `'`. Assumes that the starting char
344+ /// is a quote and will consume both the starting and end.
345+ private mutating func parseStringContents( ) -> ( Substring , SourceLocation ) {
335346 let tokenStart = startLocation ( )
336347 advance ( )
337348 let stringStart = currentIndex
@@ -348,7 +359,7 @@ struct Lexer {
348359 diagnostics. add ( . init( " Unterminated string " , at: location ( from: tokenStart) ) )
349360 }
350361
351- return Token ( kind : . string ( source [ stringRange] ) , location : location ( from: tokenStart) )
362+ return ( source [ stringRange] , location ( from: tokenStart) )
352363 }
353364
354365 private mutating func skipWhitespace( ) {
0 commit comments