Skip to content

[5.8] Introduce if/switch expressions #1305

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
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
152 changes: 152 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,158 @@ public let EXPR_NODES: [Node] = [
])
]),

Node(name: "IfExpr",
nameForDiagnostics: "'if' statement",
kind: "Expr",
traits: [
"WithCodeBlock"
],
children: [
Child(name: "IfKeyword",
kind: "IfToken",
tokenChoices: [
"If"
]),
Child(name: "Conditions",
kind: "ConditionElementList",
collectionElementName: "Condition"),
Child(name: "Body",
kind: "CodeBlock"),
Child(name: "ElseKeyword",
kind: "ElseToken",
isOptional: true,
tokenChoices: [
"Else"
]),
Child(name: "ElseBody",
kind: "Syntax",
isOptional: true,
nodeChoices: [
Child(name: "IfExpr",
kind: "IfExpr"),
Child(name: "CodeBlock",
kind: "CodeBlock")
])
]),

Node(name: "SwitchExpr",
nameForDiagnostics: "'switch' statement",
kind: "Expr",
traits: [
"Braced"
],
children: [
Child(name: "SwitchKeyword",
kind: "SwitchToken",
tokenChoices: [
"Switch"
]),
Child(name: "Expression",
kind: "Expr"),
Child(name: "LeftBrace",
kind: "LeftBraceToken",
tokenChoices: [
"LeftBrace"
]),
Child(name: "Cases",
kind: "SwitchCaseList",
collectionElementName: "Case"),
Child(name: "RightBrace",
kind: "RightBraceToken",
tokenChoices: [
"RightBrace"
],
requiresLeadingNewline: true)
]),

Node(name: "SwitchCaseList",
nameForDiagnostics: nil,
kind: "SyntaxCollection",
element: "Syntax",
elementName: "SwitchCase",
elementChoices: ["SwitchCase", "IfConfigDecl"],
elementsSeparatedByNewline: true),

Node(name: "SwitchCase",
nameForDiagnostics: "switch case",
kind: "Syntax",
traits: [
"WithStatements"
],
parserFunction: "parseSwitchCase",
children: [
Child(name: "UnknownAttr",
kind: "Attribute",
isOptional: true),
Child(name: "Label",
kind: "Syntax",
nodeChoices: [
Child(name: "Default",
kind: "SwitchDefaultLabel"),
Child(name: "Case",
kind: "SwitchCaseLabel")
]),
Child(name: "Statements",
kind: "CodeBlockItemList",
collectionElementName: "Statement",
isIndented: true)
]),

Node(name: "SwitchCaseLabel",
nameForDiagnostics: nil,
kind: "Syntax",
children: [
Child(name: "CaseKeyword",
kind: "CaseToken",
tokenChoices: [
"Case"
]),
Child(name: "CaseItems",
kind: "CaseItemList",
collectionElementName: "CaseItem"),
Child(name: "Colon",
kind: "ColonToken",
tokenChoices: [
"Colon"
])
]),

Node(name: "SwitchDefaultLabel",
nameForDiagnostics: nil,
kind: "Syntax",
children: [
Child(name: "DefaultKeyword",
kind: "DefaultToken",
tokenChoices: [
"Default"
]),
Child(name: "Colon",
kind: "ColonToken",
tokenChoices: [
"Colon"
])
]),

Node(name: "CaseItem",
nameForDiagnostics: nil,
kind: "Syntax",
traits: [
"WithTrailingComma"
],
children: [
Child(name: "Pattern",
kind: "Pattern"),
Child(name: "WhereClause",
kind: "WhereClause",
isOptional: true),
Child(name: "TrailingComma",
kind: "CommaToken",
isOptional: true,
tokenChoices: [
"Comma"
])
]),

Node(name: "UnresolvedTernaryExpr",
nameForDiagnostics: nil,
kind: "Expr",
Expand Down
152 changes: 0 additions & 152 deletions CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ public let STMT_NODES: [Node] = [
kind: "Expr")
]),

Node(name: "SwitchCaseList",
nameForDiagnostics: nil,
kind: "SyntaxCollection",
element: "Syntax",
elementName: "SwitchCase",
elementChoices: ["SwitchCase", "IfConfigDecl"],
elementsSeparatedByNewline: true),

