Skip to content

Commit b583fef

Browse files
committed
Consolidate StringInterpolationExpr to StringLiteralExpr
1 parent 5debb92 commit b583fef

File tree

5 files changed

+6
-23
lines changed

5 files changed

+6
-23
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,16 +2003,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20032003
SourceLoc Loc = Tok.getLoc();
20042004
SourceLoc EndLoc = Loc.getAdvancedLoc(Tok.getLength());
20052005

2006-
// The simple case: just a single literal segment.
2007-
if (Segments.size() == 1 &&
2008-
Segments.front().Kind == Lexer::StringSegment::Literal) {
2009-
consumeToken();
2010-
return makeParserResult(
2011-
createStringLiteralExprFromSegment(Context, L, Segments.front(), Loc));
2012-
}
2013-
2014-
// We are now sure this is a string interpolation expression.
2015-
LocalContext.setCreateSyntax(SyntaxKind::StringInterpolationExpr);
20162006
StringRef OpenQuoteStr, CloseQuoteStr;
20172007
tok QuoteKind;
20182008
std::tie(OpenQuoteStr, CloseQuoteStr, QuoteKind) = Tok.isMultilineString() ?

lib/Syntax/Status.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
* ForcedValueExpr
3232
* SuperRefExpr
3333
* ImplicitMemberExpr
34-
* InterpolatedStringLiteralExpr
3534
* KeyPathExpr
3635
* KeyPathDotExpr
3736
* InOutExpr

