-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An implementation for 0168-multi-line-string-literals.md #8813
Changes from 16 commits
d37fa1c
8ad6272
12cfc63
5c960fc
3f52458
201acde
9575546
9129aaa
e36bbd5
ecccee0
965378f
bccae22
3157849
5723d97
cee194e
4691cb2
ab9f827
c7d651d
49ec123
31609d0
7e512dd
d73ef5f
f5cf99c
fa47a67
7c7b9fd
cadd9b9
2c3eb13
2ecf9a9
1b6e411
f1ce3c5
03e2ecd
ef1dfdd
1e12e89
56536b9
14b1143
7194004
5d3b897
38be1f4
0dd605f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -375,12 +375,17 @@ class Lexer { | |
// Loc+Length for the segment inside the string literal, without quotes. | ||
SourceLoc Loc; | ||
unsigned Length; | ||
|
||
static StringSegment getLiteral(SourceLoc Loc, unsigned Length) { | ||
unsigned Modifiers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please replace with explicit boolean variables to indicate the first and last segments of a multiline string. |
||
std::string ToReplace; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: what is Modifiers for? If this is an option set of the enum below, please make this an OptionSet<> (or a type alias thereof). Similarly, plumbed throughout. |
||
static StringSegment getLiteral(SourceLoc Loc, unsigned Length, | ||
unsigned Modifiers, const std::string &ToReplace) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 80-character lines, please. |
||
StringSegment Result; | ||
Result.Kind = Literal; | ||
Result.Loc = Loc; | ||
Result.Length = Length; | ||
Result.Modifiers = Modifiers; | ||
Result.ToReplace = ToReplace; | ||
return Result; | ||
} | ||
|
||
|
@@ -397,12 +402,13 @@ class Lexer { | |
/// If a copy needs to be made, it will be allocated out of the provided | ||
/// Buffer. | ||
static StringRef getEncodedStringSegment(StringRef Str, | ||
SmallVectorImpl<char> &Buffer); | ||
SmallVectorImpl<char> &Buffer, | ||
unsigned Modifiers = 0, const std::string &ToReplace = ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: 80-character lines, here and throughout. |
||
StringRef getEncodedStringSegment(StringSegment Segment, | ||
SmallVectorImpl<char> &Buffer) const { | ||
return getEncodedStringSegment( | ||
StringRef(getBufferPtrForSourceLoc(Segment.Loc), Segment.Length), | ||
Buffer); | ||
Buffer, Segment.Modifiers, Segment.ToReplace); | ||
} | ||
|
||
/// \brief Given a string literal token, separate it into string/expr segments | ||
|
@@ -464,7 +470,7 @@ class Lexer { | |
return diagnose(Loc, Diagnostic(DiagID, std::forward<ArgTypes>(Args)...)); | ||
} | ||
|
||
void formToken(tok Kind, const char *TokStart); | ||
void formToken(tok Kind, const char *TokStart, unsigned Modifiers = 0); | ||
|
||
/// Advance to the end of the line but leave the current buffer pointer | ||
/// at that newline character. | ||
|
@@ -495,7 +501,7 @@ class Lexer { | |
static unsigned lexUnicodeEscape(const char *&CurPtr, Lexer *Diags); | ||
|
||
unsigned lexCharacter(const char *&CurPtr, | ||
char StopQuote, bool EmitDiagnostics); | ||
char StopQuote, bool EmitDiagnostics, unsigned Modifiers = 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 80-character lines, please. |
||
void lexStringLiteral(); | ||
void lexEscapedIdentifier(); | ||
|
||
|
@@ -505,6 +511,9 @@ class Lexer { | |
/// Try to lex conflict markers by checking for the presence of the start and | ||
/// end of the marker in diff3 or Perforce style respectively. | ||
bool tryLexConflictMarker(); | ||
|
||
// new for multiline string literals | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: capitalize and punctuate comments, here and throughout. |
||
void validateIndents(const Token &Str); | ||
}; | ||
|
||
} // end namespace swift | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,9 @@ class Token { | |
/// \brief Whether this token is an escaped `identifier` token. | ||
unsigned EscapedIdentifier : 1; | ||
|
||
/// modifiers for string literals | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: capitalize and punctuate. |
||
unsigned StringModifiers: 1; // currently only one - triple quotes for long strings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: follow style in this file and put a space before and after colon; also, capitalize and punctuate comment and consider where it's placed as it looks like it pushes the line past 80 characters. |
||
|
||
/// Text - The actual string covered by the token in the source buffer. | ||
StringRef Text; | ||
|
||
|
@@ -60,7 +63,7 @@ class Token { | |
EscapedIdentifier(false) {} | ||
Token(tok Kind, StringRef Text) | ||
: Kind(Kind), AtStartOfLine(false), CommentLength(0), | ||
EscapedIdentifier(false), | ||
EscapedIdentifier(false), StringModifiers(0), | ||
Text(Text) {} | ||
|
||
tok getKind() const { return Kind; } | ||
|
@@ -273,11 +276,17 @@ class Token { | |
void setText(StringRef T) { Text = T; } | ||
|
||
/// \brief Set the token to the specified kind and source range. | ||
void setToken(tok K, StringRef T, unsigned CommentLength = 0) { | ||
void setToken(tok K, StringRef T, unsigned CommentLength = 0, unsigned Modifiers = 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 80-character lines, please. |
||
Kind = K; | ||
Text = T; | ||
this->CommentLength = CommentLength; | ||
EscapedIdentifier = false; | ||
StringModifiers = Modifiers; | ||
assert(StringModifiers == Modifiers && "Modifier overflow"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do |
||
} | ||
|
||
unsigned getStringModifiers() const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to bool, rename to |
||
return StringModifiers; | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning on trailing whitespace is not a part of the approved proposal; please also split into separate PR.