Implement SE-0200 (extended escaping in string literals)

Supports string literals like #"foo"\n"bar"#.
This commit is contained in:
John Holdsworth
2018-09-06 23:19:52 +01:00
committed by Brent Royal-Gordon
parent 5e2b705f6d
commit 4da8cbe655
9 changed files with 357 additions and 79 deletions

View File

@@ -45,7 +45,10 @@ class Token {
/// Modifiers for string literals
unsigned MultilineString : 1;
// Padding bits == 32 - sizeof(Kind) * 8 - 3;
/// Length of custom delimiter of "raw" string literals
unsigned CustomDelimiterLen : 8;
// Padding bits == 32 - 11;
/// \brief The length of the comment that precedes the token.
unsigned CommentLength;
@@ -62,8 +65,8 @@ class Token {
public:
Token(tok Kind, StringRef Text, unsigned CommentLength = 0)
: Kind(Kind), AtStartOfLine(false), EscapedIdentifier(false),
MultilineString(false), CommentLength(CommentLength),
Text(Text) {}
MultilineString(false), CustomDelimiterLen(0),
CommentLength(CommentLength), Text(Text) {}
Token() : Token(tok::NUM_TOKENS, {}, 0) {}
@@ -266,17 +269,24 @@ public:
/// \brief Set the token to the specified kind and source range.
void setToken(tok K, StringRef T, unsigned CommentLength = 0,
bool MultilineString = false) {
bool IsMultilineString = false, unsigned CustomDelimiterLen = 0) {
Kind = K;
Text = T;
this->CommentLength = CommentLength;
EscapedIdentifier = false;
this->MultilineString = MultilineString;
this->MultilineString = IsMultilineString;
this->CustomDelimiterLen = CustomDelimiterLen;
assert(this->CustomDelimiterLen == CustomDelimiterLen &&
"custom string delimiter length > 255");
}
bool IsMultilineString() const {
bool isMultilineString() const {
return MultilineString;
}
unsigned getCustomDelimiterLen() const {
return CustomDelimiterLen;
}
};
} // end namespace swift