Skip to content

Commit f472888

Browse files
authored
Merge pull request #19356 from rintaro/lexer-stringliteral
[Lexer] Tweaks for string literal lexing
2 parents 815310a + 50497ff commit f472888

File tree

10 files changed

+242
-183
lines changed

10 files changed

+242
-183
lines changed

include/swift/Parse/Lexer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,10 @@ class Lexer {
506506
return diagnose(Loc, Diagnostic(DiagID, std::forward<ArgTypes>(Args)...));
507507
}
508508

509-
void formToken(tok Kind, const char *TokStart, bool IsMultilineString = false,
510-
unsigned CustomDelimiterLen = 0);
509+
void formToken(tok Kind, const char *TokStart);
511510
void formEscapedIdentifierToken(const char *TokStart);
511+
void formStringLiteralToken(const char *TokStart, bool IsMultilineString,
512+
unsigned CustomDelimiterLen);
512513

513514
/// Advance to the end of the line.
514515
/// If EatNewLine is true, CurPtr will be at end of newline character.

include/swift/Parse/Token.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ class Token {
220220
default: return false;
221221
}
222222
}
223+
224+
/// \brief True if the string literal token is multiline.
225+
bool isMultilineString() const {
226+
return MultilineString;
227+
}
228+
/// \brief Count of extending escaping '#'.
229+
unsigned getCustomDelimiterLen() const {
230+
return CustomDelimiterLen;
231+
}
232+
/// \brief Set characteristics of string literal token.
233+
void setStringLiteral(bool IsMultilineString, unsigned CustomDelimiterLen) {
234+
assert(Kind == tok::string_literal);
235+
this->MultilineString = IsMultilineString;
236+
this->CustomDelimiterLen = CustomDelimiterLen;
237+
}
223238

224239
/// getLoc - Return a source location identifier for the specified
225240
/// offset in the current file.
@@ -268,25 +283,16 @@ class Token {
268283
void setText(StringRef T) { Text = T; }
269284

270285
/// \brief Set the token to the specified kind and source range.
271-
void setToken(tok K, StringRef T, unsigned CommentLength = 0,
272-
bool IsMultilineString = false, unsigned CustomDelimiterLen = 0) {
286+
void setToken(tok K, StringRef T, unsigned CommentLength = 0) {
273287
Kind = K;
274288
Text = T;
275289
this->CommentLength = CommentLength;
276290
EscapedIdentifier = false;
277-
this->MultilineString = IsMultilineString;
278-
this->CustomDelimiterLen = CustomDelimiterLen;
291+
this->MultilineString = false;
292+
this->CustomDelimiterLen = 0;
279293
assert(this->CustomDelimiterLen == CustomDelimiterLen &&
280294
"custom string delimiter length > 255");
281295
}
282-
283-
bool isMultilineString() const {
284-
return MultilineString;
285-
}
286-
287-
unsigned getCustomDelimiterLen() const {
288-
return CustomDelimiterLen;
289-
}
290296
};
291297

292298
} // end namespace swift

0 commit comments

Comments
 (0)