Skip to content

Commit 89d5d32

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 89d5d32

35 files changed

+5447
-2406
lines changed

CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,90 @@ 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+
description: "The '(' to open the parameter clause."
443+
),
444+
Child(
445+
name: "ParameterList",
446+
kind: .collection(kind: "EnumCaseParameterList", collectionElementName: "Parameter"),
447+
nameForDiagnostics: "parameters",
448+
description: "The actual parameters.",
449+
isIndented: true
450+
),
451+
Child(
452+
name: "RightParen",
453+
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
454+
description: "The ')' to close the parameter clause."
455+
),
456+
]
457+
),
458+
459+
Node(
460+
name: "EnumCaseParameterList",
461+
nameForDiagnostics: "parameter list",
462+
kind: "SyntaxCollection",
463+
element: "EnumCaseParameter"
464+
),
465+
466+
Node(
467+
name: "EnumCaseParameter",
468+
nameForDiagnostics: "parameter",
469+
kind: "Syntax",
470+
traits: [
471+
"WithTrailingComma"
472+
],
473+
parserFunction: "parseEnumCaseParameter",
474+
children: [
475+
Child(
476+
name: "Modifiers",
477+
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
478+
nameForDiagnostics: "modifiers",
479+
isOptional: true
480+
),
481+
Child(
482+
name: "Label",
483+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
484+
description: "If the parameter is labeled, its label.",
485+
isOptional: true
486+
),
487+
Child(
488+
name: "Colon",
489+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
490+
description: "If the parameter has a label, the colon separating the label from the type.",
491+
isOptional: true
492+
),
493+
Child(
494+
name: "Type",
495+
kind: .node(kind: "Type"),
496+
nameForDiagnostics: "type",
497+
description: "The parameter's type."
498+
),
499+
Child(
500+
name: "DefaultArgument",
501+
kind: .node(kind: "InitializerClause"),
502+
nameForDiagnostics: "default argument",
503+
description: "If the parameter has a default value, the initializer clause describing the default value.",
504+
isOptional: true
505+
),
506+
Child(
507+
name: "TrailingComma",
508+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
509+
description: "If the parameter is followed by another parameter, the comma separating them.",
510+
isOptional: true
511+
),
512+
]
513+
),
514+
431515
Node(
432516
name: "EnumCaseDecl",
433517
nameForDiagnostics: "enum case",
@@ -489,7 +573,7 @@ public let DECL_NODES: [Node] = [
489573
),
490574
Child(
491575
name: "AssociatedValue",
492-
kind: .node(kind: "ParameterClause"),
576+
kind: .node(kind: "EnumCaseParameterClause"),
493577
nameForDiagnostics: "associated values",
494578
description: "The set of associated values of the case.",
495579
isOptional: true
@@ -699,6 +783,7 @@ public let DECL_NODES: [Node] = [
699783
"WithTrailingComma",
700784
"Attributed",
701785
],
786+
parserFunction: "parseFunctionParameter",
702787
children: [
703788
Child(
704789
name: "Attributes",
@@ -714,8 +799,7 @@ public let DECL_NODES: [Node] = [
714799
),
715800
Child(
716801
name: "FirstName",
717-
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
718-
isOptional: true
802+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")])
719803
),
720804
// One of these two names needs be optional, we choose the second
721805
// name to avoid backtracking.
@@ -727,14 +811,12 @@ public let DECL_NODES: [Node] = [
727811
),
728812
Child(
729813
name: "Colon",
730-
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
731-
isOptional: true
814+
kind: .token(choices: [.token(tokenKind: "ColonToken")])
732815
),
733816
Child(
734817
name: "Type",
735818
kind: .node(kind: "Type"),
736-
nameForDiagnostics: "type",
737-
isOptional: true
819+
nameForDiagnostics: "type"
738820
),
739821
Child(
740822
name: "Ellipsis",

CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,95 @@ 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+
description: "The label of this parameter that will be used when the closure is called."
323+
),
324+
Child(
325+
name: "SecondName",
326+
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
327+
description: "If this is specified, it is the name by which the parameter can be referenced inside the closure body. If it is `nil`, the closure parameter is referenced by the first name.",
328+
isOptional: true
329+
),
330+
Child(
331+
name: "Colon",
332+
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
333+
description: "The colon separating the parameter's name and type.",
334+
isOptional: true
335+
),
336+
Child(
337+
name: "Type",
338+
kind: .node(kind: "Type"),
339+
nameForDiagnostics: "type",
340+
description: "The type of the parameter.",
341+
isOptional: true
342+
),
343+
Child(
344+
name: "Ellipsis",
345+
kind: .token(choices: [.token(tokenKind: "EllipsisToken")]),
346+
description: "If the parameter is variadic, `...` to indicate that.",
347+
isOptional: true
348+
),
349+
Child(
350+
name: "TrailingComma",
351+
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
352+
description: "If the parameter is followed by another parameter, the comma separating them.",
353+
isOptional: true
354+
),
355+
]
356+
),
357+
358+
Node(
359+
name: "ClosureParameterList",
360+
nameForDiagnostics: "parameter list",
361+
kind: "SyntaxCollection",
362+
element: "ClosureParameter"
363+
),
364+
365+
Node(
366+
name: "ClosureParameterClause",
367+
nameForDiagnostics: "parameter clause",
368+
kind: "Syntax",
369+
traits: [
370+
"Parenthesized"
371+
],
372+
children: [
373+
Child(
374+
name: "LeftParen",
375+
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
376+
description: "The '(' to open the parameter clause."
377+
),
378+
Child(
379+
name: "ParameterList",
380+
kind: .collection(kind: "ClosureParameterList", collectionElementName: "Parameter"),
381+
nameForDiagnostics: "parameters",
382+
description: "The actual parameters.",
383+
isIndented: true
384+
),
385+
Child(
386+
name: "RightParen",
387+
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
388+
description: "The ')' to close the parameter clause."
389+
),
390+
]
391+
),
392+
304393
Node(
305394
name: "ClosureExpr",
306395
nameForDiagnostics: "closure",
@@ -389,7 +478,7 @@ public let EXPR_NODES: [Node] = [
389478
),
390479
Child(
391480
name: "Input",
392-
kind: .node(kind: "ParameterClause")
481+
kind: .node(kind: "ClosureParameterClause")
393482
),
394483
]),
395484
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)