Skip to content

Commit 33d4ce3

Browse files
committed
Split FunctionParameterSyntax and related types
FunctionParameterSyntax was used in a number of cases (function parameter, closure parameter and enum case parameter) and because it needs to satisfy all of them all its parameters are optional. Split it into three different types that have non-optional children. rdar://106874808
1 parent 96e6850 commit 33d4ce3

35 files changed

+5337
-2410
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,82 @@ public let DECL_NODES: [Node] = [
428428
]
429429
),
430430

431+
Node(
432+
name: "EnumCaseParameterClause",
433+
nameForDiagnostics: "parameter clause",
434+
kind: "Syntax",
435+
traits: [
436+
"Parenthesized"
437+
],
438+
children: [
439+
Child(
440+
name: "LeftParen",
441+
kind: .token(choices: [.token(tokenKind: "LeftParenToken")])
442+
),
443+
Child(
444+
name: "ParameterList",
445+
kind: .collection(kind: "EnumCaseParameterList", collectionElementName: "Parameter"),
446+
nameForDiagnostics: "parameters",
447+
isIndented: true
448+
),
449+
Child(
450+
name: "RightParen",
451+
kind: .token(choices: [.token(tokenKind: "RightParenToken")])
452+
),
453+
]
454+
),
455+
456+
Node(
457+
name: "EnumCaseParameterList",
458+
nameForDiagnostics: "parameter list",
459+
kind: "SyntaxCollection",
460+
element: "EnumCaseParameter"
461+
),
462+
463+
Node(
464+
name: "EnumCaseParameter",
465+
nameForDiagnostics: "parameter",
466+
kind: "Syntax",
467+
traits: [
468+
"WithTrailingComma"
469+
],
470+
parserFunction: "parseEnumCaseParameter",
471+
children: [
472+
Child(
473+
name: "Modifiers",
474+
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
475+
nameForDiagnostics: "modifiers",
476+
isOptional: true
477+
),
478+
Child(
479+
name: "FirstName",
480+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
481+
isOptional: true
482+
),
483+
Child(
484+
name: "Colon",
485+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
486+
isOptional: true
487+
),
488+
Child(
489+
name: "Type",
490+
kind: .node(kind: "Type"),
491+
nameForDiagnostics: "type"
492+
),
493+
Child(
494+
name: "DefaultArgument",
495+
kind: .node(kind: "InitializerClause"),
496+
nameForDiagnostics: "default argument",
497+
isOptional: true
498+
),
499+
Child(
500+
name: "TrailingComma",
501+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
502+
isOptional: true
503+
),
504+
]
505+
),
506+
431507
Node(
432508
name: "EnumCaseDecl",
433509
nameForDiagnostics: "enum case",
@@ -489,7 +565,7 @@ public let DECL_NODES: [Node] = [
489565
),
490566
Child(
491567
name: "AssociatedValue",
492-
kind: .node(kind: "ParameterClause"),
568+
kind: .node(kind: "EnumCaseParameterClause"),
493569
nameForDiagnostics: "associated values",
494570
description: "The set of associated values of the case.",
495571
isOptional: true
@@ -699,6 +775,7 @@ public let DECL_NODES: [Node] = [
699775
"WithTrailingComma",
700776
"Attributed",
701777
],
778+
parserFunction: "parseFunctionParameter",
702779
children: [
703780
Child(
704781
name: "Attributes",
@@ -714,8 +791,7 @@ public let DECL_NODES: [Node] = [
714791
),
715792
Child(
716793
name: "FirstName",
717-
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
718-
isOptional: true
794+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")])
719795
),
720796
// One of these two names needs be optional, we choose the second
721797
// name to avoid backtracking.
@@ -727,14 +803,12 @@ public let DECL_NODES: [Node] = [
727803
),
728804
Child(
729805
name: "Colon",
730-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
731-
isOptional: true
806+
kind: .token(choices: [.token(tokenKind: "ColonToken")])
732807
),
733808
Child(
734809
name: "Type",
735810
kind: .node(kind: "Type"),
736-
nameForDiagnostics: "type",
737-
isOptional: true
811+
nameForDiagnostics: "type"
738812
),
739813
Child(
740814
name: "Ellipsis",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,81 @@ public let EXPR_NODES: [Node] = [
301301
]
302302
),
303303

304+
Node(
305+
name: "ClosureParameter",
306+
nameForDiagnostics: "parameter",
307+
kind: "Syntax",
308+
traits: [
309+
"WithTrailingComma"
310+
],
311+
parserFunction: "parseClosureParameter",
312+
children: [
313+
Child(
314+
name: "Modifiers",
315+
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
316+
nameForDiagnostics: "modifiers",
317+
isOptional: true
318+
),
319+
Child(
320+
name: "FirstName",
321+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")])
322+
),
323+
Child(
324+
name: "Colon",
325+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
326+
isOptional: true
327+
),
328+
Child(
329+
name: "Type",
330+
kind: .node(kind: "Type"),
331+
nameForDiagnostics: "type",
332+
isOptional: true
333+
),
334+
Child(
335+
name: "Ellipsis",
336+
kind: .token(choices: [.token(tokenKind: "EllipsisToken")]),
337+
isOptional: true
338+
),
339+
Child(
340+
name: "TrailingComma",
341+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
342+
isOptional: true
343+
),
344+
]
345+
),
346+
347+
Node(
348+
name: "ClosureParameterList",
349+
nameForDiagnostics: "parameter list",
350+
kind: "SyntaxCollection",
351+
element: "ClosureParameter"
352+
),
353+
354+
Node(
355+
name: "ClosureParameterClause",
356+
nameForDiagnostics: "parameter clause",
357+
kind: "Syntax",
358+
traits: [
359+
"Parenthesized"
360+
],
361+
children: [
362+
Child(
363+
name: "LeftParen",
364+
kind: .token(choices: [.token(tokenKind: "LeftParenToken")])
365+
),
366+
Child(
367+
name: "ParameterList",
368+
kind: .collection(kind: "ClosureParameterList", collectionElementName: "Parameter"),
369+
nameForDiagnostics: "parameters",
370+
isIndented: true
371+
),
372+
Child(
373+
name: "RightParen",
374+
kind: .token(choices: [.token(tokenKind: "RightParenToken")])
375+
),
376+
]
377+
),
378+
304379
Node(
305380
name: "ClosureExpr",
306381
nameForDiagnostics: "closure",
@@ -389,7 +464,7 @@ public let EXPR_NODES: [Node] = [
389464
),
390465
Child(
391466
name: "Input",
392-
kind: .node(kind: "ParameterClause")
467+
kind: .node(kind: "ClosureParameterClause")
393468
),
394469
]),
395470
isOptional: true

Sources/SwiftBasicFormat/generated/BasicFormat.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ open class BasicFormat: SyntaxRewriter {
9999
return true
100100
case \ClosureExprSyntax.statements:
101101
return true
102+
case \ClosureParameterClauseSyntax.parameterList:
103+
return true
102104
case \CodeBlockSyntax.statements:
103105
return true
104106
case \DictionaryElementSyntax.valueExpression:
105107
return true
106108
case \DictionaryExprSyntax.content:
107109
return true
110+
case \EnumCaseParameterClauseSyntax.parameterList:
111+
return true
108112
case \FunctionCallExprSyntax.argumentList:
109113
return true
110114
case \FunctionTypeSyntax.arguments:

Sources/SwiftParser/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ add_swift_host_library(SwiftParser
1818
Modifiers.swift
1919
Names.swift
2020
Nominals.swift
21+
Parameters.swift
2122
Parser.swift
2223
Patterns.swift
2324
TokenSpec.swift

0 commit comments

Comments
 (0)