Skip to content

Commit 78de9ef

Browse files
authored
Merge pull request #1228 from hamishknight/express-yourself
2 parents 27d0697 + e072157 commit 78de9ef

33 files changed

+11570
-10732
lines changed

CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,122 @@ public let EXPR_NODES: [Node] = [
362362
kind: .token(choices: [.keyword(text: "true"), .keyword(text: "false")]))
363363
]),
364364

365+
Node(name: "IfExpr",
366+
nameForDiagnostics: "'if' statement",
367+
kind: "Expr",
368+
traits: [
369+
"WithCodeBlock"
370+
],
371+
children: [
372+
Child(name: "IfKeyword",
373+
kind: .token(choices: [.keyword(text: "if")])),
374+
Child(name: "Conditions",
375+
kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition")),
376+
Child(name: "Body",
377+
kind: .node(kind: "CodeBlock")),
378+
Child(name: "ElseKeyword",
379+
kind: .node(kind: "ElseToken"),
380+
isOptional: true),
381+
Child(name: "ElseBody",
382+
kind: .nodeChoices(choices: [
383+
Child(name: "IfExpr",
384+
kind: .node(kind: "IfExpr")),
385+
Child(name: "CodeBlock",
386+
kind: .node(kind: "CodeBlock"))
387+
]),
388+
isOptional: true)
389+
]),
390+
391+
Node(name: "SwitchExpr",
392+
nameForDiagnostics: "'switch' statement",
393+
kind: "Expr",
394+
traits: [
395+
"Braced"
396+
],
397+
children: [
398+
Child(name: "SwitchKeyword",
399+
kind: .token(choices: [.keyword(text: "switch")])),
400+
Child(name: "Expression",
401+
kind: .node(kind: "Expr")),
402+
Child(name: "LeftBrace",
403+
kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])),
404+
Child(name: "Cases",
405+
kind: .collection(kind: "SwitchCaseList", collectionElementName: "Case")),
406+
Child(name: "RightBrace",
407+
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
408+
requiresLeadingNewline: true)
409+
]),
410+
411+
Node(name: "SwitchCaseList",
412+
nameForDiagnostics: nil,
413+
kind: "SyntaxCollection",
414+
element: "Syntax",
415+
elementName: "SwitchCase",
416+
elementChoices: ["SwitchCase", "IfConfigDecl"],
417+
elementsSeparatedByNewline: true),
418+
419+
Node(name: "SwitchCase",
420+
nameForDiagnostics: "switch case",
421+
kind: "Syntax",
422+
traits: [
423+
"WithStatements"
424+
],
425+
parserFunction: "parseSwitchCase",
426+
children: [
427+
Child(name: "UnknownAttr",
428+
kind: .node(kind: "Attribute"),
429+
isOptional: true),
430+
Child(name: "Label",
431+
kind: .nodeChoices(choices: [
432+
Child(name: "Default",
433+
kind: .node(kind: "SwitchDefaultLabel")),
434+
Child(name: "Case",
435+
kind: .node(kind: "SwitchCaseLabel"))
436+
])),
437+
Child(name: "Statements",
438+
kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"),
439+
isIndented: true)
440+
]),
441+
442+
Node(name: "SwitchCaseLabel",
443+
nameForDiagnostics: nil,
444+
kind: "Syntax",
445+
children: [
446+
Child(name: "CaseKeyword",
447+
kind: .token(choices: [.keyword(text: "case")])),
448+
Child(name: "CaseItems",
449+
kind: .collection(kind: "CaseItemList", collectionElementName: "CaseItem")),
450+
Child(name: "Colon",
451+
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
452+
]),
453+
454+
Node(name: "SwitchDefaultLabel",
455+
nameForDiagnostics: nil,
456+
kind: "Syntax",
457+
children: [
458+
Child(name: "DefaultKeyword",
459+
kind: .token(choices: [.keyword(text: "default")])),
460+
Child(name: "Colon",
461+
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
462+
]),
463+
464+
Node(name: "CaseItem",
465+
nameForDiagnostics: nil,
466+
kind: "Syntax",
467+
traits: [
468+
"WithTrailingComma"
469+
],
470+
children: [
471+
Child(name: "Pattern",
472+
kind: .node(kind: "Pattern")),
473+
Child(name: "WhereClause",
474+
kind: .node(kind: "WhereClause"),
475+
isOptional: true),
476+
Child(name: "TrailingComma",
477+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
478+
isOptional: true)
479+
]),
480+
365481
Node(name: "UnresolvedTernaryExpr",
366482
nameForDiagnostics: "ternary operator",
367483
kind: "Expr",

CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift

Lines changed: 8 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public let STMT_NODES: [Node] = [
2525
kind: .node(kind: "Stmt"))
2626
]),
2727

28+
Node(name: "ExpressionStmt",
29+
nameForDiagnostics: "expression",
30+
kind: "Stmt",
31+
children: [
32+
Child(name: "Expression",
33+
kind: .node(kind: "Expr"))
34+
]),
35+
2836
Node(name: "ContinueStmt",
2937
nameForDiagnostics: "'continue' statement",
3038
kind: "Stmt",
@@ -64,14 +72,6 @@ public let STMT_NODES: [Node] = [
6472
kind: .node(kind: "CodeBlock"))
6573
]),
6674

