Skip to content
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

Split FunctionParameterSyntax and related types #1455

Merged
merged 1 commit into from
Apr 5, 2023
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
100 changes: 93 additions & 7 deletions CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,94 @@ public let DECL_NODES: [Node] = [
]
),

Node(
name: "EnumCaseParameterClause",
nameForDiagnostics: "parameter clause",
kind: "Syntax",
traits: [
"Parenthesized"
],
children: [
Child(
name: "LeftParen",
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
description: "The '(' to open the parameter clause."
),
Child(
name: "ParameterList",
kind: .collection(kind: "EnumCaseParameterList", collectionElementName: "Parameter"),
nameForDiagnostics: "parameters",
description: "The actual parameters.",
isIndented: true
),
Child(
name: "RightParen",
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
description: "The ')' to close the parameter clause."
),
]
),

Node(
name: "EnumCaseParameterList",
nameForDiagnostics: "parameter list",
kind: "SyntaxCollection",
element: "EnumCaseParameter"
),

Node(
name: "EnumCaseParameter",
nameForDiagnostics: "parameter",
kind: "Syntax",
traits: [
"WithTrailingComma"
],
parserFunction: "parseEnumCaseParameter",
children: [
Child(
name: "Modifiers",
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
nameForDiagnostics: "modifiers",
isOptional: true
),
Child(
name: "FirstName",
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
isOptional: true
),
Child(
name: "SecondName",
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
isOptional: true
),
Child(
name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
description: "If the parameter has a label, the colon separating the label from the type.",
isOptional: true
),
Child(
name: "Type",
kind: .node(kind: "Type"),
nameForDiagnostics: "type",
description: "The parameter's type."
),
Child(
name: "DefaultArgument",
kind: .node(kind: "InitializerClause"),
nameForDiagnostics: "default argument",
description: "If the parameter has a default value, the initializer clause describing the default value.",
isOptional: true
),
Child(
name: "TrailingComma",
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
description: "If the parameter is followed by another parameter, the comma separating them.",
isOptional: true
),
]
),

Node(
name: "EnumCaseDecl",
nameForDiagnostics: "enum case",
Expand Down Expand Up @@ -489,7 +577,7 @@ public let DECL_NODES: [Node] = [
),
Child(
name: "AssociatedValue",
kind: .node(kind: "ParameterClause"),
kind: .node(kind: "EnumCaseParameterClause"),
nameForDiagnostics: "associated values",
description: "The set of associated values of the case.",
isOptional: true
Expand Down Expand Up @@ -699,6 +787,7 @@ public let DECL_NODES: [Node] = [
"WithTrailingComma",
"Attributed",
],
parserFunction: "parseFunctionParameter",
children: [
Child(
name: "Attributes",
Expand All @@ -714,8 +803,7 @@ public let DECL_NODES: [Node] = [
),
Child(
name: "FirstName",
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
isOptional: true
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")])
),
// One of these two names needs be optional, we choose the second
// name to avoid backtracking.
Expand All @@ -727,14 +815,12 @@ public let DECL_NODES: [Node] = [
),
Child(
name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
isOptional: true
kind: .token(choices: [.token(tokenKind: "ColonToken")])
),
Child(
name: "Type",
kind: .node(kind: "Type"),
nameForDiagnostics: "type",
isOptional: true
Comment on lines -736 to -737
Copy link
Contributor

Choose a reason for hiding this comment

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

🥳

nameForDiagnostics: "type"
),
Child(
name: "Ellipsis",
Expand Down
97 changes: 96 additions & 1 deletion CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,101 @@ public let EXPR_NODES: [Node] = [
]
),

Node(
name: "ClosureParameter",
nameForDiagnostics: "parameter",
kind: "Syntax",
traits: [
"WithTrailingComma"
],
parserFunction: "parseClosureParameter",
children: [
Child(
name: "Attributes",
kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"),
nameForDiagnostics: "attributes",
isOptional: true
),
Child(
name: "Modifiers",
kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"),
nameForDiagnostics: "modifiers",
isOptional: true
),
Child(
name: "FirstName",
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
description: "The label of this parameter that will be used when the closure is called."
),
Child(
name: "SecondName",
kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]),
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.",
isOptional: true
),
Child(
name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
description: "The colon separating the parameter's name and type.",
isOptional: true
),
Child(
name: "Type",
kind: .node(kind: "Type"),
nameForDiagnostics: "type",
description: "The type of the parameter.",
isOptional: true
),
Child(
name: "Ellipsis",
kind: .token(choices: [.token(tokenKind: "EllipsisToken")]),
description: "If the parameter is variadic, `...` to indicate that.",
isOptional: true
),
Child(
name: "TrailingComma",
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
description: "If the parameter is followed by another parameter, the comma separating them.",
isOptional: true
),
]
),

Node(
name: "ClosureParameterList",
nameForDiagnostics: "parameter list",
kind: "SyntaxCollection",
element: "ClosureParameter"
),

Node(
name: "ClosureParameterClause",
nameForDiagnostics: "parameter clause",
kind: "Syntax",
traits: [
"Parenthesized"
],
children: [
Child(
name: "LeftParen",
kind: .token(choices: [.token(tokenKind: "LeftParenToken")]),
description: "The '(' to open the parameter clause."
),
Child(
name: "ParameterList",
kind: .collection(kind: "ClosureParameterList", collectionElementName: "Parameter"),
nameForDiagnostics: "parameters",
description: "The actual parameters.",
isIndented: true
),
Child(
name: "RightParen",
kind: .token(choices: [.token(tokenKind: "RightParenToken")]),
description: "The ')' to close the parameter clause."
),
]
),

Node(
name: "ClosureExpr",
nameForDiagnostics: "closure",
Expand Down Expand Up @@ -389,7 +484,7 @@ public let EXPR_NODES: [Node] = [
),
Child(
name: "Input",
kind: .node(kind: "ParameterClause")
kind: .node(kind: "ClosureParameterClause")
),
]),
isOptional: true
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftBasicFormat/generated/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ open class BasicFormat: SyntaxRewriter {
return true
case \ClosureExprSyntax.statements:
return true
case \ClosureParameterClauseSyntax.parameterList:
return true
case \CodeBlockSyntax.statements:
return true
case \DictionaryElementSyntax.valueExpression:
return true
case \DictionaryExprSyntax.content:
return true
case \EnumCaseParameterClauseSyntax.parameterList:
return true
case \FunctionCallExprSyntax.argumentList:
return true
case \FunctionTypeSyntax.arguments:
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ add_swift_host_library(SwiftParser
Modifiers.swift
Names.swift
Nominals.swift
Parameters.swift
Parser.swift
Patterns.swift
TokenSpec.swift
Expand Down
Loading