19
19
20
20
#include " swift/Basic/SourceLoc.h"
21
21
#include " swift/Basic/SourceManager.h"
22
- #include " swift/Syntax/Token.h"
23
- #include " swift/Syntax/Syntax.h"
22
+ #include " swift/Parse/Token.h"
24
23
#include " swift/AST/DiagnosticEngine.h"
25
24
#include " llvm/ADT/SmallVector.h"
26
25
27
- #include < deque>
28
-
29
26
namespace swift {
30
27
class DiagnosticEngine ;
31
28
class InFlightDiagnostic ;
@@ -91,7 +88,7 @@ class Lexer {
91
88
92
89
// / @}
93
90
94
- syntax:: Token NextToken;
91
+ Token NextToken;
95
92
96
93
// / \brief This is true if we're lexing a .sil file instead of a .swift
97
94
// / file. This enables the 'sil' keyword.
@@ -102,13 +99,6 @@ class Lexer {
102
99
// / InSILBody - This is true when we're lexing the body of a SIL declaration
103
100
// / in a SIL file. This enables some context-sensitive lexing.
104
101
bool InSILBody = false ;
105
-
106
- // / The source trivia leading up to the current token.
107
- std::deque<syntax::Trivia> LeadingTrivia;
108
-
109
- // / The source trivia after the current token, up to and including the first
110
- // / newline after the token.
111
- std::deque<syntax::Trivia> TrailingTrivia;
112
102
113
103
public:
114
104
// / \brief Lexer state can be saved/restored to/from objects of this class.
@@ -202,11 +192,10 @@ class Lexer {
202
192
return CodeCompletionPtr != nullptr ;
203
193
}
204
194
205
- syntax::Token lex () {
206
- auto Result = NextToken;
195
+ void lex (Token &Result ) {
196
+ Result = NextToken;
207
197
if (Result.isNot (tok::eof))
208
198
lexImpl ();
209
- return Result;
210
199
}
211
200
212
201
bool isKeepingComments () const {
@@ -217,7 +206,7 @@ class Lexer {
217
206
218
207
// / peekNextToken - Return the next token to be returned by Lex without
219
208
// / actually lexing it.
220
- const syntax:: Token &peekNextToken () const { return NextToken; }
209
+ const Token &peekNextToken () const { return NextToken; }
221
210
222
211
// / \brief Returns the lexer state for the beginning of the given token
223
212
// / location. After restoring the state, lexer will return this token and
@@ -227,11 +216,11 @@ class Lexer {
227
216
// / \brief Returns the lexer state for the beginning of the given token.
228
217
// / After restoring the state, lexer will return this token and continue from
229
218
// / there.
230
- State getStateForBeginningOfToken (syntax:: Token Tok) const {
219
+ State getStateForBeginningOfToken (const Token & Tok) const {
231
220
// If the token has a comment attached to it, rewind to before the comment,
232
221
// not just the start of the token. This ensures that we will re-lex and
233
222
// reattach the comment to the token if rewound to this state.
234
- auto TokStart = Tok.getAbsoluteTriviaStart ();
223
+ SourceLoc TokStart = Tok.getCommentStart ();
235
224
if (TokStart.isInvalid ())
236
225
TokStart = Tok.getLoc ();
237
226
return getStateForBeginningOfTokenLoc (TokStart);
@@ -267,8 +256,8 @@ class Lexer {
267
256
// / resides.
268
257
// /
269
258
// / \param Loc The source location of the beginning of a token.
270
- static Optional<syntax:: Token>
271
- getTokenAtLocation ( const SourceManager &SM, SourceLoc Loc);
259
+ static Token getTokenAtLocation ( const SourceManager &SM, SourceLoc Loc);
260
+
272
261
273
262
// / \brief Retrieve the source location that points just past the
274
263
// / end of the token referred to by \c Loc.
@@ -379,11 +368,11 @@ class Lexer {
379
368
// / \brief Given a string literal token, separate it into string/expr segments
380
369
// / of a potentially interpolated string.
381
370
static void getStringLiteralSegments (
382
- const syntax:: Token &Str,
371
+ const Token &Str,
383
372
SmallVectorImpl<StringSegment> &Segments,
384
373
DiagnosticEngine *Diags);
385
374
386
- void getStringLiteralSegments (const syntax:: Token &Str,
375
+ void getStringLiteralSegments (const Token &Str,
387
376
SmallVectorImpl<StringSegment> &Segments) {
388
377
return getStringLiteralSegments (Str, Segments, Diags);
389
378
}
@@ -393,7 +382,7 @@ class Lexer {
393
382
}
394
383
395
384
// / Get the token that starts at the given location.
396
- syntax:: Token getTokenAt (SourceLoc Loc);
385
+ Token getTokenAt (SourceLoc Loc);
397
386
398
387
// / SILBodyRAII - This helper class is used when parsing a SIL body to inform
399
388
// / the lexer that SIL-specific lexing should be enabled.
@@ -437,7 +426,6 @@ class Lexer {
437
426
438
427
void formToken (tok Kind, const char *TokStart);
439
428
440
- void skipUpToEndOfLine ();
441
429
void skipToEndOfLine ();
442
430
443
431
// / Skip to the end of the line of a // comment.
@@ -453,12 +441,6 @@ class Lexer {
453
441
void lexOperatorIdentifier ();
454
442
void lexHexNumber ();
455
443
void lexNumber ();
456
- void lexTrivia (std::deque<syntax::Trivia> &T, bool StopAtFirstNewline = false );
457
- Optional<syntax::Trivia> lexWhitespace (bool StopAtFirstNewline);
458
- Optional<syntax::Trivia> lexComment ();
459
- Optional<syntax::Trivia> lexSingleLineComment (syntax::TriviaKind Kind);
460
- Optional<syntax::Trivia> lexBlockComment (syntax::TriviaKind Kind);
461
- Optional<syntax::Trivia> lexDocComment ();
462
444
static unsigned lexUnicodeEscape (const char *&CurPtr, Lexer *Diags);
463
445
464
446
unsigned lexCharacter (const char *&CurPtr,
0 commit comments