Node(name: "RepeatWhileStmt",
nameForDiagnostics: "'repeat' statement",
kind: "Stmt",
Expand Down Expand Up @@ -212,36 +204,6 @@ public let STMT_NODES: [Node] = [
kind: "CodeBlock")
]),

Node(name: "SwitchStmt",
nameForDiagnostics: "'switch' statement",
kind: "Stmt",
traits: [
"Braced"
],
children: [
Child(name: "SwitchKeyword",
kind: "SwitchToken",
tokenChoices: [
"Switch"
]),
Child(name: "Expression",
kind: "Expr"),
Child(name: "LeftBrace",
kind: "LeftBraceToken",
tokenChoices: [
"LeftBrace"
]),
Child(name: "Cases",
kind: "SwitchCaseList",
collectionElementName: "Case"),
Child(name: "RightBrace",
kind: "RightBraceToken",
tokenChoices: [
"RightBrace"
],
requiresLeadingNewline: true)
]),

Node(name: "CatchClauseList",
nameForDiagnostics: "'catch' clause",
kind: "SyntaxCollection",
Expand Down Expand Up @@ -520,101 +482,6 @@ public let STMT_NODES: [Node] = [
kind: "Expr")
]),

Node(name: "IfStmt",
nameForDiagnostics: "'if' statement",
kind: "Stmt",
traits: [
"WithCodeBlock"
],
children: [
Child(name: "IfKeyword",
kind: "IfToken",
tokenChoices: [
"If"
]),
Child(name: "Conditions",
kind: "ConditionElementList",
collectionElementName: "Condition"),
Child(name: "Body",
kind: "CodeBlock"),
Child(name: "ElseKeyword",
kind: "ElseToken",
isOptional: true,
tokenChoices: [
"Else"
]),
Child(name: "ElseBody",
kind: "Syntax",
isOptional: true,
nodeChoices: [
Child(name: "IfStmt",
kind: "IfStmt"),
Child(name: "CodeBlock",
kind: "CodeBlock")
])
]),

Node(name: "SwitchCase",
nameForDiagnostics: "switch case",
kind: "Syntax",
traits: [
"WithStatements"
],
parserFunction: "parseSwitchCase",
children: [
Child(name: "UnknownAttr",
kind: "Attribute",
isOptional: true),
Child(name: "Label",
kind: "Syntax",
nodeChoices: [
Child(name: "Default",
kind: "SwitchDefaultLabel"),
Child(name: "Case",
kind: "SwitchCaseLabel")
]),
Child(name: "Statements",
kind: "CodeBlockItemList",
collectionElementName: "Statement",
isIndented: true)
]),

Node(name: "SwitchDefaultLabel",
nameForDiagnostics: nil,
kind: "Syntax",
children: [
Child(name: "DefaultKeyword",
kind: "DefaultToken",
tokenChoices: [
"Default"
]),
Child(name: "Colon",
kind: "ColonToken",
tokenChoices: [
"Colon"
])
]),

Node(name: "CaseItem",
nameForDiagnostics: nil,
kind: "Syntax",
traits: [
"WithTrailingComma"
],
children: [
Child(name: "Pattern",
kind: "Pattern"),
Child(name: "WhereClause",
kind: "WhereClause",
isOptional: true),
Child(name: "TrailingComma",
kind: "CommaToken",
isOptional: true,
tokenChoices: [
"Comma"
])
]),

Node(name: "CatchItem",
nameForDiagnostics: nil,
kind: "Syntax",
Expand All @@ -636,25 +503,6 @@ public let STMT_NODES: [Node] = [
])
]),

Node(name: "SwitchCaseLabel",
nameForDiagnostics: nil,
kind: "Syntax",
children: [
Child(name: "CaseKeyword",
kind: "CaseToken",
tokenChoices: [
"Case"
]),
Child(name: "CaseItems",
kind: "CaseItemList",
collectionElementName: "CaseItem"),
Child(name: "Colon",
kind: "ColonToken",
tokenChoices: [
"Colon"
])
]),

Node(name: "CatchClause",
nameForDiagnostics: "'catch' clause",
kind: "Syntax",
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftBasicFormat/generated/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ open class BasicFormat: SyntaxRewriter {
return true
case \MemberDeclBlockSyntax.rightBrace:
return true
case \SwitchStmtSyntax.rightBrace:
case \SwitchExprSyntax.rightBrace:
return true
default:
return putNextTokenOnNewLine
Expand Down
Loading