Skip to content

Commit 0441183

Browse files
authoredJul 16, 2021
Merge pull request #38410 from rintaro/syntax-postfixifconfig-sr14929
[Syntax] Make `PostfixIfConfigExpr.base` optional

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed
 

‎test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

+15-1
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,22 @@ func foo<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSigna
599599
##"<StringSegment>abc </StringSegment><ExpressionSegment>\##(<TupleExprElement><IdentifierExpr>foo</IdentifierExpr></TupleExprElement>)</ExpressionSegment><StringSegment></StringSegment>"##</StringLiteralExpr><PostfixIfConfigExpr><FunctionCallExpr><IdentifierExpr>
600600

601601
foo</IdentifierExpr>()</FunctionCallExpr><IfConfigDecl><IfConfigClause>
602-
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><ForcedValueExpr><FunctionCallExpr><OptionalChainingExpr><MemberAccessExpr>
602+
#if <IdentifierExpr>COND1</IdentifierExpr><ForcedValueExpr><FunctionCallExpr><OptionalChainingExpr><MemberAccessExpr>
603603
.bar</MemberAccessExpr>?</OptionalChainingExpr>()</FunctionCallExpr>!</ForcedValueExpr></IfConfigClause><IfConfigClause>
604+
#elseif <IdentifierExpr>COND2</IdentifierExpr><MemberAccessExpr><PostfixIfConfigExpr><IfConfigDecl><IfConfigClause>
605+
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><FunctionCallExpr><MemberAccessExpr>
606+
.call</MemberAccessExpr>()</FunctionCallExpr></IfConfigClause><IfConfigClause>
607+
#elseif <BooleanLiteralExpr>true</BooleanLiteralExpr><PostfixIfConfigExpr><IfConfigDecl><IfConfigClause>
608+
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><MemberAccessExpr>
609+
.other</MemberAccessExpr></IfConfigClause>
610+
#endif</IfConfigDecl></PostfixIfConfigExpr></IfConfigClause><IfConfigClause>
611+
#else<PostfixIfConfigExpr><FunctionCallExpr><MemberAccessExpr>
612+
.before</MemberAccessExpr>()</FunctionCallExpr><IfConfigDecl><IfConfigClause>
613+
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><FunctionCallExpr><MemberAccessExpr>
614+
.after</MemberAccessExpr>()</FunctionCallExpr></IfConfigClause>
615+
#endif</IfConfigDecl></PostfixIfConfigExpr></IfConfigClause>
616+
#endif</IfConfigDecl></PostfixIfConfigExpr>
617+
.member</MemberAccessExpr></IfConfigClause><IfConfigClause>
604618
#else<FunctionCallExpr><MemberAccessExpr>
605619
.baz</MemberAccessExpr>() <ClosureExpr>{}</ClosureExpr></FunctionCallExpr></IfConfigClause>
606620
#endif</IfConfigDecl></PostfixIfConfigExpr>

‎test/Syntax/round_trip_parse_gen.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,22 @@ func foo() {}
599599
##"abc \##(foo)"##
600600

601601
foo()
602-
#if true
602+
#if COND1
603603
.bar?()!
604+
#elseif COND2
605+
#if true
606+
.call()
607+
#elseif true
608+
#if true
609+
.other
610+
#endif
611+
#else
612+
.before()
613+
#if true
614+
.after()
615+
#endif
616+
#endif
617+
.member
604618
#else
605619
.baz() {}
606620
#endif

‎utils/gyb_syntax_support/ExprNodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@
597597
# postfix '#if' expession
598598
Node('PostfixIfConfigExpr', kind='Expr',
599599
children=[
600-
Child('Base', kind='Expr'),
600+
Child('Base', kind='Expr', is_optional=True),
601601
Child('Config', kind='IfConfigDecl'),
602602
]),
603603

0 commit comments

Comments
 (0)
Please sign in to comment.