Skip to content

[Syntax] Make PostfixIfConfigExpr.base optional #38410

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

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,22 @@ func foo<FunctionSignature><ParameterClause>() </ParameterClause></FunctionSigna
##"<StringSegment>abc </StringSegment><ExpressionSegment>\##(<TupleExprElement><IdentifierExpr>foo</IdentifierExpr></TupleExprElement>)</ExpressionSegment><StringSegment></StringSegment>"##</StringLiteralExpr><PostfixIfConfigExpr><FunctionCallExpr><IdentifierExpr>

foo</IdentifierExpr>()</FunctionCallExpr><IfConfigDecl><IfConfigClause>
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><ForcedValueExpr><FunctionCallExpr><OptionalChainingExpr><MemberAccessExpr>
#if <IdentifierExpr>COND1</IdentifierExpr><ForcedValueExpr><FunctionCallExpr><OptionalChainingExpr><MemberAccessExpr>
.bar</MemberAccessExpr>?</OptionalChainingExpr>()</FunctionCallExpr>!</ForcedValueExpr></IfConfigClause><IfConfigClause>
#elseif <IdentifierExpr>COND2</IdentifierExpr><MemberAccessExpr><PostfixIfConfigExpr><IfConfigDecl><IfConfigClause>
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><FunctionCallExpr><MemberAccessExpr>
.call</MemberAccessExpr>()</FunctionCallExpr></IfConfigClause><IfConfigClause>
#elseif <BooleanLiteralExpr>true</BooleanLiteralExpr><PostfixIfConfigExpr><IfConfigDecl><IfConfigClause>
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><MemberAccessExpr>
.other</MemberAccessExpr></IfConfigClause>
#endif</IfConfigDecl></PostfixIfConfigExpr></IfConfigClause><IfConfigClause>
#else<PostfixIfConfigExpr><FunctionCallExpr><MemberAccessExpr>
.before</MemberAccessExpr>()</FunctionCallExpr><IfConfigDecl><IfConfigClause>
#if <BooleanLiteralExpr>true</BooleanLiteralExpr><FunctionCallExpr><MemberAccessExpr>
.after</MemberAccessExpr>()</FunctionCallExpr></IfConfigClause>
#endif</IfConfigDecl></PostfixIfConfigExpr></IfConfigClause>
#endif</IfConfigDecl></PostfixIfConfigExpr>
.member</MemberAccessExpr></IfConfigClause><IfConfigClause>
#else<FunctionCallExpr><MemberAccessExpr>
.baz</MemberAccessExpr>() <ClosureExpr>{}</ClosureExpr></FunctionCallExpr></IfConfigClause>
#endif</IfConfigDecl></PostfixIfConfigExpr>
16 changes: 15 additions & 1 deletion test/Syntax/round_trip_parse_gen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,22 @@ func foo() {}
##"abc \##(foo)"##

foo()
#if true
#if COND1
.bar?()!
#elseif COND2
#if true
.call()
#elseif true
#if true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth having another case where there is an intervening member access expression in the middle of two clauses, to check that the base is present in that nesting scenario? For example,

foo()
#if COND1
  .bar?()!
#elseif COND2
  #if true
    .call()
  #else
    .somethingElse
    #if true
      ...

.other
#endif
#else
.before()
#if true
.after()
#endif
#endif
.member
#else
.baz() {}
#endif
2 changes: 1 addition & 1 deletion utils/gyb_syntax_support/ExprNodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
# postfix '#if' expession
Node('PostfixIfConfigExpr', kind='Expr',
children=[
Child('Base', kind='Expr'),
Child('Base', kind='Expr', is_optional=True),
Child('Config', kind='IfConfigDecl'),
]),

Expand Down