File tree Expand file tree Collapse file tree 5 files changed +25
-56
lines changed Expand file tree Collapse file tree 5 files changed +25
-56
lines changed Original file line number Diff line number Diff line change @@ -695,16 +695,6 @@ extension Lexer.Cursor {
695
695
mutating func advanceValidatingUTF8Character( ) -> Unicode . Scalar ? {
696
696
return Unicode . Scalar. lexing ( advance: { self . advance ( ) } , peek: { self . peek ( at: 0 ) } )
697
697
}
698
-
699
- /// Rever the lexer by `offset` bytes. This should only be used by `resetForSplit`.
700
- /// This must not back up by more bytes than the last token because that would
701
- /// require us to also update `previousTokenKind`, which we don't do in this
702
- /// function
703
- mutating func backUp( by offset: Int ) {
704
- assert ( !self . isAtStartOfFile)
705
- self . previous = self . input. baseAddress!. advanced ( by: - ( offset + 1 ) ) . pointee
706
- self . input = UnsafeBufferPointer ( start: self . input. baseAddress!. advanced ( by: - offset) , count: self . input. count + offset)
707
- }
708
698
}
709
699
710
700
// MARK: - Boundness of operators
Original file line number Diff line number Diff line change @@ -61,18 +61,14 @@ extension Lexer {
61
61
return self . nextToken
62
62
}
63
63
64
+ /// Reset the lexeme sequence to the state we were in when lexing `splitToken`
65
+ /// but after we consumed `consumedPrefix` bytes from `splitToken`.
64
66
/// - Warning: Do not add more usages of this function.
65
- mutating func resetForSplit( of bytes: Int ) -> Lexer . Lexeme {
66
- guard bytes > 0 else {
67
- return self . advance ( )
67
+ mutating func resetForSplit( splitToken: Lexeme , consumedPrefix: Int ) -> Lexer . Lexeme {
68
+ self . cursor = splitToken. cursor
69
+ for _ in 0 ..< consumedPrefix {
70
+ _ = self . cursor. advance ( )
68
71
}
69
-
70
- // FIXME: This is kind of ridiculous. We shouldn't have to look backwards
71
- // in the token stream. We should be fusing together runs of operator and
72
- // identifier characters in the parser, not splitting and backing up
73
- // again in the lexer.
74
- let backUpLength = self . nextToken. byteLength + bytes
75
- self . cursor. backUp ( by: backUpLength)
76
72
self . nextToken = self . cursor. nextToken ( sourceBufferStart: self . sourceBufferStart, stateAllocator: lexerStateAllocator)
77
73
return self . advance ( )
78
74
}
Original file line number Diff line number Diff line change @@ -122,12 +122,10 @@ extension Parser.Lookahead {
122
122
}
123
123
assert ( tokenText. hasPrefix ( prefix) )
124
124
125
- // See also: Parser.consumePrefix(_:as:)
126
- let offset =
127
- ( self . currentToken. trailingTriviaByteLength
128
- + tokenText. count
129
- - prefix. count)
130
- self . currentToken = self . lexemes. resetForSplit ( of: offset)
125
+ self . currentToken = self . lexemes. resetForSplit (
126
+ splitToken: self . currentToken,
127
+ consumedPrefix: self . currentToken. leadingTriviaByteLength + prefix. count
128
+ )
131
129
}
132
130
}
133
131
Original file line number Diff line number Diff line change @@ -555,36 +555,10 @@ extension Parser {
555
555
556
556
self . adjustNestingLevel ( for: tokenKind)
557
557
558
- // ... or a multi-character token with the first N characters being the one
559
- // that we want to consume as a separate token.
560
- // Careful: We need to reset the lexer to a point just before it saw the
561
- // current token, plus the split point. That means we need to take trailing
562
- // trivia into account for the current token, but we only need to take the
563
- // number of UTF-8 bytes of the text of the split - no trivia necessary.
564
- //
565
- // <TOKEN<trailing trivia>> <NEXT TOKEN> ... -> <T> <OKEN<trailing trivia>> <NEXT TOKEN>
566
- //
567
- // The current calculation is:
568
- //
569
- // <<leading trivia>TOKEN<trailing trivia>>
570
- // CURSOR ^
571
- // + trailing trivia length
572
- //
573
- // <<leading trivia>TOKEN<trailing trivia>>
574
- // CURSOR ^
575
- // + content length
576
- //
577
- // <<leading trivia>TOKEN<trailing trivia>>
578
- // CURSOR ^
579
- // - split point length
580
- //
581
- // <<leading trivia>TOKEN<trailing trivia>>
582
- // CURSOR ^
583
- let offset =
584
- ( self . currentToken. trailingTriviaByteLength
585
- + tokenText. count
586
- - prefix. count)
587
- self . currentToken = self . lexemes. resetForSplit ( of: offset)
558
+ self . currentToken = self . lexemes. resetForSplit (
559
+ splitToken: self . currentToken,
560
+ consumedPrefix: self . currentToken. leadingTriviaByteLength + prefix. count
561
+ )
588
562
return tok
589
563
}
590
564
}
Original file line number Diff line number Diff line change @@ -1666,4 +1666,15 @@ final class StatementExpressionTests: XCTestCase {
1666
1666
]
1667
1667
)
1668
1668
}
1669
+
1670
+ func testStringLiteralAfterKeyPath( ) {
1671
+ AssertParse (
1672
+ #"""
1673
+ \String.?1️⃣""
1674
+ """# ,
1675
+ diagnostics: [
1676
+ DiagnosticSpec ( message: " consecutive statements on a line must be separated by ';' " )
1677
+ ]
1678
+ )
1679
+ }
1669
1680
}
You can’t perform that action at this time.
0 commit comments