67-
Node(name: "SwitchCaseList",
68-
nameForDiagnostics: nil,
69-
kind: "SyntaxCollection",
70-
element: "Syntax",
71-
elementName: "SwitchCase",
72-
elementChoices: ["SwitchCase", "IfConfigDecl"],
73-
elementsSeparatedByNewline: true),
74-
7575
Node(name: "RepeatWhileStmt",
7676
nameForDiagnostics: "'repeat' statement",
7777
kind: "Stmt",
@@ -151,26 +151,6 @@ public let STMT_NODES: [Node] = [
151151
kind: .node(kind: "CodeBlock"))
152152
]),
153153

154-
Node(name: "SwitchStmt",
155-
nameForDiagnostics: "'switch' statement",
156-
kind: "Stmt",
157-
traits: [
158-
"Braced"
159-
],
160-
children: [
161-
Child(name: "SwitchKeyword",
162-
kind: .token(choices: [.keyword(text: "switch")])),
163-
Child(name: "Expression",
164-
kind: .node(kind: "Expr")),
165-
Child(name: "LeftBrace",
166-
kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])),
167-
Child(name: "Cases",
168-
kind: .collection(kind: "SwitchCaseList", collectionElementName: "Case")),
169-
Child(name: "RightBrace",
170-
kind: .token(choices: [.token(tokenKind: "RightBraceToken")]),
171-
requiresLeadingNewline: true)
172-
]),
173-
174154
Node(name: "CatchClauseList",
175155
nameForDiagnostics: "'catch' clause",
176156
kind: "SyntaxCollection",
@@ -342,82 +322,6 @@ public let STMT_NODES: [Node] = [
342322
kind: .node(kind: "Expr"))
343323
]),
344324

345-
Node(name: "IfStmt",
346-
nameForDiagnostics: "'if' statement",
347-
kind: "Stmt",
348-
traits: [
349-
"WithCodeBlock"
350-
],
351-
children: [
352-
Child(name: "IfKeyword",
353-
kind: .token(choices: [.keyword(text: "if")])),
354-
Child(name: "Conditions",
355-
kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition")),
356-
Child(name: "Body",
357-
kind: .node(kind: "CodeBlock")),
358-
Child(name: "ElseKeyword",
359-
kind: .node(kind: "ElseToken"),
360-
isOptional: true),
361-
Child(name: "ElseBody",
362-
kind: .nodeChoices(choices: [
363-
Child(name: "IfStmt",
364-
kind: .node(kind: "IfStmt")),
365-
Child(name: "CodeBlock",
366-
kind: .node(kind: "CodeBlock"))
367-
]),
368-
isOptional: true)
369-
]),
370-
371-
Node(name: "SwitchCase",
372-
nameForDiagnostics: "switch case",
373-
kind: "Syntax",
374-
traits: [
375-
"WithStatements"
376-
],
377-
parserFunction: "parseSwitchCase",
378-
children: [
379-
Child(name: "UnknownAttr",
380-
kind: .node(kind: "Attribute"),
381-
isOptional: true),
382-
Child(name: "Label",
383-
kind: .nodeChoices(choices: [
384-
Child(name: "Default",
385-
kind: .node(kind: "SwitchDefaultLabel")),
386-
Child(name: "Case",
387-
kind: .node(kind: "SwitchCaseLabel"))
388-
])),
389-
Child(name: "Statements",
390-
kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"),
391-
isIndented: true)
392-
]),
393-
394-
Node(name: "SwitchDefaultLabel",
395-
nameForDiagnostics: nil,
396-
kind: "Syntax",
397-
children: [
398-
Child(name: "DefaultKeyword",
399-
kind: .token(choices: [.keyword(text: "default")])),
400-
Child(name: "Colon",
401-
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
402-
]),
403-
404-
Node(name: "CaseItem",
405-
nameForDiagnostics: nil,
406-
kind: "Syntax",
407-
traits: [
408-
"WithTrailingComma"
409-
],
410-
children: [
411-
Child(name: "Pattern",
412-
kind: .node(kind: "Pattern")),
413-
Child(name: "WhereClause",
414-
kind: .node(kind: "WhereClause"),
415-
isOptional: true),
416-
Child(name: "TrailingComma",
417-
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
418-
isOptional: true)
419-
]),
420-
421325
Node(name: "CatchItem",
422326
nameForDiagnostics: nil,
423327
kind: "Syntax",
@@ -436,18 +340,6 @@ public let STMT_NODES: [Node] = [
436340
isOptional: true)
437341
]),
438342

439-
Node(name: "SwitchCaseLabel",
440-
nameForDiagnostics: nil,
441-
kind: "Syntax",
442-
children: [
443-
Child(name: "CaseKeyword",
444-
kind: .token(choices: [.keyword(text: "case")])),
445-
Child(name: "CaseItems",
446-
kind: .collection(kind: "CaseItemList", collectionElementName: "CaseItem")),
447-
Child(name: "Colon",
448-
kind: .token(choices: [.token(tokenKind: "ColonToken")]))
449-
]),
450-
451343
Node(name: "CatchClause",
452344
nameForDiagnostics: "'catch' clause",
453345
kind: "Syntax",

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ open class BasicFormat: SyntaxRewriter {
114114
return true
115115
case \MemberDeclBlockSyntax.rightBrace:
116116
return true
117-
case \SwitchStmtSyntax.rightBrace:
117+
case \SwitchExprSyntax.rightBrace:
118118
return true
119119
default:
120120
return putNextTokenOnNewLine

0 commit comments

Comments
 (0)