Skip to content

Commit 7476677

Browse files
committed
libSyntax: create separate node kinds for quote (") and multiline quote (""").
This allows us to serialize the quote tokens without serializing their underlying text.
1 parent 06dfe86 commit 7476677

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

include/swift/Syntax/Serialization/SyntaxSerialization.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ struct ObjectTraits<TokenDescription> {
155155
case tok::oper_prefix:
156156
case tok::dollarident:
157157
case tok::comment:
158-
case tok::string_quote:
159158
case tok::string_segment:
160159
out.mapRequired("text", value.Text);
161160
break;

include/swift/Syntax/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ MISC(comment)
288288
MISC(string_interpolation_anchor)
289289
MISC(contextual_keyword)
290290
MISC(string_quote)
291+
MISC(multiline_string_quote)
291292
MISC(string_segment)
292293

293294
#undef KEYWORD

lib/Parse/ParseExpr.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,11 +2000,15 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20002000

20012001
// We are now sure this is a string interpolation expression.
20022002
LocalContext.setCreateSyntax(SyntaxKind::StringInterpolationExpr);
2003-
StringRef Quote = Tok.IsMultilineString() ? "\"\"\"" : "\"";
2003+
StringRef Quote;
2004+
tok QuoteKind;
2005+
std::tie(Quote, QuoteKind) = Tok.IsMultilineString() ?
2006+
std::make_tuple("\"\"\"", tok::multiline_string_quote) :
2007+
std::make_tuple("\"", tok::string_quote);
20042008

20052009
// Make unknown tokens to represent the open and close quote.
2006-
Token OpenQuote(tok::string_quote, Quote);
2007-
Token CloseQuote(tok::string_quote, Quote);
2010+
Token OpenQuote(QuoteKind, Quote);
2011+
Token CloseQuote(QuoteKind, Quote);
20082012
Trivia EmptyTrivia;
20092013
Trivia EntireTrailingTrivia = TrailingTrivia;
20102014

lib/Syntax/RawTokenSyntax.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ void RawTokenSyntax::dumpKind(llvm::raw_ostream &OS) const {
7979
case tok::string_quote:
8080
OS << "string_quote";
8181
break;
82+
case tok::multiline_string_quote:
83+
OS << "multiline_string_quote";
84+
break;
8285
case tok::string_segment:
8386
OS << "string_segment";
8487
break;

utils/gyb_syntax_support/ExprNodes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,16 @@
430430
# e.g. "abc \(foo()) def"
431431
Node('StringInterpolationExpr', kind='Expr',
432432
children=[
433-
Child('OpenQuote', kind='StringQuoteToken'),
433+
Child('OpenQuote', kind='Token',
434+
token_choices=[
435+
'StringQuoteToken',
436+
'MultilineStringQuoteToken',
437+
]),
434438
Child('Segments', kind='StringInterpolationSegments'),
435-
Child('CloseQuote', kind='StringQuoteToken'),
439+
Child('CloseQuote', kind='Token',
440+
token_choices=[
441+
'StringQuoteToken',
442+
'MultilineStringQuoteToken',
443+
]),
436444
]),
437445
]

utils/gyb_syntax_support/Token.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ def __init__(self, name, text):
135135
Token('Backslash', 'backslash', text='\\\\'),
136136
Token('StringInterpolationAnchor', 'string_interpolation_anchor',
137137
text=')'),
138-
Token('StringQuote', 'string_quote'),
138+
Token('StringQuote', 'string_quote', text='\\\"'),
139+
Token('MultilineStringQuote', 'multiline_string_quote',
140+
text='\\\"\\\"\\\"'),
139141
Token('StringSegment', 'string_segment'),
140142
Token('Identifier', 'identifier'),
141143
Token('DollarIdentifier', 'dollarident'),

0 commit comments

Comments
 (0)