Skip to content

Make the first character of both name and deprecatedName in every Child lowercase #2055

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 2 commits into from
Aug 15, 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
250 changes: 125 additions & 125 deletions CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,30 @@ public let AVAILABILITY_NODES: [Node] = [
traits: ["WithTrailingComma"],
children: [
Child(
name: "Argument",
deprecatedName: "Entry",
name: "argument",
deprecatedName: "entry",
kind: .nodeChoices(choices: [
Child(
name: "Token",
name: "token",
kind: .token(
choices: [.token(.binaryOperator), .token(.identifier)],
requiresLeadingSpace: false,
requiresTrailingSpace: false
)
),
Child(
name: "AvailabilityVersionRestriction",
name: "availabilityVersionRestriction",
kind: .node(kind: .platformVersion)
),
Child(
name: "AvailabilityLabeledArgument",
name: "availabilityLabeledArgument",
kind: .node(kind: .availabilityLabeledArgument)
),
]),
documentation: "The actual argument"
),
Child(
name: "TrailingComma",
name: "trailingComma",
kind: .token(choices: [.token(.comma)]),
documentation: "A trailing comma if the argument is followed by another argument",
isOptional: true
Expand All @@ -64,7 +64,7 @@ public let AVAILABILITY_NODES: [Node] = [
documentation: "An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
children: [
Child(
name: "Label",
name: "label",
kind: .token(choices: [
.keyword(text: "message"),
.keyword(text: "renamed"),
Expand All @@ -76,19 +76,19 @@ public let AVAILABILITY_NODES: [Node] = [
documentation: "The label of the argument"
),
Child(
name: "Colon",
name: "colon",
kind: .token(choices: [.token(.colon)]),
documentation: "The colon separating label and value"
),
Child(
name: "Value",
name: "value",
kind: .nodeChoices(choices: [
Child(
name: "String",
name: "string",
kind: .node(kind: .simpleStringLiteralExpr)
),
Child(
name: "Version",
name: "version",
kind: .node(kind: .versionTuple)
),
]),
Expand All @@ -115,14 +115,14 @@ public let AVAILABILITY_NODES: [Node] = [
documentation: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
children: [
Child(
name: "Platform",
name: "platform",
kind: .token(choices: [.token(.identifier)]),
nameForDiagnostics: "platform",
documentation:
"The name of the OS on which the availability should be restricted or 'swift' if the availability should be restricted based on a Swift version."
),
Child(
name: "Version",
name: "version",
kind: .node(kind: .versionTuple),
nameForDiagnostics: "version",
documentation: """
Expand All @@ -145,12 +145,12 @@ public let AVAILABILITY_NODES: [Node] = [
documentation: "An element to represent a single component in a version, like `.1`.",
children: [
Child(
name: "Period",
name: "period",
kind: .token(choices: [.token(.period)]),
documentation: "The period of this version component"
),
Child(
name: "Number",
name: "number",
kind: .token(choices: [.token(.integerLiteral)]),
documentation: "The version number of this component"
),
Expand All @@ -173,12 +173,12 @@ public let AVAILABILITY_NODES: [Node] = [
documentation: "A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
children: [
Child(
name: "Major",
name: "major",
kind: .token(choices: [.token(.integerLiteral)]),
documentation: "The major version."
),
Child(
name: "Components",
name: "components",
kind: .collection(kind: .versionComponentList, collectionElementName: "VersionComponent"),
documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`"
),
Expand Down
4 changes: 2 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public class Child {
documentation: String? = nil,
isOptional: Bool = false
) {
precondition(name.first?.isUppercase ?? true, "The first letter of a child’s name should be uppercase")
precondition(deprecatedName?.first?.isUppercase ?? true, "The first letter of a child’s name should be uppercase")
precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also precondition that deprecatedName starts with a lowercase letter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you, but before selecting the exact implementation, I would like to discuss the best option. This is why I've added this comment:

I'm uncertain about the optimal way to handle this edge case.

If we want to make deprecatedName lowercase as well, I'm not sure there's a better solution than simply hardcoding the condition if deprecatedName == "eofToken" { ... somewhere 😕

Sorry if it wasn't understandable in the first place.

So, we are dealing with an edge case where deprecatedName is set to "EOFToken", and I'm wondering what would be the best approach to address this situation. The best solution that comes to my mind is hardcoding the condition if deprecatedName == "eofToken" { ... somewhere... :/

precondition(deprecatedName?.first?.isLowercase ?? true, "The first letter of a child’s deprecatedName should be lowercase")
self.name = name
self.deprecatedName = deprecatedName
self.kind = kind
Expand Down
46 changes: 23 additions & 23 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public let COMMON_NODES: [Node] = [
parserFunction: "parseNonOptionalCodeBlockItem",
children: [
Child(
name: "Item",
name: "item",
kind: .nodeChoices(choices: [
Child(
name: "Decl",
name: "decl",
kind: .node(kind: .decl)
),
Child(
name: "Stmt",
name: "stmt",
kind: .node(kind: .stmt)
),
Child(
name: "Expr",
name: "expr",
kind: .node(kind: .expr)
),
]),
documentation: "The underlying node inside the code block."
),
Child(
name: "Semicolon",
name: "semicolon",
kind: .token(choices: [.token(.semicolon)]),
documentation: "If present, the trailing semicolon at the end of the item.",
isOptional: true
Expand All @@ -65,16 +65,16 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "LeftBrace",
name: "leftBrace",
kind: .token(choices: [.token(.leftBrace)])
),
Child(
name: "Statements",
name: "statements",
kind: .collection(kind: .codeBlockItemList, collectionElementName: "Statement"),
nameForDiagnostics: "statements"
),
Child(
name: "RightBrace",
name: "rightBrace",
kind: .token(choices: [.token(.rightBrace)])
),
]
Expand All @@ -90,12 +90,12 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "AsyncSpecifier",
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
isOptional: true
),
Child(
name: "ThrowsSpecifier",
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws")]),
isOptional: true
),
Expand All @@ -112,12 +112,12 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "AsyncSpecifier",
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async"), .keyword(text: "reasync")]),
isOptional: true
),
Child(
name: "ThrowsSpecifier",
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws"), .keyword(text: "rethrows")]),
isOptional: true
),
Expand All @@ -132,7 +132,7 @@ public let COMMON_NODES: [Node] = [
traits: [],
children: [
Child(
name: "AsyncSpecifier",
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
isOptional: true
)
Expand Down Expand Up @@ -165,17 +165,17 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Attributes",
name: "attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
),
Child(
name: "Modifiers",
name: "modifiers",
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
documentation: "If there were standalone modifiers without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
),
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#decl#>`, that can be inserted into the source code to represent the missing declaration.
Expand All @@ -196,7 +196,7 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#expression#>`, that can be inserted into the source code to represent the missing expression.
Expand All @@ -217,7 +217,7 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#pattern#>`, that can be inserted into the source code to represent the missing pattern.
Expand All @@ -238,7 +238,7 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#statement#>`, that can be inserted into the source code to represent the missing pattern.
Expand All @@ -259,7 +259,7 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#syntax#>`, that can be inserted into the source code to represent the missing pattern.
Expand All @@ -280,7 +280,7 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "Placeholder",
name: "placeholder",
kind: .token(choices: [.token(.identifier)], requiresLeadingSpace: false, requiresTrailingSpace: false),
documentation: """
A placeholder, i.e. `<#type#>`, that can be inserted into the source code to represent the missing type.
Expand Down Expand Up @@ -315,12 +315,12 @@ public let COMMON_NODES: [Node] = [
],
children: [
Child(
name: "AsyncSpecifier",
name: "asyncSpecifier",
kind: .token(choices: [.keyword(text: "async")]),
isOptional: true
),
Child(
name: "ThrowsSpecifier",
name: "throwsSpecifier",
kind: .token(choices: [.keyword(text: "throws")]),
isOptional: true
),
Expand Down
Loading