test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class C <MemberDeclBlock>{<MemberDeclListItem><FunctionDecl>
2626
func bar3<FunctionSignature><ParameterClause>(<FunctionParameter>a: <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionParameter>) </ParameterClause><ReturnClause>-> <SimpleTypeIdentifier>Int </SimpleTypeIdentifier></ReturnClause></FunctionSignature><CodeBlock>{ <ReturnStmt>return <IntegerLiteralExpr>1 </IntegerLiteralExpr></ReturnStmt>}</CodeBlock></FunctionDecl></MemberDeclListItem><MemberDeclListItem><FunctionDecl>
2727
func bar4<FunctionSignature><ParameterClause>(<FunctionParameter>_ a: <SimpleTypeIdentifier>Int</SimpleTypeIdentifier></FunctionParameter>) </ParameterClause><ReturnClause>-> <SimpleTypeIdentifier>Int </SimpleTypeIdentifier></ReturnClause></FunctionSignature><CodeBlock>{ <ReturnStmt>return <IntegerLiteralExpr>1 </IntegerLiteralExpr></ReturnStmt>}</CodeBlock></FunctionDecl></MemberDeclListItem><MemberDeclListItem><FunctionDecl>
2828
func foo<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<VariableDecl>
29-
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringInterpolationExpr>/*comment*/"<StringSegment>ab</StringSegment><ExpressionSegment>\(<FunctionCallArgument><IdentifierExpr>x</IdentifierExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>c</StringSegment>"</StringInterpolationExpr></InitializerClause></PatternBinding></VariableDecl><VariableDecl>/*comment*/
29+
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringLiteralExpr>/*comment*/"<StringSegment>ab</StringSegment><ExpressionSegment>\(<FunctionCallArgument><IdentifierExpr>x</IdentifierExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>c</StringSegment>"</StringLiteralExpr></InitializerClause></PatternBinding></VariableDecl><VariableDecl>/*comment*/
3030
var <PatternBinding><IdentifierPattern>b </IdentifierPattern><InitializerClause>= <PrefixOperatorExpr>/*comment*/+<IntegerLiteralExpr>2</IntegerLiteralExpr></PrefixOperatorExpr></InitializerClause></PatternBinding></VariableDecl><FunctionCallExpr><IdentifierExpr>/*comment*/
3131
bar</IdentifierExpr>(<FunctionCallArgument><IntegerLiteralExpr>1</IntegerLiteralExpr></FunctionCallArgument>)</FunctionCallExpr><FunctionCallExpr><IdentifierExpr>
3232
bar</IdentifierExpr>(<FunctionCallArgument><PrefixOperatorExpr>+<IntegerLiteralExpr>10</IntegerLiteralExpr></PrefixOperatorExpr></FunctionCallArgument>)</FunctionCallExpr><FunctionCallExpr><IdentifierExpr>
@@ -434,13 +434,13 @@ extension <SimpleTypeIdentifier>ext </SimpleTypeIdentifier><GenericWhereClause>w
434434
extension <MemberTypeIdentifier><MemberTypeIdentifier><SimpleTypeIdentifier>ext</SimpleTypeIdentifier>.a</MemberTypeIdentifier>.b </MemberTypeIdentifier><MemberDeclBlock>{}</MemberDeclBlock></ExtensionDecl><FunctionDecl>
435435

436436
func foo<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<VariableDecl>
437-
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringInterpolationExpr>"<StringSegment>abc </StringSegment><ExpressionSegment>\(<FunctionCallArgument><FunctionCallExpr><IdentifierExpr>foo</IdentifierExpr>()</FunctionCallExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> def </StringSegment><ExpressionSegment>\(<FunctionCallArgument><SequenceExpr><IdentifierExpr>a </IdentifierExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><IdentifierExpr>b </IdentifierExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><StringInterpolationExpr>"<StringSegment>a </StringSegment><ExpressionSegment>\(<FunctionCallArgument><IntegerLiteralExpr>3</IntegerLiteralExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment></StringSegment>"</StringInterpolationExpr></SequenceExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> gh </StringSegment><ExpressionSegment>\(<FunctionCallArgument><IdentifierExpr>bar</IdentifierExpr>, </FunctionCallArgument><FunctionCallArgument>default: <IntegerLiteralExpr>1</IntegerLiteralExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment></StringSegment>"</StringInterpolationExpr></InitializerClause></PatternBinding></VariableDecl><VariableDecl>
438-
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringInterpolationExpr>"""<StringSegment>
437+
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringLiteralExpr>"<StringSegment>abc </StringSegment><ExpressionSegment>\(<FunctionCallArgument><FunctionCallExpr><IdentifierExpr>foo</IdentifierExpr>()</FunctionCallExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> def </StringSegment><ExpressionSegment>\(<FunctionCallArgument><SequenceExpr><IdentifierExpr>a </IdentifierExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><IdentifierExpr>b </IdentifierExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><StringLiteralExpr>"<StringSegment>a </StringSegment><ExpressionSegment>\(<FunctionCallArgument><IntegerLiteralExpr>3</IntegerLiteralExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment></StringSegment>"</StringLiteralExpr></SequenceExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> gh </StringSegment><ExpressionSegment>\(<FunctionCallArgument><IdentifierExpr>bar</IdentifierExpr>, </FunctionCallArgument><FunctionCallArgument>default: <IntegerLiteralExpr>1</IntegerLiteralExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment></StringSegment>"</StringLiteralExpr></InitializerClause></PatternBinding></VariableDecl><VariableDecl>
438+
var <PatternBinding><IdentifierPattern>a </IdentifierPattern><InitializerClause>= <StringLiteralExpr>"""<StringSegment>
439439
abc </StringSegment><ExpressionSegment>\( <FunctionCallArgument><SequenceExpr><FunctionCallExpr><IdentifierExpr>foo</IdentifierExpr>() </FunctionCallExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><FunctionCallExpr><IdentifierExpr>bar</IdentifierExpr>() </FunctionCallExpr></SequenceExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>
440-
de </StringSegment><ExpressionSegment>\(<FunctionCallArgument><SequenceExpr><IntegerLiteralExpr>3 </IntegerLiteralExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><IntegerLiteralExpr>3 </IntegerLiteralExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><StringInterpolationExpr>"<StringSegment>abc </StringSegment><ExpressionSegment>\(<FunctionCallArgument><FunctionCallExpr><IdentifierExpr>foo</IdentifierExpr>()</FunctionCallExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> def</StringSegment>"</StringInterpolationExpr></SequenceExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>
440+
de </StringSegment><ExpressionSegment>\(<FunctionCallArgument><SequenceExpr><IntegerLiteralExpr>3 </IntegerLiteralExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><IntegerLiteralExpr>3 </IntegerLiteralExpr><BinaryOperatorExpr>+ </BinaryOperatorExpr><StringLiteralExpr>"<StringSegment>abc </StringSegment><ExpressionSegment>\(<FunctionCallArgument><FunctionCallExpr><IdentifierExpr>foo</IdentifierExpr>()</FunctionCallExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment> def</StringSegment>"</StringLiteralExpr></SequenceExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>
441441
fg
442442
</StringSegment><ExpressionSegment>\(<FunctionCallArgument><IdentifierExpr>bar</IdentifierExpr>, </FunctionCallArgument><FunctionCallArgument>default: <IntegerLiteralExpr>1</IntegerLiteralExpr></FunctionCallArgument>)</ExpressionSegment><StringSegment>
443-
</StringSegment>"""</StringInterpolationExpr></InitializerClause></PatternBinding></VariableDecl>
443+
</StringSegment>"""</StringLiteralExpr></InitializerClause></PatternBinding></VariableDecl>
444444
}</CodeBlock></FunctionDecl><FunctionDecl>
445445

446446
func keypath<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSignature><CodeBlock>{<SequenceExpr><DiscardAssignmentExpr>

utils/gyb_syntax_support/ExprNodes.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,6 @@
267267
Child('Digits', kind='IntegerLiteralToken'),
268268
]),
269269

270-
Node('StringLiteralExpr', kind='Expr',
271-
children=[
272-
Child("StringLiteral", kind='StringLiteralToken')
273-
]),
274-
275270
# true or false
276271
Node('BooleanLiteralExpr', kind='Expr',
277272
children=[
@@ -476,7 +471,7 @@
476471
]),
477472

478473
# e.g. "abc \(foo()) def"
479-
Node('StringInterpolationExpr', kind='Expr',
474+
Node('StringLiteralExpr', kind='Expr',
480475
children=[
481476
Child('OpenQuote', kind='Token',
482477
token_choices=[

utils/gyb_syntax_support/NodeSerializationCodes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
'ForcedValueExpr': 61,
6767
'PostfixUnaryExpr': 62,
6868
'SpecializeExpr': 63,
69-
'StringInterpolationExpr': 64,
7069
'KeyPathExpr': 65,
7170
'KeyPathBaseExpr': 66,
7271
'ObjcKeyPathExpr': 67,

0 commit comments

Comments
 (0)