diff --git a/CodeGeneration/Package.swift b/CodeGeneration/Package.swift index 596db48791b..66d910715be 100644 --- a/CodeGeneration/Package.swift +++ b/CodeGeneration/Package.swift @@ -26,25 +26,7 @@ let package = Package( ] ), .target( - name: "SyntaxSupport", - exclude: [ - "gyb_helpers", - "AttributeNodes.swift.gyb", - "AvailabilityNodes.swift.gyb", - "BuilderInitializableTypes.swift.gyb", - "Classification.swift.gyb", - "CommonNodes.swift.gyb", - "DeclNodes.swift.gyb", - "ExprNodes.swift.gyb", - "GenericNodes.swift.gyb", - "PatternNodes.swift.gyb", - "StmtNodes.swift.gyb", - "SyntaxBaseKinds.swift.gyb", - "TokenSpec.swift.gyb", - "Traits.swift.gyb", - "Trivia.swift.gyb", - "TypeNodes.swift.gyb", - ] + name: "SyntaxSupport" ), .target( name: "Utils", diff --git a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift new file mode 100644 index 00000000000..42a49f9f03f --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift @@ -0,0 +1,892 @@ +//// Automatically Generated From AttributeNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let ATTRIBUTE_NODES: [Node] = [ + // attribute-list -> attribute attribute-list? + Node( + name: "AttributeList", + nameForDiagnostics: "attributes", + kind: "SyntaxCollection", + element: "Syntax", + elementName: "Attribute", + elementChoices: ["Attribute", "IfConfigDecl"], + omitWhenEmpty: true + ), + + // attribute -> '@' identifier '('? + // ( identifier + // | string-literal + // | integer-literal + // | availability-spec-list + // | specialize-attr-spec-list + // | implements-attr-arguments + // | named-attribute-string-argument + // | back-deploy-attr-spec-list + // )? ')'? + Node( + name: "Attribute", + nameForDiagnostics: "attribute", + description: "An `@` attribute.", + kind: "Syntax", + parserFunction: "parseAttribute", + children: [ + Child( + name: "AtSignToken", + kind: .token(choices: [.token(tokenKind: "AtSignToken")]), + description: "The `@` sign." + ), + Child( + name: "AttributeName", + kind: .node(kind: "Type"), + nameForDiagnostics: "name", + description: "The name of the attribute.", + classification: "Attribute" + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + description: "If the attribute takes arguments, the opening parenthesis.", + isOptional: true + ), + Child( + name: "Argument", + kind: .nodeChoices(choices: [ + Child( + name: "ArgumentList", + kind: .node(kind: "TupleExprElementList") + ), + Child( + name: "Token", + kind: .node(kind: "Token") + ), + Child( + name: "String", + kind: .node(kind: "StringLiteralExpr") + ), + Child( + name: "Availability", + kind: .node(kind: "AvailabilitySpecList") + ), + Child( + name: "SpecializeArguments", + kind: .node(kind: "SpecializeAttributeSpecList") + ), + Child( + name: "ObjCName", + kind: .node(kind: "ObjCSelector") + ), + Child( + name: "ImplementsArguments", + kind: .node(kind: "ImplementsAttributeArguments") + ), + Child( + name: "DifferentiableArguments", + kind: .node(kind: "DifferentiableAttributeArguments") + ), + Child( + name: "DerivativeRegistrationArguments", + kind: .node(kind: "DerivativeRegistrationAttributeArguments") + ), + Child( + name: "BackDeployedArguments", + kind: .node(kind: "BackDeployedAttributeSpecList") + ), + Child( + name: "ConventionArguments", + kind: .node(kind: "ConventionAttributeArguments") + ), + Child( + name: "ConventionWitnessMethodArguments", + kind: .node(kind: "ConventionWitnessMethodAttributeArguments") + ), + Child( + name: "OpaqueReturnTypeOfAttributeArguments", + kind: .node(kind: "OpaqueReturnTypeOfAttributeArguments") + ), + Child( + name: "ExposeAttributeArguments", + kind: .node(kind: "ExposeAttributeArguments") + ), + Child( + name: "OriginallyDefinedInArguments", + kind: .node(kind: "OriginallyDefinedInArguments") + ), + Child( + name: "UnderscorePrivateAttributeArguments", + kind: .node(kind: "UnderscorePrivateAttributeArguments") + ), + Child( + name: "DynamicReplacementArguments", + kind: .node(kind: "DynamicReplacementArguments") + ), + Child( + name: "UnavailableFromAsyncArguments", + kind: .node(kind: "UnavailableFromAsyncArguments") + ), + Child( + name: "EffectsArguments", + kind: .node(kind: "EffectsArguments") + ), + Child( + name: "DocumentationArguments", + kind: .node(kind: "DocumentationAttributeArguments") + ), + ]), + description: "The arguments of the attribute. In case the attribute takes multiple arguments, they are gather in the appropriate takes first.", + isOptional: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + description: "If the attribute takes arguments, the closing parenthesis.", + isOptional: true + ), + ] + ), + + Node( + name: "AvailabilityEntry", + nameForDiagnostics: "availability entry", + description: "The availability argument for the _specialize attribute", + kind: "Syntax", + children: [ + Child( + name: "Label", + kind: .token(choices: [.keyword(text: "availability")]), + nameForDiagnostics: "label", + description: "The label of the argument" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating the label and the value" + ), + Child( + name: "AvailabilityList", + kind: .collection(kind: "AvailabilitySpecList", collectionElementName: "Availability") + ), + Child( + name: "Semicolon", + kind: .token(choices: [.token(tokenKind: "SemicolonToken")]) + ), + ] + ), + + // back-deploy-version-entry -> availability-version-restriction ','? + Node( + name: "AvailabilityVersionRestrictionListEntry", + nameForDiagnostics: "version", + description: "A single platform/version pair in an attribute, e.g. `iOS 10.1`.", + kind: "Syntax", + children: [ + Child( + name: "AvailabilityVersionRestriction", + kind: .node(kind: "AvailabilityVersionRestriction"), + classification: "Keyword" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "A trailing comma if the argument is followed by another argument", + isOptional: true + ), + ] + ), + + // back-deploy-version-list -> + // back-deploy-version-entry back-deploy-version-list? + Node( + name: "AvailabilityVersionRestrictionList", + nameForDiagnostics: "version list", + kind: "SyntaxCollection", + element: "AvailabilityVersionRestrictionListEntry" + ), + + // The arguments of '@backDeployed(...)' + // back-deployed-attr-spec-list -> 'before' ':' back-deployed-version-list + Node( + name: "BackDeployedAttributeSpecList", + nameForDiagnostics: "'@backDeployed' arguments", + description: "A collection of arguments for the `@backDeployed` attribute", + kind: "Syntax", + children: [ + Child( + name: "BeforeLabel", + kind: .token(choices: [.keyword(text: "before")]), + description: "The \"before\" label." + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating \"before\" and the parameter list." + ), + Child( + name: "VersionList", + kind: .collection(kind: "AvailabilityVersionRestrictionList", collectionElementName: "Availability"), + description: "The list of OS versions in which the declaration became ABI stable." + ), + ] + ), + + // convention-attribute-arguments -> token ',' 'cType'? ':' string-literal + Node( + name: "ConventionAttributeArguments", + nameForDiagnostics: "@convention(...) arguments", + description: "The arguments for the '@convention(...)'.", + kind: "Syntax", + children: [ + Child( + name: "ConventionLabel", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + description: "The convention label." + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + Child( + name: "CTypeLabel", + kind: .token(choices: [.keyword(text: "cType")]), + isOptional: true + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "CTypeString", + kind: .node(kind: "StringLiteralExpr"), + isOptional: true + ), + ] + ), + + // convention-attribute-arguments -> 'witness_method' ':' identifier + Node( + name: "ConventionWitnessMethodAttributeArguments", + nameForDiagnostics: "@convention(...) arguments for witness methods", + description: "The arguments for the '@convention(witness_method: ...)'.", + kind: "Syntax", + children: [ + Child( + name: "WitnessMethodLabel", + kind: .token(choices: [.keyword(text: "witness_method")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "ProtocolName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + ] + ), + + Node( + name: "DeclName", + nameForDiagnostics: "declaration name", + kind: "Syntax", + children: [ + Child( + name: "DeclBaseName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "PrefixOperatorToken"), .keyword(text: "init")]), + nameForDiagnostics: "base name", + description: "The base name of the protocol's requirement." + ), + Child( + name: "DeclNameArguments", + kind: .node(kind: "DeclNameArguments"), + nameForDiagnostics: "arguments", + description: "The argument labels of the protocol's requirement if it is a function requirement.", + isOptional: true + ), + ] + ), + + // The argument of the derivative registration attribute + // '@derivative(of: ...)' and the transpose registration attribute + // '@transpose(of: ...)'. + // + // derivative-registration-attr-arguments -> + // 'of' ':' func-decl-name ','? differentiability-params-clause? + Node( + name: "DerivativeRegistrationAttributeArguments", + nameForDiagnostics: "attribute arguments", + description: "The arguments for the '@derivative(of:)' and '@transpose(of:)' attributes: the 'of:' label, the original declaration name, and an optional differentiability parameter list.", + kind: "Syntax", + children: [ + Child( + name: "OfLabel", + kind: .token(choices: [.keyword(text: "of")]), + description: "The \"of\" label." + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating the \"of\" label and the original declaration name." + ), + Child( + name: "OriginalDeclName", + kind: .node(kind: "QualifiedDeclName"), + description: "The referenced original declaration name." + ), + Child( + name: "Period", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]), + description: "The period separating the original declaration name and the accessor name.", + isOptional: true + ), + Child( + name: "AccessorKind", + kind: .token(choices: [.keyword(text: "get"), .keyword(text: "set")]), + description: "The accessor name.", + isOptional: true + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + Child( + name: "DiffParams", + kind: .node(kind: "DifferentiabilityParamsClause"), + isOptional: true + ), + ] + ), + + // differentiability-param-list -> + // differentiability-param differentiability-param-list? + Node( + name: "DifferentiabilityParamList", + nameForDiagnostics: "differentiability parameters", + kind: "SyntaxCollection", + element: "DifferentiabilityParam" + ), + + // differentiability-param -> ('self' | identifier | integer-literal) ','? + Node( + name: "DifferentiabilityParam", + nameForDiagnostics: "differentiability parameter", + description: "A differentiability parameter: either the \"self\" identifier, a function parameter name, or a function parameter index.", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Parameter", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "IntegerLiteralToken"), .token(tokenKind: "KeywordToken")]) + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // differentiability-params-clause -> + // 'wrt' ':' (differentiability-param | differentiability-params) + Node( + name: "DifferentiabilityParamsClause", + nameForDiagnostics: "'@differentiable' argument", + description: "A clause containing differentiability parameters.", + kind: "Syntax", + children: [ + Child( + name: "WrtLabel", + kind: .token(choices: [.keyword(text: "wrt")]), + description: "The \"wrt\" label." + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating \"wrt\" and the parameter list." + ), + Child( + name: "Parameters", + kind: .nodeChoices(choices: [ + Child( + name: "Parameter", + kind: .node(kind: "DifferentiabilityParam") + ), + Child( + name: "ParameterList", + kind: .node(kind: "DifferentiabilityParams") + ), + ]), + nameForDiagnostics: "parameters" + ), + ] + ), + + // differentiability-params -> '(' differentiability-param-list ')' + Node( + name: "DifferentiabilityParams", + nameForDiagnostics: "differentiability parameters", + description: "The differentiability parameters.", + kind: "Syntax", + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "DiffParams", + kind: .collection(kind: "DifferentiabilityParamList", collectionElementName: "DifferentiabilityParam"), + description: "The parameters for differentiation." + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // The argument of '@differentiable(...)'. + // differentiable-attr-arguments -> + // differentiability-kind? '.'? differentiability-params-clause? ','? + // generic-where-clause? + Node( + name: "DifferentiableAttributeArguments", + nameForDiagnostics: "'@differentiable' arguments", + description: "The arguments for the `@differentiable` attribute: an optional differentiability kind, an optional differentiability parameter clause, and an optional 'where' clause.", + kind: "Syntax", + children: [ + Child( + name: "DiffKind", + kind: .token(choices: [.keyword(text: "forward"), .keyword(text: "reverse"), .keyword(text: "linear")]), + isOptional: true + ), + Child( + name: "DiffKindComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "The comma following the differentiability kind, if it exists.", + isOptional: true + ), + Child( + name: "DiffParams", + kind: .node(kind: "DifferentiabilityParamsClause"), + isOptional: true + ), + Child( + name: "DiffParamsComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "The comma following the differentiability parameters clause, if it exists.", + isOptional: true + ), + Child( + name: "WhereClause", + kind: .node(kind: "GenericWhereClause"), + isOptional: true + ), + ] + ), + + Node( + name: "DocumentationAttributeArgument", + nameForDiagnostics: "@_documentation argument", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Label", + kind: .token(choices: [.keyword(text: "visibility"), .keyword(text: "metadata")]), + nameForDiagnostics: "label" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Value", + kind: .nodeChoices(choices: [ + Child( + name: "Token", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")]) + ), // Keywords can be: public, internal, private, fileprivate, open + Child( + name: "String", + kind: .node(kind: "StringLiteralExpr") + ), + ]) + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "A trailing comma if this argument is followed by another one", + isOptional: true + ), + ] + ), + + Node( + name: "DocumentationAttributeArguments", + nameForDiagnostics: "@_documentation arguments", + description: "The arguments of the '@_documentation' attribute", + kind: "SyntaxCollection", + element: "DocumentationAttributeArgument" + ), + + Node( + name: "DynamicReplacementArguments", + nameForDiagnostics: "@_dynamicReplacement argument", + description: "The arguments for the '@_dynamicReplacement' attribute", + kind: "Syntax", + children: [ + Child( + name: "ForLabel", + kind: .token(choices: [.keyword(text: "for")], requiresTrailingSpace: false) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Declname", + kind: .node(kind: "DeclName") + ), + ] + ), + + Node( + name: "EffectsArguments", + nameForDiagnostics: "@_effects arguments", + description: "The arguments of the '@_effect' attribute. These will be parsed during the SIL stage.", + kind: "SyntaxCollection", + element: "Token" + ), + + Node( + name: "ExposeAttributeArguments", + nameForDiagnostics: "@_expose arguments", + description: "The arguments for the '@_expose' attribute", + kind: "Syntax", + children: [ + Child( + name: "Language", + kind: .node(kind: "Token") + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + Child( + name: "CxxName", + kind: .node(kind: "StringLiteralExpr"), + isOptional: true + ), + ] + ), + + // The argument of '@_implements(...)' + // implements-attr-arguments -> simple-type-identifier ',' + // (identifier | operator) decl-name-arguments + Node( + name: "ImplementsAttributeArguments", + nameForDiagnostics: "@_implements arguemnts", + description: "The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`", + kind: "Syntax", + children: [ + Child( + name: "Type", + kind: .node(kind: "Type"), + nameForDiagnostics: "type", + description: "The type for which the method with this attribute implements a requirement." + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "The comma separating the type and method name" + ), + Child( + name: "DeclBaseName", + kind: .node(kind: "Token"), + nameForDiagnostics: "declaration base name", + description: "The base name of the protocol's requirement." + ), + Child( + name: "DeclNameArguments", + kind: .node(kind: "DeclNameArguments"), + nameForDiagnostics: "declaration name arguments", + description: "The argument labels of the protocol's requirement if it is a function requirement.", + isOptional: true + ), + ] + ), + + // Representation of e.g. 'exported: true,' + // labeled-specialize-entry -> identifier ':' token ','? + Node( + name: "LabeledSpecializeEntry", + nameForDiagnostics: "attribute argument", + description: "A labeled argument for the `@_specialize` attribute like `exported: true`", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Label", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .keyword(text: "available"), .keyword(text: "exported"), .keyword(text: "kind"), .keyword(text: "spi"), .keyword(text: "spiModule")]), + nameForDiagnostics: "label", + description: "The label of the argument" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating the label and the value" + ), + Child( + name: "Value", + kind: .node(kind: "Token"), + nameForDiagnostics: "value", + description: "The value for this argument" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "A trailing comma if this argument is followed by another one", + isOptional: true + ), + ] + ), + + // objc-selector-piece -> identifier? ':'? + Node( + name: "ObjCSelectorPiece", + nameForDiagnostics: "Objective-C selector piece", + description: "A piece of an Objective-C selector. Either consisting of just an identifier for a nullary selector, an identifier and a colon for a labeled argument or just a colon for an unlabeled argument", + kind: "Syntax", + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name", + isOptional: true + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + ] + ), + + // objc-selector -> objc-selector-piece objc-selector? + Node( + name: "ObjCSelector", + nameForDiagnostics: "Objective-C selector", + kind: "SyntaxCollection", + element: "ObjCSelectorPiece" + ), + + // opaque-return-type-of-arguments -> string-literal ',' integer-literal + Node( + name: "OpaqueReturnTypeOfAttributeArguments", + nameForDiagnostics: "opaque return type arguments", + description: "The arguments for the '@_opaqueReturnTypeOf()'.", + kind: "Syntax", + children: [ + Child( + name: "MangledName", + kind: .node(kind: "StringLiteralExpr"), + description: "The mangled name of a declaration." + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]) + ), + Child( + name: "Ordinal", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), + description: "The ordinal corresponding to the 'some' keyword that introduced this opaque type." + ), + ] + ), + + Node( + name: "OriginallyDefinedInArguments", + nameForDiagnostics: "@_originallyDefinedIn arguments", + description: "The arguments for the '@_originallyDefinedIn' attribute", + kind: "Syntax", + children: [ + Child( + name: "ModuleLabel", + kind: .token(choices: [.keyword(text: "module")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "ModuleName", + kind: .node(kind: "StringLiteralExpr") + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]) + ), + Child( + name: "Platforms", + kind: .collection(kind: "AvailabilityVersionRestrictionList", collectionElementName: "Platform") + ), + ] + ), + + // An optionally qualified declaration name. + // Currently used only for `@derivative` and `@transpose` attribute. + // TODO(TF-1066): Use module qualified name syntax/parsing instead of custom + // qualified name syntax/parsing. + // + // qualified-decl-name -> + // base-type? '.'? (identifier | operator) decl-name-arguments? + // base-type -> + // member-type-identifier | base-type-identifier + Node( + name: "QualifiedDeclName", + nameForDiagnostics: "declaration name", + description: "An optionally qualified function declaration name (e.g. `+(_:_:)`, `A.B.C.foo(_:_:)`).", + kind: "Syntax", + children: [ + Child( + name: "BaseType", + kind: .node(kind: "Type"), + nameForDiagnostics: "base type", + description: "The base type of the qualified name, optionally specified.", + isOptional: true + ), + Child( + name: "Dot", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]), + isOptional: true + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]), + nameForDiagnostics: "base name", + description: "The base name of the referenced function." + ), + Child( + name: "Arguments", + kind: .node(kind: "DeclNameArguments"), + nameForDiagnostics: "arguments", + description: "The argument labels of the referenced function, optionally specified.", + isOptional: true + ), + ] + ), + + // The argument of '@_specialize(...)' + // specialize-attr-spec-list -> labeled-specialize-entry + // specialize-spec-attr-list? + // | generic-where-clause + // specialize-spec-attr-list? + Node( + name: "SpecializeAttributeSpecList", + nameForDiagnostics: "argument to '@_specialize", + description: "A collection of arguments for the `@_specialize` attribute", + kind: "SyntaxCollection", + element: "Syntax", + elementName: "SpecializeAttribute", + elementChoices: ["LabeledSpecializeEntry", "AvailabilityEntry", "TargetFunctionEntry", "GenericWhereClause"] + ), + + // Representation of e.g. 'exported: true,' + // labeled-specialize-entry -> identifier ':' token ','? + Node( + name: "TargetFunctionEntry", + nameForDiagnostics: "attribute argument", + description: "A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Label", + kind: .token(choices: [.keyword(text: "target")]), + nameForDiagnostics: "label", + description: "The label of the argument" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating the label and the value" + ), + Child( + name: "Declname", + kind: .node(kind: "DeclName"), + nameForDiagnostics: "declaration name", + description: "The value for this argument" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "A trailing comma if this argument is followed by another one", + isOptional: true + ), + ] + ), + + Node( + name: "UnavailableFromAsyncArguments", + nameForDiagnostics: "@_unavailableFromAsync argument", + description: "The arguments for the '@_unavailableFromAsync' attribute", + kind: "Syntax", + children: [ + Child( + name: "MessageLabel", + kind: .token(choices: [.keyword(text: "message")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Message", + kind: .node(kind: "StringLiteralExpr") + ), + ] + ), + + Node( + name: "UnderscorePrivateAttributeArguments", + nameForDiagnostics: "@_private argument", + description: "The arguments for the '@_private' attribute", + kind: "Syntax", + children: [ + Child( + name: "SourceFileLabel", + kind: .token(choices: [.keyword(text: "sourceFile")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Filename", + kind: .node(kind: "StringLiteralExpr") + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift.gyb deleted file mode 100644 index 627fb246319..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From AttributeNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let ATTRIBUTE_NODES: [Node] = [ -% for node in sorted(ATTRIBUTE_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift new file mode 100644 index 00000000000..43bea690b9a --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift @@ -0,0 +1,152 @@ +//// Automatically Generated From AvailabilityNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let AVAILABILITY_NODES: [Node] = [ + // Wrapper for all the different entries that may occur inside @available + // availability-entry -> '*' ','? + // | identifier ','? + // | availability-version-restriction ','? + // | availability-versioned-argument ','? + Node( + name: "AvailabilityArgument", + nameForDiagnostics: "availability argument", + description: "A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.", + kind: "Syntax", + children: [ + Child( + name: "Entry", + kind: .nodeChoices(choices: [ + Child( + name: "Token", + kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "IdentifierToken")], requiresLeadingSpace: false, requiresTrailingSpace: false) + ), + Child( + name: "AvailabilityVersionRestriction", + kind: .node(kind: "AvailabilityVersionRestriction") + ), + Child( + name: "AvailabilityLabeledArgument", + kind: .node(kind: "AvailabilityLabeledArgument") + ), + ]), + description: "The actual argument" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "A trailing comma if the argument is followed by another argument", + isOptional: true + ), + ] + ), + + // Representation of 'deprecated: 2.3', 'message: "Hello world"' etc. + // availability-versioned-argument -> identifier ':' version-tuple + Node( + name: "AvailabilityLabeledArgument", + nameForDiagnostics: "availability argument", + description: "A argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.", + kind: "Syntax", + children: [ + Child( + name: "Label", + kind: .token(choices: [.keyword(text: "message"), .keyword(text: "renamed"), .keyword(text: "introduced"), .keyword(text: "obsoleted"), .keyword(text: "deprecated")]), + nameForDiagnostics: "label", + description: "The label of the argument" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + description: "The colon separating label and value" + ), + Child( + name: "Value", + kind: .nodeChoices(choices: [ + Child( + name: "String", + kind: .node(kind: "StringLiteralExpr") + ), + Child( + name: "Version", + kind: .node(kind: "VersionTuple") + ), + ]), + nameForDiagnostics: "value", + description: "The value of this labeled argument" + ), + ] + ), + + // availability-spec-list -> availability-entry availability-spec-list? + Node( + name: "AvailabilitySpecList", + nameForDiagnostics: "'@availability' arguments", + kind: "SyntaxCollection", + element: "AvailabilityArgument" + ), + + // Representation for 'iOS 10', 'swift 3.4' etc. + // availability-version-restriction -> identifier version-tuple + Node( + name: "AvailabilityVersionRestriction", + nameForDiagnostics: "version restriction", + description: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.", + kind: "Syntax", + children: [ + Child( + name: "Platform", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "platform", + description: "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.", + classification: "Keyword" + ), + Child( + name: "Version", + kind: .node(kind: "VersionTuple"), + nameForDiagnostics: "version", + isOptional: true + ), + ] + ), + + // version-tuple -> integer-literal + // | float-literal + // | float-literal '.' integer-literal + Node( + name: "VersionTuple", + nameForDiagnostics: "version tuple", + description: "A version number of the form major.minor.patch in which the minor and patch part may be omitted.", + kind: "Syntax", + children: [ + Child( + name: "MajorMinor", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken"), .token(tokenKind: "FloatingLiteralToken")]), + description: "In case the version consists only of the major version, an integer literal that specifies the major version. In case the version consists of major and minor version number, a floating literal in which the decimal part is interpreted as the minor version." + ), + Child( + name: "PatchPeriod", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]), + description: "If the version contains a patch number, the period separating the minor from the patch number.", + isOptional: true + ), + Child( + name: "PatchVersion", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), + description: "The patch version if specified.", + isOptional: true + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift.gyb deleted file mode 100644 index 774f02a2706..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From AvailabilityNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let AVAILABILITY_NODES: [Node] = [ -% for node in sorted(AVAILABILITY_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/BuilderInitializableTypes.swift b/CodeGeneration/Sources/SyntaxSupport/BuilderInitializableTypes.swift similarity index 100% rename from CodeGeneration/Sources/SyntaxSupport/gyb_generated/BuilderInitializableTypes.swift rename to CodeGeneration/Sources/SyntaxSupport/BuilderInitializableTypes.swift diff --git a/CodeGeneration/Sources/SyntaxSupport/BuilderInitializableTypes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/BuilderInitializableTypes.swift.gyb deleted file mode 100644 index 8991ca402bb..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/BuilderInitializableTypes.swift.gyb +++ /dev/null @@ -1,25 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import BUILDER_INITIALIZABLE_TYPES - # -*- mode: Swift -*- - # Ignore the following admonition; it applies to the resulting .swift file only -}% -//// Automatically Generated From BuilderInitializableTypes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let BUILDER_INITIALIZABLE_TYPES: [String: String?] = [ -% for type, resolved_type in BUILDER_INITIALIZABLE_TYPES.items(): - "${type}": ${'"' + resolved_type + '"' if resolved_type is not None else 'nil'}, -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Classification.swift b/CodeGeneration/Sources/SyntaxSupport/Classification.swift similarity index 99% rename from CodeGeneration/Sources/SyntaxSupport/gyb_generated/Classification.swift rename to CodeGeneration/Sources/SyntaxSupport/Classification.swift index 24268631e4b..b71e1242758 100644 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Classification.swift +++ b/CodeGeneration/Sources/SyntaxSupport/Classification.swift @@ -43,7 +43,6 @@ public class ChildClassification { } } - public let SYNTAX_CLASSIFICATIONS: [SyntaxClassification] = [ SyntaxClassification(name: "Attribute", description: "An attribute starting with an `@`."), SyntaxClassification(name: "BlockComment", description: "A block comment starting with `/**` and ending with `*/."), diff --git a/CodeGeneration/Sources/SyntaxSupport/Classification.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/Classification.swift.gyb deleted file mode 100644 index 7fde63ce55e..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/Classification.swift.gyb +++ /dev/null @@ -1,67 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_syntax_support.Token import * - from gyb_syntax_support.kinds import lowercase_first_word - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From Classification.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -/// Represents a classification a token can receive for syntax highlighting. -public class SyntaxClassification { - public let name: String - public let description: String - - public var swiftName: String { - lowercaseFirstWord(name: name) - } - - public init(name: String, description: String) { - self.name = name - self.description = description - } -} - -public class ChildClassification { - public let parent: Node - public let childIndex: Int - public let isToken: Bool - public let classification: SyntaxClassification? - public let force: Bool - - public init(node: Node, childIndex: Int, child: Child) { - self.parent = node - self.childIndex = childIndex - self.isToken = child.syntaxKind.hasSuffix("Token") - self.classification = child.classification - self.force = child.forceClassification - } -} - - -public let SYNTAX_CLASSIFICATIONS: [SyntaxClassification] = [ -% for syntaxClassification in sorted(SYNTAX_CLASSIFICATIONS, key=lambda x: x.name): - SyntaxClassification(name: "${syntaxClassification.name}", description: "${syntaxClassification.description.strip()}"), -% end -] - -func classificationByName(_ name: String?) -> SyntaxClassification? { - guard let name = name else { return nil } - for classification in SYNTAX_CLASSIFICATIONS where classification.name == name { - return classification - } - - fatalError("Unknown syntax classification '\(name)'") -} diff --git a/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift b/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift new file mode 100644 index 00000000000..2287df5fd1b --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift @@ -0,0 +1,226 @@ +//// Automatically Generated From CommonNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let COMMON_NODES: [Node] = [ + // code-block-item-list -> code-block-item code-block-item-list? + Node( + name: "CodeBlockItemList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "CodeBlockItem", + elementsSeparatedByNewline: true + ), + + // code-block-item = (decl | stmt | expr) ';'? + Node( + name: "CodeBlockItem", + nameForDiagnostics: nil, + description: "A CodeBlockItem is any Syntax node that appears on its own line inside a CodeBlock.", + kind: "Syntax", + children: [ + Child( + name: "Item", + kind: .nodeChoices(choices: [ + Child( + name: "Decl", + kind: .node(kind: "Decl") + ), + Child( + name: "Stmt", + kind: .node(kind: "Stmt") + ), + Child( + name: "Expr", + kind: .node(kind: "Expr") + ), + ]), + description: "The underlying node inside the code block." + ), + Child( + name: "Semicolon", + kind: .token(choices: [.token(tokenKind: "SemicolonToken")]), + description: "If present, the trailing semicolon at the end of the item.", + isOptional: true + ), + ], + omitWhenEmpty: true + ), + + // code-block -> '{' stmt-list '}' + Node( + name: "CodeBlock", + nameForDiagnostics: "code block", + kind: "Syntax", + traits: [ + "Braced", + "WithStatements", + ], + children: [ + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "Statements", + kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), + nameForDiagnostics: "statements", + isIndented: true + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), + requiresLeadingNewline: true + ), + ] + ), + + // decl-effect-specifiers -> (async | reasync)? (throws | rethrows)? + Node( + name: "DeclEffectSpecifiers", + nameForDiagnostics: "effect specifiers", + kind: "Syntax", + traits: [ + "EffectSpecifiers" + ], + children: [ + Child( + name: "AsyncSpecifier", + kind: .token(choices: [.keyword(text: "async"), .keyword(text: "reasync")]), + isOptional: true + ), + Child( + name: "ThrowsSpecifier", + kind: .token(choices: [.keyword(text: "throws"), .keyword(text: "rethrows")]), + isOptional: true + ), + ] + ), + + Node( + name: "Decl", + nameForDiagnostics: "declaration", + kind: "Syntax", + parserFunction: "parseDeclaration" + ), + + Node( + name: "Expr", + nameForDiagnostics: "expression", + kind: "Syntax", + parserFunction: "parseExpression" + ), + + Node( + name: "MissingDecl", + nameForDiagnostics: "declaration", + kind: "Decl", + traits: [ + "Attributed" + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + isOptional: true + ), + Child( + name: "Modifiers", + kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), + isOptional: true + ), + ] + ), + + Node( + name: "MissingExpr", + nameForDiagnostics: "expression", + kind: "Expr" + ), + + Node( + name: "MissingPattern", + nameForDiagnostics: "pattern", + kind: "Pattern" + ), + + Node( + name: "MissingStmt", + nameForDiagnostics: "statement", + kind: "Stmt" + ), + + Node( + name: "Missing", + nameForDiagnostics: nil, + kind: "Syntax" + ), + + Node( + name: "MissingType", + nameForDiagnostics: "type", + kind: "Type" + ), + + Node( + name: "Pattern", + nameForDiagnostics: "pattern", + kind: "Syntax", + parserFunction: "parsePattern" + ), + + Node( + name: "Stmt", + nameForDiagnostics: "statement", + kind: "Syntax", + parserFunction: "parseStatement" + ), + + // type-effect-specifiers -> async? throws? + Node( + name: "TypeEffectSpecifiers", + nameForDiagnostics: "effect specifiers", + kind: "Syntax", + traits: [ + "EffectSpecifiers" + ], + children: [ + Child( + name: "AsyncSpecifier", + kind: .token(choices: [.keyword(text: "async")]), + isOptional: true + ), + Child( + name: "ThrowsSpecifier", + kind: .token(choices: [.keyword(text: "throws")]), + isOptional: true + ), + ] + ), + + Node( + name: "Type", + nameForDiagnostics: "type", + kind: "Syntax", + parserFunction: "parseType" + ), + + Node( + name: "UnexpectedNodes", + nameForDiagnostics: nil, + description: "A collection of syntax nodes that occurred in the source code but could not be used to form a valid syntax tree.", + kind: "SyntaxCollection", + element: "Syntax" + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift.gyb deleted file mode 100644 index a9484b33a22..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From CommonNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let COMMON_NODES: [Node] = [ -% for node in sorted(COMMON_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift new file mode 100644 index 00000000000..96d22ab8500 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift @@ -0,0 +1,1913 @@ +//// Automatically Generated From DeclNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let DECL_NODES: [Node] = [ + // FIXME: technically misnamed; should be "ImportPathComponent" + Node( + name: "AccessPathComponent", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "TrailingDot", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]), + isOptional: true + ), + ] + ), + + // FIXME: technically misnamed; should be "ImportPath" + Node( + name: "AccessPath", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "AccessPathComponent" + ), + + Node( + name: "AccessorBlock", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "Braced" + ], + children: [ + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "Accessors", + kind: .collection(kind: "AccessorList", collectionElementName: "Accessor"), + isIndented: true + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), + requiresLeadingNewline: true + ), + ] + ), + + Node( + name: "AccessorDecl", + nameForDiagnostics: "accessor", + kind: "Decl", + traits: [ + "Attributed" + ], + parserFunction: "parseAccessorDecl", + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + isOptional: true + ), + Child( + name: "Modifier", + kind: .node(kind: "DeclModifier"), + nameForDiagnostics: "modifiers", + isOptional: true + ), + Child( + name: "AccessorKind", + kind: .token(choices: [.keyword(text: "get"), .keyword(text: "set"), .keyword(text: "didSet"), .keyword(text: "willSet"), .keyword(text: "unsafeAddress"), .keyword(text: "addressWithOwner"), .keyword(text: "addressWithNativeOwner"), .keyword(text: "unsafeMutableAddress"), .keyword(text: "mutableAddressWithOwner"), .keyword(text: "mutableAddressWithNativeOwner"), .keyword(text: "_read"), .keyword(text: "_modify")]) + ), + Child( + name: "Parameter", + kind: .node(kind: "AccessorParameter"), + nameForDiagnostics: "parameter", + isOptional: true + ), + Child( + name: "EffectSpecifiers", + kind: .node(kind: "DeclEffectSpecifiers"), + isOptional: true + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + isOptional: true + ), + ] + ), + + Node( + name: "AccessorList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "AccessorDecl", + elementsSeparatedByNewline: true + ), + + // (value) + Node( + name: "AccessorParameter", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // actor-declaration -> attributes? access-level-modifier? + // 'actor' actor-name + // generic-parameter-clause? + // type-inheritance-clause? + // generic-where-clause? + // '{' actor-members '}' + // actor-name -> identifier + Node( + name: "ActorDecl", + nameForDiagnostics: "actor", + kind: "Decl", + traits: [ + "DeclGroup", + "IdentifiedDecl", + "Attributed", + ], + 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: "ActorKeyword", + kind: .token(choices: [.keyword(text: "actor")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "type inheritance clause", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock") + ), + ] + ), + + // associatedtype-declaration -> attributes? access-level-modifier? + // 'associatedtype' associatedtype-name + // inheritance-clause? type-assignment? + // generic-where-clause? + // associatedtype-name -> identifier + Node( + name: "AssociatedtypeDecl", + nameForDiagnostics: "associatedtype declaration", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + 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: "AssociatedtypeKeyword", + kind: .token(choices: [.keyword(text: "associatedtype")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "inheritance clause", + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "TypeInitializerClause"), + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + ] + ), + + // class-declaration -> attributes? access-level-modifier? + // 'class' class-name + // generic-parameter-clause? + // type-inheritance-clause? + // generic-where-clause? + // '{' class-members '}' + // class-name -> identifier + Node( + name: "ClassDecl", + nameForDiagnostics: "class", + kind: "Decl", + traits: [ + "DeclGroup", + "IdentifiedDecl", + "Attributed", + ], + 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: "ClassKeyword", + kind: .token(choices: [.keyword(text: "class")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "inheritance clause", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock") + ), + ] + ), + + Node( + name: "DeclModifierDetail", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Detail", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .keyword(text: "set")]) + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + Node( + name: "DeclModifier", + nameForDiagnostics: "modifier", + kind: "Syntax", + children: [ + Child( + name: "Name", + kind: .token(choices: [.keyword(text: "class"), .keyword(text: "convenience"), .keyword(text: "dynamic"), .keyword(text: "final"), .keyword(text: "infix"), .keyword(text: "lazy"), .keyword(text: "optional"), .keyword(text: "override"), .keyword(text: "postfix"), .keyword(text: "prefix"), .keyword(text: "required"), .keyword(text: "static"), .keyword(text: "unowned"), .keyword(text: "weak"), .keyword(text: "private"), .keyword(text: "fileprivate"), .keyword(text: "internal"), .keyword(text: "public"), .keyword(text: "open"), .keyword(text: "mutating"), .keyword(text: "nonmutating"), .keyword(text: "indirect"), .keyword(text: "__consuming"), .keyword(text: "borrowing"), .keyword(text: "consuming"), .keyword(text: "actor"), .keyword(text: "async"), .keyword(text: "distributed"), .keyword(text: "isolated"), .keyword(text: "nonisolated"), .keyword(text: "_const"), .keyword(text: "_local"), .keyword(text: "package")]), + classification: "Attribute" + ), + Child( + name: "Detail", + kind: .node(kind: "DeclModifierDetail"), + isOptional: true + ), + ] + ), + + Node( + name: "DeinitializerDecl", + nameForDiagnostics: "deinitializer", + kind: "Decl", + traits: [ + "Attributed" + ], + 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: "DeinitKeyword", + kind: .token(choices: [.keyword(text: "deinit")]) + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + isOptional: true + ), + ] + ), + + Node( + name: "DesignatedTypeElement", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "LeadingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]) + ), + Child( + name: "Name", + kind: .node(kind: "Token") + ), + ] + ), + + // designated-type-list -> (',' identifier)* + Node( + name: "DesignatedTypeList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "DesignatedTypeElement" + ), + + // <#content#> + Node( + name: "EditorPlaceholderDecl", + nameForDiagnostics: "editor placeholder", + kind: "Decl", + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ) + ] + ), + + Node( + name: "EnumCaseDecl", + nameForDiagnostics: "enum case", + description: "A `case` declaration of a Swift `enum`. It can have 1 or more `EnumCaseElement`s inside, each declaring a different case of the enum.", + kind: "Decl", + traits: [ + "Attributed" + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + description: "The attributes applied to the case declaration.", + isOptional: true + ), + Child( + name: "Modifiers", + kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), + nameForDiagnostics: "modifiers", + description: "The declaration modifiers applied to the case declaration.", + isOptional: true + ), + Child( + name: "CaseKeyword", + kind: .token(choices: [.keyword(text: "case")]), + description: "The `case` keyword for this case." + ), + Child( + name: "Elements", + kind: .collection(kind: "EnumCaseElementList", collectionElementName: "Element"), + nameForDiagnostics: "elements", + description: "The elements this case declares." + ), + ] + ), + + Node( + name: "EnumCaseElementList", + nameForDiagnostics: nil, + description: "A collection of 0 or more `EnumCaseElement`s.", + kind: "SyntaxCollection", + element: "EnumCaseElement" + ), + + Node( + name: "EnumCaseElement", + nameForDiagnostics: nil, + description: "An element of an enum case, containing the name of the case and, optionally, either associated values or an assignment to a raw value.", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + description: "The name of this case." + ), + Child( + name: "AssociatedValue", + kind: .node(kind: "ParameterClause"), + nameForDiagnostics: "associated values", + description: "The set of associated values of the case.", + isOptional: true + ), + Child( + name: "RawValue", + kind: .node(kind: "InitializerClause"), + description: "The raw value of this enum element, if present.", + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + description: "The trailing comma of this element, if the case has multiple elements.", + isOptional: true + ), + ] + ), + + Node( + name: "EnumDecl", + nameForDiagnostics: "enum", + description: "A Swift `enum` declaration.", + kind: "Decl", + traits: [ + "DeclGroup", + "IdentifiedDecl", + "Attributed", + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + description: "The attributes applied to the enum declaration.", + isOptional: true + ), + Child( + name: "Modifiers", + kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), + nameForDiagnostics: "modifiers", + description: "The declaration modifiers applied to the enum declaration.", + isOptional: true + ), + Child( + name: "EnumKeyword", + kind: .token(choices: [.keyword(text: "enum")]), + description: "The `enum` keyword for this declaration." + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + description: "The name of this enum." + ), + Child( + name: "GenericParameters", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + description: "The generic parameters, if any, for this enum.", + isOptional: true + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "inheritance clause", + description: "The inheritance clause describing conformances or raw values for this enum.", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + description: "The `where` clause that applies to the generic parameters of this enum.", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock"), + description: "The cases and other members of this enum." + ), + ] + ), + + // extension-declaration -> attributes? access-level-modifier? + // 'extension' extended-type + // type-inheritance-clause? + // generic-where-clause? + // '{' extension-members '}' + // extension-name -> identifier + Node( + name: "ExtensionDecl", + nameForDiagnostics: "extension", + kind: "Decl", + traits: [ + "DeclGroup", + "Attributed", + ], + 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: "ExtensionKeyword", + kind: .token(choices: [.keyword(text: "extension")]) + ), + Child( + name: "ExtendedType", + kind: .node(kind: "Type") + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "inheritance clause", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock") + ), + ] + ), + + Node( + name: "FunctionDecl", + nameForDiagnostics: "function", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + 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: "FuncKeyword", + kind: .token(choices: [.keyword(text: "func")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "Signature", + kind: .node(kind: "FunctionSignature"), + nameForDiagnostics: "function signature" + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + isOptional: true + ), + ] + ), + + Node( + name: "FunctionParameterList", + nameForDiagnostics: "parameter list", + kind: "SyntaxCollection", + element: "FunctionParameter" + ), + + // parameter -> + // external-parameter-name? local-parameter-name ':' + // type '...'? '='? expression? ','? + Node( + name: "FunctionParameter", + nameForDiagnostics: "parameter", + kind: "Syntax", + traits: [ + "WithTrailingComma", + "Attributed", + ], + 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")]), + isOptional: true + ), + // One of these two names needs be optional, we choose the second + // name to avoid backtracking. + Child( + name: "SecondName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "internal name", + isOptional: true + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "Type", + kind: .node(kind: "Type"), + nameForDiagnostics: "type", + isOptional: true + ), + Child( + name: "Ellipsis", + kind: .token(choices: [.token(tokenKind: "EllipsisToken")]), + isOptional: true + ), + Child( + name: "DefaultArgument", + kind: .node(kind: "InitializerClause"), + nameForDiagnostics: "default argument", + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // function-signature -> + // '(' parameter-list? ')' decl-effect-specifiers? return-clause? + Node( + name: "FunctionSignature", + nameForDiagnostics: "function signature", + kind: "Syntax", + children: [ + Child( + name: "Input", + kind: .node(kind: "ParameterClause") + ), + Child( + name: "EffectSpecifiers", + kind: .node(kind: "DeclEffectSpecifiers"), + isOptional: true + ), + Child( + name: "Output", + kind: .node(kind: "ReturnClause"), + isOptional: true + ), + ] + ), + + Node( + name: "IfConfigClauseList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "IfConfigClause" + ), + + // if-config-clause -> + // ('#if' | '#elseif' | '#else') expr? (stmt-list | switch-case-list) + Node( + name: "IfConfigClause", + nameForDiagnostics: "conditional compilation clause", + kind: "Syntax", + children: [ + Child( + name: "PoundKeyword", + kind: .token(choices: [.token(tokenKind: "PoundIfToken"), .token(tokenKind: "PoundElseifToken"), .token(tokenKind: "PoundElseToken")]), + classification: "BuildConfigId", + requiresLeadingNewline: true + ), + Child( + name: "Condition", + kind: .node(kind: "Expr"), + nameForDiagnostics: "condition", + isOptional: true, + classification: "BuildConfigId" + ), + Child( + name: "Elements", + kind: .nodeChoices(choices: [ + Child( + name: "Statements", + kind: .node(kind: "CodeBlockItemList") + ), + Child( + name: "SwitchCases", + kind: .node(kind: "SwitchCaseList") + ), + Child( + name: "Decls", + kind: .node(kind: "MemberDeclList") + ), + Child( + name: "PostfixExpression", + kind: .node(kind: "Expr") + ), + Child( + name: "Attributes", + kind: .node(kind: "AttributeList") + ), + ]), + isOptional: true + ), + ] + ), + + // if-config-decl -> '#if' expr stmt-list else-if-directive-clause-list + // else-clause? '#endif' + Node( + name: "IfConfigDecl", + nameForDiagnostics: "conditional compilation block", + kind: "Decl", + children: [ + Child( + name: "Clauses", + kind: .collection(kind: "IfConfigClauseList", collectionElementName: "Clause") + ), + Child( + name: "PoundEndif", + kind: .token(choices: [.token(tokenKind: "PoundEndifToken")]), + classification: "BuildConfigId", + requiresLeadingNewline: true + ), + ] + ), + + Node( + name: "ImportDecl", + nameForDiagnostics: "import", + kind: "Decl", + traits: [ + "Attributed" + ], + 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: "ImportTok", + kind: .token(choices: [.keyword(text: "import")]) + ), + Child( + name: "ImportKind", + kind: .token(choices: [.keyword(text: "typealias"), .keyword(text: "struct"), .keyword(text: "class"), .keyword(text: "enum"), .keyword(text: "protocol"), .keyword(text: "var"), .keyword(text: "let"), .keyword(text: "func"), .keyword(text: "inout")]), + isOptional: true + ), + Child( + name: "Path", + kind: .collection(kind: "AccessPath", collectionElementName: "PathComponent") + ), + ] + ), + + Node( + name: "InheritedTypeList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "InheritedType" + ), + + Node( + name: "InheritedType", + nameForDiagnostics: "inherited type", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "TypeName", + kind: .node(kind: "Type") + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // initializer -> '=' expr + Node( + name: "InitializerClause", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Equal", + kind: .token(choices: [.token(tokenKind: "EqualToken")]) + ), + Child( + name: "Value", + kind: .node(kind: "Expr") + ), + ] + ), + + Node( + name: "InitializerDecl", + nameForDiagnostics: "initializer", + kind: "Decl", + traits: [ + "Attributed" + ], + 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: "InitKeyword", + kind: .token(choices: [.keyword(text: "init")]) + ), + Child( + name: "OptionalMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "InfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), + isOptional: true + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "Signature", + kind: .node(kind: "FunctionSignature"), + nameForDiagnostics: "function signature" + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + isOptional: true + ), + ] + ), + + Node( + name: "MacroDecl", + nameForDiagnostics: "macro", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + 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: "MacroKeyword", + kind: .token(choices: [.keyword(text: "macro")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "Signature", + kind: .nodeChoices(choices: [ + Child( + name: "FunctionLike", + kind: .node(kind: "FunctionSignature"), + nameForDiagnostics: "macro signature" + ), + Child( + name: "ValueLike", + kind: .node(kind: "TypeAnnotation"), + nameForDiagnostics: "macro signature" + ), + ]), + nameForDiagnostics: "macro signature" + ), + Child( + name: "Definition", + kind: .node(kind: "InitializerClause"), + nameForDiagnostics: "macro definition", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + ] + ), + + // e.g., "#embed("filename.txt")" + Node( + name: "MacroExpansionDecl", + nameForDiagnostics: "macro expansion", + kind: "Decl", + traits: [ + "FreestandingMacroExpansion" + ], + children: [ + Child( + name: "PoundToken", + kind: .token(choices: [.token(tokenKind: "PoundToken")]), + description: "The `#` sign." + ), + Child( + name: "Macro", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericArguments", + kind: .node(kind: "GenericArgumentClause"), + isOptional: true + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + isOptional: true + ), + Child( + name: "ArgumentList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + isOptional: true + ), + Child( + name: "TrailingClosure", + kind: .node(kind: "ClosureExpr"), + isOptional: true + ), + Child( + name: "AdditionalTrailingClosures", + kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), + isOptional: true + ), + ] + ), + + Node( + name: "MemberDeclBlock", + nameForDiagnostics: "member block", + kind: "Syntax", + traits: [ + "Braced" + ], + parserFunction: "parseMemberDeclList", + children: [ + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "Members", + kind: .collection(kind: "MemberDeclList", collectionElementName: "Member"), + isIndented: true + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), + requiresLeadingNewline: true + ), + ] + ), + + // member-decl = decl ';'? + Node( + name: "MemberDeclListItem", + nameForDiagnostics: nil, + description: "A member declaration of a type consisting of a declaration and an optional semicolon;", + kind: "Syntax", + children: [ + Child( + name: "Decl", + kind: .node(kind: "Decl"), + description: "The declaration of the type member." + ), + Child( + name: "Semicolon", + kind: .token(choices: [.token(tokenKind: "SemicolonToken")]), + description: "An optional trailing semicolon.", + isOptional: true + ), + ], + omitWhenEmpty: true + ), + + // member-decl-list = member-decl member-decl-list? + Node( + name: "MemberDeclList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "MemberDeclListItem", + elementsSeparatedByNewline: true + ), + + // declaration-modifier -> access-level-modifier + // | mutation-modifier + // | 'class' + // | 'convenience' + // | 'distributed' + // | 'dynamic' + // | 'final' + // | 'infix' + // | 'isolated' + // | 'lazy' + // | 'nonisolated' + // | 'optional' + // | 'override' + // | 'postfix' + // | 'prefix' + // | 'required' + // | 'static' + // | 'unowned' + // | 'unowned(safe)' + // | 'unowned(unsafe)' + // | 'weak' + // mutation-modifier -> 'mutating' | 'nonmutating' + Node( + name: "ModifierList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "DeclModifier", + elementName: "Modifier", + omitWhenEmpty: true + ), + + // operator-decl -> attribute? modifiers? 'operator' operator + Node( + name: "OperatorDecl", + nameForDiagnostics: "operator declaration", + description: "A Swift `operator` declaration.", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + description: "The attributes applied to the 'operator' declaration.", + isOptional: true + ), + Child( + name: "Modifiers", + kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), + nameForDiagnostics: "modifiers", + description: "The declaration modifiers applied to the 'operator' declaration.", + isOptional: true, + classification: "Attribute" + ), + Child( + name: "OperatorKeyword", + kind: .token(choices: [.keyword(text: "operator")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]), + classification: "OperatorIdentifier" + ), + Child( + name: "OperatorPrecedenceAndTypes", + kind: .node(kind: "OperatorPrecedenceAndTypes"), + description: "Optionally specify a precedence group and designated types.", + isOptional: true + ), + ] + ), + + // infix-operator-group -> ':' identifier designated-type-list? + Node( + name: "OperatorPrecedenceAndTypes", + nameForDiagnostics: nil, + description: "A clause to specify precedence group in infix operator declarations, and designated types in any operator declaration.", + kind: "Syntax", + children: [ + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "PrecedenceGroup", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "precedence group", + description: "The precedence group for this operator" + ), + Child( + name: "DesignatedTypes", + kind: .collection(kind: "DesignatedTypeList", collectionElementName: "DesignatedTypeElement"), + description: "The designated types associated with this operator." + ), + ] + ), + + Node( + name: "ParameterClause", + nameForDiagnostics: "parameter clause", + kind: "Syntax", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "ParameterList", + kind: .collection(kind: "FunctionParameterList", collectionElementName: "Parameter"), + nameForDiagnostics: "parameters", + isIndented: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + Node( + name: "PatternBindingList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "PatternBinding" + ), + + // Pattern: Type = Value { get {} }, + Node( + name: "PatternBinding", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "TypeAnnotation", + kind: .node(kind: "TypeAnnotation"), + nameForDiagnostics: "type annotation", + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "InitializerClause"), + isOptional: true + ), + Child( + name: "Accessor", + kind: .nodeChoices(choices: [ + Child( + name: "Accessors", + kind: .node(kind: "AccessorBlock") + ), + Child( + name: "Getter", + kind: .node(kind: "CodeBlock") + ), + ]), + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "PoundSourceLocationArgs", + nameForDiagnostics: "'#sourceLocation' arguments", + kind: "Syntax", + children: [ + Child( + name: "FileArgLabel", + kind: .token(choices: [.keyword(text: "file")]) + ), + Child( + name: "FileArgColon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "FileName", + kind: .node(kind: "StringLiteralExpr"), + nameForDiagnostics: "file name" + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]) + ), + Child( + name: "LineArgLabel", + kind: .token(choices: [.keyword(text: "line")]) + ), + Child( + name: "LineArgColon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "LineNumber", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), + nameForDiagnostics: "line number" + ), + ] + ), + + Node( + name: "PoundSourceLocation", + nameForDiagnostics: "'#sourceLocation' directive", + kind: "Decl", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "PoundSourceLocation", + kind: .token(choices: [.token(tokenKind: "PoundSourceLocationToken")]) + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Args", + kind: .node(kind: "PoundSourceLocationArgs"), + nameForDiagnostics: "arguments", + isOptional: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // precedence-group-assignment -> + // 'assignment' ':' ('true' | 'false') + Node( + name: "PrecedenceGroupAssignment", + nameForDiagnostics: "'assignment' property of precedencegroup", + description: "Specifies the precedence of an operator when used in an operation that includes optional chaining.", + kind: "Syntax", + children: [ + Child( + name: "AssignmentKeyword", + kind: .token(choices: [.keyword(text: "assignment")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Flag", + kind: .token(choices: [.keyword(text: "true"), .keyword(text: "false")]), + description: "When true, an operator in the corresponding precedence group uses the same grouping rules during optional chaining as the assignment operators from the standard library. Otherwise, operators in the precedence group follows the same optional chaining rules as operators that don't perform assignment." + ), + ] + ), + + // precedence-group-associativity -> + // 'associativity' ':' ('left' | 'right' | 'none') + Node( + name: "PrecedenceGroupAssociativity", + nameForDiagnostics: "'associativity' property of precedencegroup", + description: "Specifies how a sequence of operators with the same precedence level are grouped together in the absence of grouping parentheses.", + kind: "Syntax", + children: [ + Child( + name: "AssociativityKeyword", + kind: .token(choices: [.keyword(text: "associativity")]), + classification: "Keyword" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Value", + kind: .token(choices: [.keyword(text: "left"), .keyword(text: "right"), .keyword(text: "none")]), + description: "Operators that are `left`-associative group left-to-right. Operators that are `right`-associative group right-to-left. Operators that are specified with an associativity of `none` don't associate at all" + ), + ] + ), + // precedence-group-attribute-list -> + // (precedence-group-relation | precedence-group-assignment | + // precedence-group-associativity )* + Node( + name: "PrecedenceGroupAttributeList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "Syntax", + elementName: "PrecedenceGroupAttribute", + elementChoices: ["PrecedenceGroupRelation", "PrecedenceGroupAssignment", "PrecedenceGroupAssociativity"] + ), + + // precedence-group-decl -> attributes? modifiers? 'precedencegroup' + // identifier '{' precedence-group-attribute-list + // '}' + Node( + name: "PrecedenceGroupDecl", + nameForDiagnostics: "precedencegroup", + description: "A Swift `precedencegroup` declaration.", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + description: "The attributes applied to the 'precedencegroup' declaration.", + isOptional: true + ), + Child( + name: "Modifiers", + kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), + nameForDiagnostics: "modifiers", + description: "The declaration modifiers applied to the 'precedencegroup' declaration.", + isOptional: true + ), + Child( + name: "PrecedencegroupKeyword", + kind: .token(choices: [.keyword(text: "precedencegroup")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + description: "The name of this precedence group." + ), + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "GroupAttributes", + kind: .collection(kind: "PrecedenceGroupAttributeList", collectionElementName: "GroupAttribute"), + description: "The characteristics of this precedence group." + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]) + ), + ] + ), + + Node( + name: "PrecedenceGroupNameElement", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // precedence-group-name-list -> + // identifier (',' identifier)* + Node( + name: "PrecedenceGroupNameList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "PrecedenceGroupNameElement" + ), + + // precedence-group-relation -> + // ('higherThan' | 'lowerThan') ':' precedence-group-name-list + Node( + name: "PrecedenceGroupRelation", + nameForDiagnostics: "'relation' property of precedencegroup", + description: "Specify the new precedence group's relation to existing precedence groups.", + kind: "Syntax", + children: [ + Child( + name: "HigherThanOrLowerThan", + kind: .token(choices: [.keyword(text: "higherThan"), .keyword(text: "lowerThan")]), + description: "The relation to specified other precedence groups.", + classification: "Keyword" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "OtherNames", + kind: .collection(kind: "PrecedenceGroupNameList", collectionElementName: "OtherName"), + description: "The name of other precedence group to which this precedence group relates." + ), + ] + ), + + Node( + name: "ProtocolDecl", + nameForDiagnostics: "protocol", + kind: "Decl", + traits: [ + "DeclGroup", + "IdentifiedDecl", + "Attributed", + ], + 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: "ProtocolKeyword", + kind: .token(choices: [.keyword(text: "protocol")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "PrimaryAssociatedTypeClause", + kind: .node(kind: "PrimaryAssociatedTypeClause"), + nameForDiagnostics: "primary associated type clause", + isOptional: true + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "inheritance clause", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock") + ), + ] + ), + + // return-clause -> + // '->' type + Node( + name: "ReturnClause", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Arrow", + kind: .token(choices: [.token(tokenKind: "ArrowToken")]) + ), + Child( + name: "ReturnType", + kind: .node(kind: "Type"), + nameForDiagnostics: "return type" + ), + ] + ), + + // source-file = code-block-item-list eof + Node( + name: "SourceFile", + nameForDiagnostics: "source file", + kind: "Syntax", + traits: [ + "WithStatements" + ], + parserFunction: "parseSourceFile", + children: [ + Child( + name: "Statements", + kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement") + ), + Child( + name: "EOFToken", + kind: .node(kind: "EOFToken") + ), + ] + ), + + // struct-declaration -> attributes? access-level-modifier? + // 'struct' struct-name + // generic-parameter-clause? + // type-inheritance-clause? + // generic-where-clause? + // '{' struct-members '}' + // struct-name -> identifier + Node( + name: "StructDecl", + nameForDiagnostics: "struct", + kind: "Decl", + traits: [ + "DeclGroup", + "IdentifiedDecl", + "Attributed", + ], + 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: "StructKeyword", + kind: .token(choices: [.keyword(text: "struct")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "InheritanceClause", + kind: .node(kind: "TypeInheritanceClause"), + nameForDiagnostics: "type inheritance clause", + isOptional: true + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Members", + kind: .node(kind: "MemberDeclBlock") + ), + ] + ), + + Node( + name: "SubscriptDecl", + nameForDiagnostics: "subscript", + kind: "Decl", + traits: [ + "Attributed" + ], + 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: "SubscriptKeyword", + kind: .token(choices: [.keyword(text: "subscript")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "Indices", + kind: .node(kind: "ParameterClause") + ), + Child( + name: "Result", + kind: .node(kind: "ReturnClause") + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + Child( + name: "Accessor", + kind: .nodeChoices(choices: [ + Child( + name: "Accessors", + kind: .node(kind: "AccessorBlock") + ), + Child( + name: "Getter", + kind: .node(kind: "CodeBlock") + ), + ]), + isOptional: true + ), + ] + ), + + // type-inheritance-clause -> ':' type + Node( + name: "TypeInheritanceClause", + nameForDiagnostics: "inheritance clause", + kind: "Syntax", + children: [ + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "InheritedTypeCollection", + kind: .collection(kind: "InheritedTypeList", collectionElementName: "InheritedType") + ), + ] + ), + + // type-assignment -> '=' type + Node( + name: "TypeInitializerClause", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Equal", + kind: .token(choices: [.token(tokenKind: "EqualToken")]) + ), + Child( + name: "Value", + kind: .node(kind: "Type"), + nameForDiagnostics: "type" + ), + ] + ), + + // typealias-declaration -> attributes? access-level-modifier? 'typealias' + // typealias-name generic-parameter-clause? + // type-assignment + // typealias-name -> identifier + Node( + name: "TypealiasDecl", + nameForDiagnostics: "typealias declaration", + kind: "Decl", + traits: [ + "IdentifiedDecl", + "Attributed", + ], + 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: "TypealiasKeyword", + kind: .token(choices: [.keyword(text: "typealias")]) + ), + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericParameterClause", + kind: .node(kind: "GenericParameterClause"), + nameForDiagnostics: "generic parameter clause", + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "TypeInitializerClause") + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + nameForDiagnostics: "generic where clause", + isOptional: true + ), + ] + ), + + Node( + name: "VariableDecl", + nameForDiagnostics: "variable", + kind: "Decl", + traits: [ + "Attributed" + ], + 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: "BindingKeyword", + kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")]) + ), + Child( + name: "Bindings", + kind: .collection(kind: "PatternBindingList", collectionElementName: "Binding") + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift.gyb deleted file mode 100644 index a870ba9cb26..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/DeclNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From DeclNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let DECL_NODES: [Node] = [ -% for node in sorted(DECL_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift new file mode 100644 index 00000000000..ff4307a1006 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift @@ -0,0 +1,1701 @@ +//// Automatically Generated From ExprNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let EXPR_NODES: [Node] = [ + Node( + name: "ArrayElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "ArrayElement" + ), + + // element inside an array expression: expression ','? + Node( + name: "ArrayElement", + nameForDiagnostics: "array element", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "value" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // Array literal, e.g. [1, 2, 3] + Node( + name: "ArrayExpr", + nameForDiagnostics: "array", + kind: "Expr", + children: [ + Child( + name: "LeftSquare", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "Elements", + kind: .collection(kind: "ArrayElementList", collectionElementName: "Element"), + isIndented: true + ), + Child( + name: "RightSquare", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + // arrow-expr -> 'async'? 'throws'? '->' + // NOTE: This appears only in SequenceExpr. + Node( + name: "ArrowExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "EffectSpecifiers", + kind: .node(kind: "TypeEffectSpecifiers"), + isOptional: true + ), + Child( + name: "ArrowToken", + kind: .token(choices: [.token(tokenKind: "ArrowToken")]) + ), + ] + ), + + // expression as TypeName + // NOTE: This won't come directly out of the parser. Rather, it is the + // result of "folding" a SequenceExpr based on knowing the precedence + // relationships amongst the different infix operators. + Node( + name: "AsExpr", + nameForDiagnostics: "'as'", + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "AsTok", + kind: .token(choices: [.keyword(text: "as")]) + ), + Child( + name: "QuestionOrExclamationMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), + isOptional: true + ), + Child( + name: "TypeName", + kind: .node(kind: "Type") + ), + ] + ), + + // An = expression. + Node( + name: "AssignmentExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "AssignToken", + kind: .token(choices: [.token(tokenKind: "EqualToken")]) + ) + ] + ), + + // The await operator. + // await foo() + Node( + name: "AwaitExpr", + nameForDiagnostics: "'await' expression", + kind: "Expr", + children: [ + Child( + name: "AwaitKeyword", + kind: .token(choices: [.keyword(text: "await")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + // An operator like + or -. + // NOTE: This appears only in SequenceExpr. + Node( + name: "BinaryOperatorExpr", + nameForDiagnostics: "operator", + kind: "Expr", + children: [ + Child( + name: "OperatorToken", + kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken")]) + ) + ] + ), + + // true or false + Node( + name: "BooleanLiteralExpr", + nameForDiagnostics: "bool literal", + kind: "Expr", + children: [ + Child( + name: "BooleanLiteral", + kind: .token(choices: [.keyword(text: "true"), .keyword(text: "false")]) + ) + ] + ), + + // The borrow expr + Node( + name: "BorrowExpr", + nameForDiagnostics: "'_borrow' expression", + kind: "Expr", + children: [ + Child( + name: "BorrowKeyword", + kind: .token(choices: [.keyword(text: "_borrow")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + // case-item -> pattern where-clause? ','? + Node( + name: "CaseItem", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "WhereClause", + kind: .node(kind: "WhereClause"), + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "ClosureCaptureItemList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "ClosureCaptureItem" + ), + + Node( + name: "ClosureCaptureItemSpecifier", + nameForDiagnostics: "closure capture specifier", + kind: "Syntax", + children: [ + Child( + name: "Specifier", + kind: .token(choices: [.keyword(text: "weak"), .keyword(text: "unowned")]) + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + isOptional: true + ), + Child( + name: "Detail", + kind: .token(choices: [.keyword(text: "safe"), .keyword(text: "unsafe")]), + isOptional: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "ClosureCaptureItem", + nameForDiagnostics: "closure capture item", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Specifier", + kind: .node(kind: "ClosureCaptureItemSpecifier"), + isOptional: true + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + isOptional: true + ), + Child( + name: "AssignToken", + kind: .token(choices: [.token(tokenKind: "EqualToken")]), + isOptional: true + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "ClosureCaptureSignature", + nameForDiagnostics: "closure capture signature", + kind: "Syntax", + children: [ + Child( + name: "LeftSquare", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "Items", + kind: .collection(kind: "ClosureCaptureItemList", collectionElementName: "Item"), + isOptional: true + ), + Child( + name: "RightSquare", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + Node( + name: "ClosureExpr", + nameForDiagnostics: "closure", + kind: "Expr", + traits: [ + "Braced", + "WithStatements", + ], + children: [ + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "Signature", + kind: .node(kind: "ClosureSignature"), + isOptional: true + ), + Child( + name: "Statements", + kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), + isIndented: true + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), + requiresLeadingNewline: true + ), + ] + ), + + // a, b, c + Node( + name: "ClosureParamList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "ClosureParam" + ), + + Node( + name: "ClosureParam", + nameForDiagnostics: "closure parameter", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "ClosureSignature", + nameForDiagnostics: "closure signature", + kind: "Syntax", + traits: [ + "Attributed" + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + nameForDiagnostics: "attributes", + isOptional: true + ), + Child( + name: "Capture", + kind: .node(kind: "ClosureCaptureSignature"), + isOptional: true + ), + Child( + name: "Input", + kind: .nodeChoices(choices: [ + Child( + name: "SimpleInput", + kind: .node(kind: "ClosureParamList") + ), + Child( + name: "Input", + kind: .node(kind: "ParameterClause") + ), + ]), + isOptional: true + ), + Child( + name: "EffectSpecifiers", + kind: .node(kind: "TypeEffectSpecifiers"), + isOptional: true + ), + Child( + name: "Output", + kind: .node(kind: "ReturnClause"), + isOptional: true + ), + Child( + name: "InTok", + kind: .token(choices: [.keyword(text: "in")]) + ), + ] + ), + + Node( + name: "DeclNameArgumentList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "DeclNameArgument" + ), + + // declname-arguments -> '(' declname-argument-list ')' + // declname-argument-list -> declname-argument* + // declname-argument -> identifier ':' + Node( + name: "DeclNameArgument", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Name", + kind: .node(kind: "Token") + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false) + ), + ] + ), + + Node( + name: "DeclNameArguments", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Arguments", + kind: .collection(kind: "DeclNameArgumentList", collectionElementName: "Argument") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + Node( + name: "DictionaryElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "DictionaryElement" + ), + + // element inside an array expression: expression ','? + Node( + name: "DictionaryElement", + nameForDiagnostics: "dictionary element", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "KeyExpression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "key" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "ValueExpression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "value", + isIndented: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // Dictionary literal, e.g. [1:1, 2:2, 3:3] + Node( + name: "DictionaryExpr", + nameForDiagnostics: "dictionary", + kind: "Expr", + children: [ + Child( + name: "LeftSquare", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "Content", + kind: .nodeChoices(choices: [ + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false) + ), + Child( + name: "Elements", + kind: .node(kind: "DictionaryElementList") + ), + ]), + isIndented: true + ), + Child( + name: "RightSquare", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + // A _ expression. + Node( + name: "DiscardAssignmentExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Wildcard", + kind: .token(choices: [.token(tokenKind: "WildcardToken")]) + ) + ] + ), + + // <#content#> + Node( + name: "EditorPlaceholderExpr", + nameForDiagnostics: "editor placeholder", + kind: "Expr", + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ) + ] + ), + + Node( + name: "ExprList", + nameForDiagnostics: nil, + description: "A list of expressions connected by operators. This list is contained by a `SequenceExprSyntax`.", + kind: "SyntaxCollection", + element: "Expr", + elementName: "Expression" + ), + + // expression segment in a string interpolation expression. + Node( + name: "ExpressionSegment", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "Backslash", + kind: .token(choices: [.token(tokenKind: "BackslashToken")]) + ), + Child( + name: "Delimiter", + kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), + isOptional: true + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + classification: "StringInterpolationAnchor", + forceClassification: true + ), + Child( + name: "Expressions", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Expression") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + classification: "StringInterpolationAnchor", + forceClassification: true + ), + ] + ), + + // A floating-point literal + // 4.0 + // -3.9 + // +4e20 + Node( + name: "FloatLiteralExpr", + nameForDiagnostics: "floating literal", + kind: "Expr", + children: [ + Child( + name: "FloatingDigits", + kind: .token(choices: [.token(tokenKind: "FloatingLiteralToken")]) + ) + ] + ), + + // forced-value-expr -> expr '!' + Node( + name: "ForcedValueExpr", + nameForDiagnostics: "force unwrap", + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "ExclamationMark", + kind: .token(choices: [.token(tokenKind: "ExclamationMarkToken")]) + ), + ] + ), + + // call-expr -> expr '(' call-argument-list ')' closure-expr? + // | expr closure-expr + Node( + name: "FunctionCallExpr", + nameForDiagnostics: "function call", + kind: "Expr", + children: [ + Child( + name: "CalledExpression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "called expression" + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + isOptional: true + ), + Child( + name: "ArgumentList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), + nameForDiagnostics: "arguments", + isIndented: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + isOptional: true + ), + Child( + name: "TrailingClosure", + kind: .node(kind: "ClosureExpr"), + nameForDiagnostics: "trailing closure", + isOptional: true + ), + Child( + name: "AdditionalTrailingClosures", + kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), + nameForDiagnostics: "trailing closures", + isOptional: true + ), + ] + ), + + // An identifier expression. + Node( + name: "IdentifierExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "DollarIdentifierToken"), .token(tokenKind: "BinaryOperatorToken")]) + ), + Child( + name: "DeclNameArguments", + kind: .node(kind: "DeclNameArguments"), + isOptional: true + ), + ] + ), + + // if-expr -> identifier? ':'? 'if' condition-list code-block + // else-clause ';'? + // + // This node represents both an 'if' expression, as well as an 'if' statement + // when wrapped in a ExpressionStmt node. + Node( + name: "IfExpr", + nameForDiagnostics: "'if' statement", + kind: "Expr", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "IfKeyword", + kind: .token(choices: [.keyword(text: "if")]) + ), + Child( + name: "Conditions", + kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition") + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + nameForDiagnostics: "body" + ), + Child( + name: "ElseKeyword", + kind: .node(kind: "ElseToken"), + isOptional: true + ), + Child( + name: "ElseBody", + kind: .nodeChoices(choices: [ + Child( + name: "IfExpr", + kind: .node(kind: "IfExpr") + ), + Child( + name: "CodeBlock", + kind: .node(kind: "CodeBlock") + ), + ]), + nameForDiagnostics: "else body", + isOptional: true + ), + ] + ), + + // An inout expression. + // &x + Node( + name: "InOutExpr", + nameForDiagnostics: "inout expression", + kind: "Expr", + children: [ + Child( + name: "Ampersand", + kind: .token(choices: [.token(tokenKind: "PrefixAmpersandToken")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + // An infix binary expression like x + y. + // NOTE: This won't come directly out of the parser. Rather, it is the + // result of "folding" a SequenceExpr based on knowing the precedence + // relationships amongst the different infix operators. + Node( + name: "InfixOperatorExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "LeftOperand", + kind: .node(kind: "Expr") + ), + Child( + name: "OperatorOperand", + kind: .node(kind: "Expr") + ), + Child( + name: "RightOperand", + kind: .node(kind: "Expr") + ), + ] + ), + + // An integer literal. + // 3 + // +3_400 + // +0x4f + Node( + name: "IntegerLiteralExpr", + nameForDiagnostics: "integer literal", + kind: "Expr", + children: [ + Child( + name: "Digits", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]) + ) + ] + ), + + // expression is TypeName + // NOTE: This won't come directly out of the parser. Rather, it is the + // result of "folding" a SequenceExpr based on knowing the precedence + // relationships amongst the different infix operators. + Node( + name: "IsExpr", + nameForDiagnostics: "'is'", + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "IsTok", + kind: .token(choices: [.keyword(text: "is")]) + ), + Child( + name: "TypeName", + kind: .node(kind: "Type") + ), + ] + ), + + // The components of a key path + Node( + name: "KeyPathComponentList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "KeyPathComponent" + ), + + // A single key path component. + Node( + name: "KeyPathComponent", + nameForDiagnostics: "key path component", + kind: "Syntax", + children: [ + Child( + name: "Period", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]), + isOptional: true + ), + Child( + name: "Component", + kind: .nodeChoices(choices: [ + Child( + name: "Property", + kind: .node(kind: "KeyPathPropertyComponent") + ), + Child( + name: "Subscript", + kind: .node(kind: "KeyPathSubscriptComponent") + ), + Child( + name: "Optional", + kind: .node(kind: "KeyPathOptionalComponent") + ), + ]) + ), + ] + ), + + // e.g. "\a.b[2].a" + Node( + name: "KeyPathExpr", + nameForDiagnostics: "key path", + kind: "Expr", + children: [ + Child( + name: "Backslash", + kind: .token(choices: [.token(tokenKind: "BackslashToken")]) + ), + Child( + name: "Root", + kind: .node(kind: "Type"), + nameForDiagnostics: "root", + isOptional: true + ), + Child( + name: "Components", + kind: .collection(kind: "KeyPathComponentList", collectionElementName: "KeyPathComponent") + ), + ] + ), + + // A key path component like '?' or '!'. + Node( + name: "KeyPathOptionalComponent", + nameForDiagnostics: "key path optional component", + kind: "Syntax", + children: [ + Child( + name: "QuestionOrExclamationMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]) + ) + ] + ), + + // A key path component like .property or .1. + Node( + name: "KeyPathPropertyComponent", + nameForDiagnostics: "key path property component", + kind: "Syntax", + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "DollarIdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "IntegerLiteralToken")]) + ), + Child( + name: "DeclNameArguments", + kind: .node(kind: "DeclNameArguments"), + isOptional: true + ), + Child( + name: "GenericArgumentClause", + kind: .node(kind: "GenericArgumentClause"), + isOptional: true + ), + ] + ), + + // A key path component like .[17] + Node( + name: "KeyPathSubscriptComponent", + nameForDiagnostics: "key path subscript component", + kind: "Syntax", + children: [ + Child( + name: "LeftBracket", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "ArgumentList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), + nameForDiagnostics: "arguments" + ), + Child( + name: "RightBracket", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + // e.g., "#embed("filename.txt")" + Node( + name: "MacroExpansionExpr", + nameForDiagnostics: "macro expansion", + kind: "Expr", + traits: [ + "FreestandingMacroExpansion" + ], + children: [ + Child( + name: "PoundToken", + kind: .token(choices: [.token(tokenKind: "PoundToken")]), + description: "The `#` sign." + ), + Child( + name: "Macro", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]) + ), + Child( + name: "GenericArguments", + kind: .node(kind: "GenericArgumentClause"), + isOptional: true + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + isOptional: true + ), + Child( + name: "ArgumentList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + isOptional: true + ), + Child( + name: "TrailingClosure", + kind: .node(kind: "ClosureExpr"), + isOptional: true + ), + Child( + name: "AdditionalTrailingClosures", + kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), + isOptional: true + ), + ] + ), + + // expr?.name + Node( + name: "MemberAccessExpr", + nameForDiagnostics: "member access", + kind: "Expr", + children: [ + Child( + name: "Base", + kind: .node(kind: "Expr"), + nameForDiagnostics: "base", + isOptional: true + ), + Child( + name: "Dot", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]) + ), + Child( + name: "Name", + kind: .node(kind: "Token"), + nameForDiagnostics: "name" + ), + Child( + name: "DeclNameArguments", + kind: .node(kind: "DeclNameArguments"), + isOptional: true + ), + ] + ), + + // The move expr + Node( + name: "MoveExpr", + nameForDiagnostics: "'_move' expression", + kind: "Expr", + children: [ + Child( + name: "MoveKeyword", + kind: .token(choices: [.keyword(text: "_move"), .keyword(text: "consume")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + Node( + name: "MultipleTrailingClosureElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "MultipleTrailingClosureElement" + ), + + // trailing-closure-element -> identifier ':' closure-expression + Node( + name: "MultipleTrailingClosureElement", + nameForDiagnostics: "trailing closure", + kind: "Syntax", + children: [ + Child( + name: "Label", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "label" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Closure", + kind: .node(kind: "ClosureExpr") + ), + ] + ), + + // A nil expression. + Node( + name: "NilLiteralExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "NilKeyword", + kind: .token(choices: [.keyword(text: "nil")]) + ) + ] + ), + + // optional-chaining-expr -> expr '?' + Node( + name: "OptionalChainingExpr", + nameForDiagnostics: "optional chaining", + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "QuestionMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken")]) + ), + ] + ), + + // A pack element expr spelled with 'each'. + Node( + name: "PackElementExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "EachKeyword", + kind: .token(choices: [.keyword(text: "each")]) + ), + Child( + name: "PackRefExpr", + kind: .node(kind: "Expr") + ), + ] + ), + + // A pack expansion expr spelled with 'repeat'. + Node( + name: "PackExpansionExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "RepeatKeyword", + kind: .token(choices: [.keyword(text: "repeat")]) + ), + Child( + name: "PatternExpr", + kind: .node(kind: "Expr") + ), + ] + ), + + // postfix '#if' expression + Node( + name: "PostfixIfConfigExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Base", + kind: .node(kind: "Expr"), + isOptional: true + ), + Child( + name: "Config", + kind: .node(kind: "IfConfigDecl") + ), + ] + ), + + // postfix-unary-expr -> expr postfix-operator + Node( + name: "PostfixUnaryExpr", + nameForDiagnostics: "postfix expression", + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "OperatorToken", + kind: .token(choices: [.token(tokenKind: "PostfixOperatorToken")]) + ), + ] + ), + + // A prefix operator expression. + // -x + // !true + Node( + name: "PrefixOperatorExpr", + nameForDiagnostics: "operator", + kind: "Expr", + children: [ + Child( + name: "OperatorToken", + kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")]), + isOptional: true + ), + Child( + name: "PostfixExpression", + kind: .node(kind: "Expr") + ), + ] + ), + + // e.g '(a|c)*', the contents of the literal is opaque to the C++ Swift + // parser though. + Node( + name: "RegexLiteralExpr", + nameForDiagnostics: "regex literal", + kind: "Expr", + children: [ + Child( + name: "Regex", + kind: .token(choices: [.token(tokenKind: "RegexLiteralToken")]) + ) + ] + ), + + // A flat list of expressions before sequence folding, e.g. 1 + 2 + 3. + Node( + name: "SequenceExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Elements", + kind: .collection(kind: "ExprList", collectionElementName: "Element") + ) + ] + ), + + // specialize-expr -> expr generic-argument-clause? + Node( + name: "SpecializeExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "GenericArgumentClause", + kind: .node(kind: "GenericArgumentClause") + ), + ] + ), + + // e.g. "abc \(foo()) def" + Node( + name: "StringLiteralExpr", + nameForDiagnostics: "string literal", + kind: "Expr", + children: [ + Child( + name: "OpenDelimiter", + kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), + isOptional: true + ), + Child( + name: "OpenQuote", + kind: .token(choices: [.token(tokenKind: "StringQuoteToken"), .token(tokenKind: "MultilineStringQuoteToken"), .token(tokenKind: "SingleQuoteToken")]) + ), + Child( + name: "Segments", + kind: .collection(kind: "StringLiteralSegments", collectionElementName: "Segment") + ), + Child( + name: "CloseQuote", + kind: .token(choices: [.token(tokenKind: "StringQuoteToken"), .token(tokenKind: "MultilineStringQuoteToken"), .token(tokenKind: "SingleQuoteToken")]) + ), + Child( + name: "CloseDelimiter", + kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "StringLiteralSegments", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "Syntax", + elementName: "Segment", + elementChoices: ["StringSegment", "ExpressionSegment"] + ), + + // string literal segment in a string interpolation expression. + Node( + name: "StringSegment", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Content", + kind: .token(choices: [.token(tokenKind: "StringSegmentToken")]) + ) + ] + ), + + // subscript-expr -> expr '[' call-argument-list ']' closure-expr? + Node( + name: "SubscriptExpr", + nameForDiagnostics: "subscript", + kind: "Expr", + children: [ + Child( + name: "CalledExpression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "called expression" + ), + Child( + name: "LeftBracket", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "ArgumentList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), + nameForDiagnostics: "arguments" + ), + Child( + name: "RightBracket", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + Child( + name: "TrailingClosure", + kind: .node(kind: "ClosureExpr"), + nameForDiagnostics: "trailing closure", + isOptional: true + ), + Child( + name: "AdditionalTrailingClosures", + kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), + nameForDiagnostics: "trailing closures", + isOptional: true + ), + ] + ), + + // An 'super' expression. + Node( + name: "SuperRefExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "SuperKeyword", + kind: .token(choices: [.keyword(text: "super")]) + ) + ] + ), + + // switch-case-label -> 'case' case-item-list ':' + Node( + name: "SwitchCaseLabel", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "CaseKeyword", + kind: .token(choices: [.keyword(text: "case")]) + ), + Child( + name: "CaseItems", + kind: .collection(kind: "CaseItemList", collectionElementName: "CaseItem") + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false) + ), + ] + ), + + // switch-case-list -> switch-case switch-case-list? + Node( + name: "SwitchCaseList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "Syntax", + elementName: "SwitchCase", + elementChoices: ["SwitchCase", "IfConfigDecl"], + elementsSeparatedByNewline: true + ), + + // switch-case -> unknown-attr? switch-case-label stmt-list + // | unknown-attr? switch-default-label stmt-list + Node( + name: "SwitchCase", + nameForDiagnostics: "switch case", + kind: "Syntax", + traits: [ + "WithStatements" + ], + parserFunction: "parseSwitchCase", + children: [ + Child( + name: "UnknownAttr", + kind: .node(kind: "Attribute"), + isOptional: true + ), + Child( + name: "Label", + kind: .nodeChoices(choices: [ + Child( + name: "Default", + kind: .node(kind: "SwitchDefaultLabel") + ), + Child( + name: "Case", + kind: .node(kind: "SwitchCaseLabel") + ), + ]), + nameForDiagnostics: "label" + ), + Child( + name: "Statements", + kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), + isIndented: true + ), + ] + ), + + // switch-default-label -> 'default' ':' + Node( + name: "SwitchDefaultLabel", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "DefaultKeyword", + kind: .token(choices: [.keyword(text: "default")]) + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false) + ), + ] + ), + + // switch-expr -> identifier? ':'? 'switch' expr '{' + // switch-case-list '}' ';'? + // + // This node represents both a 'switch' expression, as well as a 'switch' + // statement when wrapped in a ExpressionStmt node. + Node( + name: "SwitchExpr", + nameForDiagnostics: "'switch' statement", + kind: "Expr", + traits: [ + "Braced" + ], + children: [ + Child( + name: "SwitchKeyword", + kind: .token(choices: [.keyword(text: "switch")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "LeftBrace", + kind: .token(choices: [.token(tokenKind: "LeftBraceToken")]) + ), + Child( + name: "Cases", + kind: .collection(kind: "SwitchCaseList", collectionElementName: "Case") + ), + Child( + name: "RightBrace", + kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), + requiresLeadingNewline: true + ), + ] + ), + + // a ? 1 : 0 + // NOTE: This won't come directly out of the parser. Rather, it is the + // result of "folding" a SequenceExpr based on knowing the precedence + // relationships amongst the different infix operators. + Node( + name: "TernaryExpr", + nameForDiagnostics: "ternay expression", + kind: "Expr", + children: [ + Child( + name: "ConditionExpression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "condition" + ), + Child( + name: "QuestionMark", + kind: .token(choices: [.token(tokenKind: "InfixQuestionMarkToken")]) + ), + Child( + name: "FirstChoice", + kind: .node(kind: "Expr"), + nameForDiagnostics: "first choice" + ), + Child( + name: "ColonMark", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "SecondChoice", + kind: .node(kind: "Expr"), + nameForDiagnostics: "second choice" + ), + ] + ), + + // The try operator. + // try foo() + // try? foo() + // try! foo() + Node( + name: "TryExpr", + nameForDiagnostics: "'try' expression", + kind: "Expr", + children: [ + Child( + name: "TryKeyword", + kind: .token(choices: [.keyword(text: "try")]) + ), + Child( + name: "QuestionOrExclamationMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")], requiresTrailingSpace: true), + isOptional: true + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + Node( + name: "TupleExprElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "TupleExprElement" + ), + + // An element inside a tuple element list + Node( + name: "TupleExprElement", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Label", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "label", + isOptional: true + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "Expression", + kind: .node(kind: "Expr"), + nameForDiagnostics: "value" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "TupleExpr", + nameForDiagnostics: "tuple", + kind: "Expr", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "ElementList", + kind: .collection(kind: "TupleExprElementList", collectionElementName: "Element"), + isIndented: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // Type + Node( + name: "TypeExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Type", + kind: .node(kind: "Type") + ) + ] + ), + + // 'as' ('?'|'!') + // "as" type casting ooperator without operands. + // NOTE: This appears only in SequenceExpr. + Node( + name: "UnresolvedAsExpr", + nameForDiagnostics: "'as'", + kind: "Expr", + children: [ + Child( + name: "AsTok", + kind: .token(choices: [.keyword(text: "as")]) + ), + Child( + name: "QuestionOrExclamationMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), + isOptional: true + ), + ] + ), + + // 'is' + // "is" type casting ooperator without operands. + // NOTE: This appears only in SequenceExpr. + Node( + name: "UnresolvedIsExpr", + nameForDiagnostics: "'is'", + kind: "Expr", + children: [ + Child( + name: "IsTok", + kind: .token(choices: [.keyword(text: "is")]) + ) + ] + ), + // unresolved-pattern-expr -> pattern + Node( + name: "UnresolvedPatternExpr", + nameForDiagnostics: nil, + kind: "Expr", + children: [ + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ) + ] + ), + + // ? expr : + // Ternary expression without the condition and the second choice. + // NOTE: This appears only in SequenceExpr. + Node( + name: "UnresolvedTernaryExpr", + nameForDiagnostics: "ternary operator", + kind: "Expr", + children: [ + Child( + name: "QuestionMark", + kind: .token(choices: [.token(tokenKind: "InfixQuestionMarkToken")]) + ), + Child( + name: "FirstChoice", + kind: .node(kind: "Expr") + ), + Child( + name: "ColonMark", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + ] + ), + + Node( + name: "YieldExprListElement", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "YieldExprList", + nameForDiagnostics: "yield list", + kind: "SyntaxCollection", + element: "YieldExprListElement", + elementName: "Yields" + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift.gyb deleted file mode 100644 index 09ac4c8a91f..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From ExprNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let EXPR_NODES: [Node] = [ -% for node in sorted(EXPR_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift new file mode 100644 index 00000000000..192c622d3d8 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift @@ -0,0 +1,301 @@ +//// Automatically Generated From GenericNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let GENERIC_NODES: [Node] = [ + // conformance-requirement -> type-identifier : type-identifier + Node( + name: "ConformanceRequirement", + nameForDiagnostics: "conformance requirement", + kind: "Syntax", + children: [ + Child( + name: "LeftTypeIdentifier", + kind: .node(kind: "Type") + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "RightTypeIdentifier", + kind: .node(kind: "Type") + ), + ] + ), + + // generic-parameter-clause -> '<' generic-parameter-list generic-where-clause? '>' + Node( + name: "GenericParameterClause", + nameForDiagnostics: "generic parameter clause", + kind: "Syntax", + parserFunction: "parseGenericParameters", + children: [ + Child( + name: "LeftAngleBracket", + kind: .token(choices: [.token(tokenKind: "LeftAngleToken")]) + ), + Child( + name: "GenericParameterList", + kind: .collection(kind: "GenericParameterList", collectionElementName: "GenericParameter") + ), + Child( + name: "GenericWhereClause", + kind: .node(kind: "GenericWhereClause"), + isOptional: true + ), + Child( + name: "RightAngleBracket", + kind: .token(choices: [.token(tokenKind: "RightAngleToken")]) + ), + ] + ), + + Node( + name: "GenericParameterList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "GenericParameter" + ), + + // generic-parameter -> type-name + // | type-name : type-identifier + // | type-name : protocol-composition-type + Node( + name: "GenericParameter", + nameForDiagnostics: "generic parameter", + kind: "Syntax", + traits: [ + "WithTrailingComma", + "Attributed", + ], + children: [ + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + isOptional: true + ), + Child( + name: "Each", + kind: .token(choices: [.keyword(text: "each")]), + nameForDiagnostics: "parameter pack specifier", + isOptional: true + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "InheritedType", + kind: .node(kind: "Type"), + nameForDiagnostics: "inherited type", + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + Node( + name: "GenericRequirementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "GenericRequirement", + elementName: "GenericRequirement" + ), + + // generic-requirement -> + // (same-type-requirement|conformance-requirement|layout-requirement) ','? + Node( + name: "GenericRequirement", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Body", + kind: .nodeChoices(choices: [ + Child( + name: "SameTypeRequirement", + kind: .node(kind: "SameTypeRequirement") + ), + Child( + name: "ConformanceRequirement", + kind: .node(kind: "ConformanceRequirement") + ), + Child( + name: "LayoutRequirement", + kind: .node(kind: "LayoutRequirement") + ), + ]) + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // generic-where-clause -> 'where' requirement-list + Node( + name: "GenericWhereClause", + nameForDiagnostics: "'where' clause", + kind: "Syntax", + children: [ + Child( + name: "WhereKeyword", + kind: .token(choices: [.keyword(text: "where")]) + ), + Child( + name: "RequirementList", + kind: .collection(kind: "GenericRequirementList", collectionElementName: "Requirement") + ), + ] + ), + + // layout-requirement -> type-name : layout-constraint + // layout-constraint -> identifier '('? integer-literal? ','? integer-literal? ')'? + Node( + name: "LayoutRequirement", + nameForDiagnostics: "layout requirement", + kind: "Syntax", + children: [ + Child( + name: "TypeIdentifier", + kind: .node(kind: "Type"), + nameForDiagnostics: "constrained type" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "LayoutConstraint", + kind: .token(choices: [.keyword(text: "_Trivial"), .keyword(text: "_TrivialAtMost"), .keyword(text: "_UnknownLayout"), .keyword(text: "_RefCountedObject"), .keyword(text: "_NativeRefCountedObject"), .keyword(text: "_Class"), .keyword(text: "_NativeClass")]) + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), + isOptional: true + ), + Child( + name: "Size", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), + nameForDiagnostics: "size", + isOptional: true + ), + Child( + name: "Comma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + Child( + name: "Alignment", + kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), + nameForDiagnostics: "alignment", + isOptional: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]), + isOptional: true + ), + ] + ), + + // primary-associated-type-clause -> '<' primary-associated-type-list '>' + Node( + name: "PrimaryAssociatedTypeClause", + nameForDiagnostics: "primary associated type clause", + kind: "Syntax", + children: [ + Child( + name: "LeftAngleBracket", + kind: .token(choices: [.token(tokenKind: "LeftAngleToken")]) + ), + Child( + name: "PrimaryAssociatedTypeList", + kind: .collection(kind: "PrimaryAssociatedTypeList", collectionElementName: "PrimaryAssociatedType") + ), + Child( + name: "RightAngleBracket", + kind: .token(choices: [.token(tokenKind: "RightAngleToken")]) + ), + ] + ), + + Node( + name: "PrimaryAssociatedTypeList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "PrimaryAssociatedType" + ), + + // primary-associated-type -> type-name ','? + Node( + name: "PrimaryAssociatedType", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "name" + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // same-type-requirement -> type-identifier == type + Node( + name: "SameTypeRequirement", + nameForDiagnostics: "same type requirement", + kind: "Syntax", + children: [ + Child( + name: "LeftTypeIdentifier", + kind: .node(kind: "Type"), + nameForDiagnostics: "left-hand type" + ), + Child( + name: "EqualityToken", + kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]) + ), + Child( + name: "RightTypeIdentifier", + kind: .node(kind: "Type"), + nameForDiagnostics: "right-hand type" + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift.gyb deleted file mode 100644 index ef26a4ef6d3..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From GenericNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let GENERIC_NODES: [Node] = [ -% for node in sorted(GENERIC_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift b/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift new file mode 100644 index 00000000000..6c62a7e3f13 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift @@ -0,0 +1,177 @@ +//// Automatically Generated From PatternNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let PATTERN_NODES: [Node] = [ + // expr-pattern -> expr + Node( + name: "ExpressionPattern", + nameForDiagnostics: "pattern", + kind: "Pattern", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ) + ] + ), + // identifier-pattern -> identifier + Node( + name: "IdentifierPattern", + nameForDiagnostics: "pattern", + kind: "Pattern", + children: [ + Child( + name: "Identifier", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")]) + ) + ] + ), + + // is-type-pattern -> 'is' type + Node( + name: "IsTypePattern", + nameForDiagnostics: "'is' pattern", + kind: "Pattern", + children: [ + Child( + name: "IsKeyword", + kind: .token(choices: [.keyword(text: "is")]) + ), + Child( + name: "Type", + kind: .node(kind: "Type") + ), + ] + ), + + // tuple-pattern-element-list -> tuple-pattern-element + // tuple-pattern-element-list? + Node( + name: "TuplePatternElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "TuplePatternElement" + ), + + // tuple-pattern-element -> identifier? ':' pattern ','? + Node( + name: "TuplePatternElement", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "LabelName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "label", + isOptional: true + ), + Child( + name: "LabelColon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // tuple-pattern -> '(' tuple-pattern-element-list ')' + Node( + name: "TuplePattern", + nameForDiagnostics: "tuple pattern", + kind: "Pattern", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Elements", + kind: .collection(kind: "TuplePatternElementList", collectionElementName: "Element") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // type-annotation -> ':' type + Node( + name: "TypeAnnotation", + nameForDiagnostics: "type annotation", + kind: "Syntax", + children: [ + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Type", + kind: .node(kind: "Type") + ), + ] + ), + + // value-binding-pattern -> 'let' pattern + // | 'var' pattern + // | 'inout' pattern + Node( + name: "ValueBindingPattern", + nameForDiagnostics: "value binding pattern", + kind: "Pattern", + children: [ + Child( + name: "BindingKeyword", + kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")]) + ), + Child( + name: "ValuePattern", + kind: .node(kind: "Pattern") + ), + ] + ), + + // wildcard-pattern -> '_' type-annotation? + Node( + name: "WildcardPattern", + nameForDiagnostics: "wildcard pattern", + kind: "Pattern", + children: [ + Child( + name: "Wildcard", + kind: .token(choices: [.token(tokenKind: "WildcardToken")]) + ), + Child( + name: "TypeAnnotation", + kind: .node(kind: "TypeAnnotation"), + isOptional: true + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift.gyb deleted file mode 100644 index 652b650c757..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/PatternNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From PatternNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let PATTERN_NODES: [Node] = [ -% for node in sorted(PATTERN_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift new file mode 100644 index 00000000000..e1aaf0be5b8 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift @@ -0,0 +1,610 @@ +//// Automatically Generated From StmtNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let STMT_NODES: [Node] = [ + // availability-condition -> '#available' '(' availability-spec ')' + Node( + name: "AvailabilityCondition", + nameForDiagnostics: "availability condition", + kind: "Syntax", + children: [ + Child( + name: "AvailabilityKeyword", + kind: .token(choices: [.token(tokenKind: "PoundAvailableToken"), .token(tokenKind: "PoundUnavailableToken")]) + ), + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "AvailabilitySpec", + kind: .collection(kind: "AvailabilitySpecList", collectionElementName: "AvailabilityArgument") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // break-stmt -> 'break' identifier? ';'? + Node( + name: "BreakStmt", + nameForDiagnostics: "'break' statement", + kind: "Stmt", + children: [ + Child( + name: "BreakKeyword", + kind: .token(choices: [.keyword(text: "break")], requiresTrailingSpace: false) + ), + Child( + name: "Label", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "label", + isOptional: true + ), + ] + ), + + // case-item-list -> case-item case-item-list? + Node( + name: "CaseItemList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "CaseItem" + ), + + // catch-clause-list -> catch-clause catch-clause-list? + Node( + name: "CatchClauseList", + nameForDiagnostics: "'catch' clause", + kind: "SyntaxCollection", + element: "CatchClause" + ), + + // catch-clause 'catch' case-item-list? code-block + Node( + name: "CatchClause", + nameForDiagnostics: "'catch' clause", + kind: "Syntax", + traits: [ + "WithCodeBlock" + ], + parserFunction: "parseCatchClause", + children: [ + Child( + name: "CatchKeyword", + kind: .token(choices: [.keyword(text: "catch")]) + ), + Child( + name: "CatchItems", + kind: .collection(kind: "CatchItemList", collectionElementName: "CatchItem"), + isOptional: true + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock") + ), + ] + ), + + // catch-item-list -> catch-item catch-item-list? + Node( + name: "CatchItemList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "CatchItem" + ), + + // catch-item -> pattern? where-clause? ','? + Node( + name: "CatchItem", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Pattern", + kind: .node(kind: "Pattern"), + isOptional: true + ), + Child( + name: "WhereClause", + kind: .node(kind: "WhereClause"), + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // condition-list -> condition + // | condition ','? condition-list + Node( + name: "ConditionElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "ConditionElement" + ), + + // condition -> expression + // | availability-condition + // | case-condition + // | optional-binding-condition + Node( + name: "ConditionElement", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "Condition", + kind: .nodeChoices(choices: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + Child( + name: "Availability", + kind: .node(kind: "AvailabilityCondition") + ), + Child( + name: "MatchingPattern", + kind: .node(kind: "MatchingPatternCondition") + ), + Child( + name: "OptionalBinding", + kind: .node(kind: "OptionalBindingCondition") + ), + ]) + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // continue-stmt -> 'continue' label? ';'? + Node( + name: "ContinueStmt", + nameForDiagnostics: "'continue' statement", + kind: "Stmt", + children: [ + Child( + name: "ContinueKeyword", + kind: .token(choices: [.keyword(text: "continue")]) + ), + Child( + name: "Label", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "label", + isOptional: true + ), + ] + ), + + // defer-stmt -> 'defer' code-block ';'? + Node( + name: "DeferStmt", + nameForDiagnostics: "'defer' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "DeferKeyword", + kind: .token(choices: [.keyword(text: "defer")]) + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock") + ), + ] + ), + + // do-stmt -> identifier? ':'? 'do' code-block catch-clause-list ';'? + Node( + name: "DoStmt", + nameForDiagnostics: "'do' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "DoKeyword", + kind: .token(choices: [.keyword(text: "do")]) + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + nameForDiagnostics: "body" + ), + Child( + name: "CatchClauses", + kind: .collection(kind: "CatchClauseList", collectionElementName: "CatchClause"), + isOptional: true + ), + ] + ), + + // expr-stmt -> expression ';'? + Node( + name: "ExpressionStmt", + nameForDiagnostics: "expression", + kind: "Stmt", + children: [ + Child( + name: "Expression", + kind: .node(kind: "Expr") + ) + ] + ), + + // fallthrough-stmt -> 'fallthrough' ';'? + Node( + name: "FallthroughStmt", + nameForDiagnostics: "'fallthrough' statement", + kind: "Stmt", + children: [ + Child( + name: "FallthroughKeyword", + kind: .token(choices: [.keyword(text: "fallthrough")]) + ) + ] + ), + + // for-in-stmt -> label? ':'? + // 'for' 'try'? 'await'? 'case'? pattern 'in' expr 'where'? + // expr code-block ';'? + Node( + name: "ForInStmt", + nameForDiagnostics: "'for' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "ForKeyword", + kind: .token(choices: [.keyword(text: "for")]) + ), + Child( + name: "TryKeyword", + kind: .node(kind: "TryToken"), + isOptional: true + ), + Child( + name: "AwaitKeyword", + kind: .token(choices: [.keyword(text: "await")]), + isOptional: true, + classification: "Keyword" + ), + Child( + name: "CaseKeyword", + kind: .node(kind: "CaseToken"), + isOptional: true + ), + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "TypeAnnotation", + kind: .node(kind: "TypeAnnotation"), + isOptional: true + ), + Child( + name: "InKeyword", + kind: .token(choices: [.keyword(text: "in")]) + ), + Child( + name: "SequenceExpr", + kind: .node(kind: "Expr") + ), + Child( + name: "WhereClause", + kind: .node(kind: "WhereClause"), + isOptional: true + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + nameForDiagnostics: "body" + ), + ] + ), + + // forget-stmt -> 'forget' expr ';'? + Node( + name: "ForgetStmt", + nameForDiagnostics: "'forget' statement", + kind: "Stmt", + children: [ + Child( + name: "ForgetKeyword", + kind: .token(choices: [.keyword(text: "_forget")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + // guard-stmt -> 'guard' condition-list 'else' code-block ';'? + Node( + name: "GuardStmt", + nameForDiagnostics: "'guard' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "GuardKeyword", + kind: .token(choices: [.keyword(text: "guard")]) + ), + Child( + name: "Conditions", + kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition"), + nameForDiagnostics: "condition" + ), + Child( + name: "ElseKeyword", + kind: .token(choices: [.keyword(text: "else")]) + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + nameForDiagnostics: "body" + ), + ] + ), + + // labeled-stmt -> label ':' stmt + Node( + name: "LabeledStmt", + nameForDiagnostics: "labeled statement", + kind: "Stmt", + children: [ + Child( + name: "LabelName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), + nameForDiagnostics: "label name" + ), + Child( + name: "LabelColon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "Statement", + kind: .node(kind: "Stmt") + ), + ] + ), + + Node( + name: "MatchingPatternCondition", + nameForDiagnostics: "pattern matching", + kind: "Syntax", + children: [ + Child( + name: "CaseKeyword", + kind: .token(choices: [.keyword(text: "case")]) + ), + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "TypeAnnotation", + kind: .node(kind: "TypeAnnotation"), + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "InitializerClause") + ), + ] + ), + + Node( + name: "OptionalBindingCondition", + nameForDiagnostics: "optional binding", + kind: "Syntax", + children: [ + Child( + name: "BindingKeyword", + kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")]) + ), + Child( + name: "Pattern", + kind: .node(kind: "Pattern") + ), + Child( + name: "TypeAnnotation", + kind: .node(kind: "TypeAnnotation"), + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "InitializerClause"), + isOptional: true + ), + ] + ), + + // repeat-while-stmt -> label? ':'? 'repeat' code-block 'while' expr ';'? + Node( + name: "RepeatWhileStmt", + nameForDiagnostics: "'repeat' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "RepeatKeyword", + kind: .token(choices: [.keyword(text: "repeat")]) + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock"), + nameForDiagnostics: "body" + ), + Child( + name: "WhileKeyword", + kind: .token(choices: [.keyword(text: "while")]) + ), + Child( + name: "Condition", + kind: .node(kind: "Expr"), + nameForDiagnostics: "condition" + ), + ] + ), + + // return-stmt -> 'return' expr? ';'? + Node( + name: "ReturnStmt", + nameForDiagnostics: "'return' statement", + kind: "Stmt", + children: [ + Child( + name: "ReturnKeyword", + kind: .token(choices: [.keyword(text: "return")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr"), + isOptional: true + ), + ] + ), + + // throw-stmt -> 'throw' expr ';'? + Node( + name: "ThrowStmt", + nameForDiagnostics: "'throw' statement", + kind: "Stmt", + children: [ + Child( + name: "ThrowKeyword", + kind: .token(choices: [.keyword(text: "throw")]) + ), + Child( + name: "Expression", + kind: .node(kind: "Expr") + ), + ] + ), + + Node( + name: "WhereClause", + nameForDiagnostics: "'where' clause", + kind: "Syntax", + children: [ + Child( + name: "WhereKeyword", + kind: .token(choices: [.keyword(text: "where")]) + ), + Child( + name: "GuardResult", + kind: .node(kind: "Expr") + ), + ] + ), + + // while-stmt -> label? ':'? 'while' condition-list code-block ';'? + Node( + name: "WhileStmt", + nameForDiagnostics: "'while' statement", + kind: "Stmt", + traits: [ + "WithCodeBlock" + ], + children: [ + Child( + name: "WhileKeyword", + kind: .token(choices: [.keyword(text: "while")]) + ), + Child( + name: "Conditions", + kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition") + ), + Child( + name: "Body", + kind: .node(kind: "CodeBlock") + ), + ] + ), + + Node( + name: "YieldList", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "ElementList", + kind: .collection(kind: "YieldExprList", collectionElementName: "Element") + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + + // yield-stmt -> 'yield' '('? expr-list? ')'? + Node( + name: "YieldStmt", + nameForDiagnostics: "'yield' statement", + kind: "Stmt", + children: [ + Child( + name: "YieldKeyword", + kind: .token(choices: [.keyword(text: "yield")]) + ), + Child( + name: "Yields", + kind: .nodeChoices(choices: [ + Child( + name: "YieldList", + kind: .node(kind: "YieldList") + ), + Child( + name: "SimpleYield", + kind: .node(kind: "Expr") + ), + ]) + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift.gyb deleted file mode 100644 index b7efd70d3e4..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/StmtNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From StmtNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let STMT_NODES: [Node] = [ -% for node in sorted(STMT_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/SyntaxBaseKinds.swift b/CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift similarity index 100% rename from CodeGeneration/Sources/SyntaxSupport/gyb_generated/SyntaxBaseKinds.swift rename to CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift diff --git a/CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift.gyb deleted file mode 100644 index 48b4961b6ef..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/SyntaxBaseKinds.swift.gyb +++ /dev/null @@ -1,25 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS - # -*- mode: Swift -*- - # Ignore the following admonition; it applies to the resulting .swift file only -}% -//// Automatically Generated From SyntaxBaseKinds.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let SYNTAX_BASE_KINDS: [String] = [ -% for name in SYNTAX_BASE_KINDS: - "${name}", -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift b/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift similarity index 98% rename from CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift rename to CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift index 033c35e19b9..26f9e1d4767 100644 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/TokenSpec.swift +++ b/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift @@ -107,7 +107,7 @@ public class PoundObjectLiteralSpec: PoundKeywordSpec { } } -public class PoundConfigSpec: PoundKeywordSpec { } +public class PoundConfigSpec: PoundKeywordSpec {} public class PoundDirectiveKeywordSpec: PoundKeywordSpec { init( @@ -164,9 +164,9 @@ public class PunctuatorSpec: TokenSpec { } } -public class LiteralSpec: TokenSpec { } +public class LiteralSpec: TokenSpec {} -public class MiscSpec: TokenSpec { } +public class MiscSpec: TokenSpec {} public let SYNTAX_TOKENS: [TokenSpec] = [ PunctuatorSpec(name: "Arrow", kind: "arrow", text: "->", requiresLeadingSpace: true, requiresTrailingSpace: true), diff --git a/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift.gyb deleted file mode 100644 index 56c203218ae..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/TokenSpec.swift.gyb +++ /dev/null @@ -1,222 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_syntax_support.Token import * - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From Tokens.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -/// Represents the specification for a Token in the TokenSyntax file. -public class TokenSpec { - public let name: String - public let kind: String - public let nameForDiagnostics: String - public let unprefixedKind: String - public let text: String? - public let classification: SyntaxClassification? - public let isKeyword: Bool - public let requiresLeadingSpace: Bool - public let requiresTrailingSpace: Bool - public let associatedValueClass: String? - - public var swiftKind: String { - let name = lowercaseFirstWord(name: self.name) - - if isKeyword { - return name + "Keyword" - } else { - return name - } - } - - init( - name: String, - kind: String, - nameForDiagnostics: String, - unprefixedKind: String? = nil, - text: String? = nil, - classification: String = "None", - isKeyword: Bool = false, - requiresLeadingSpace: Bool = false, - requiresTrailingSpace: Bool = false, - associatedValueClass: String? = nil - ) { - self.name = name - self.kind = kind - self.nameForDiagnostics = nameForDiagnostics - if let unprefixedKind = unprefixedKind { - self.unprefixedKind = unprefixedKind - } else { - self.unprefixedKind = kind - } - self.text = text - self.classification = classificationByName(classification) - self.isKeyword = isKeyword - self.requiresLeadingSpace = requiresLeadingSpace - self.requiresTrailingSpace = requiresTrailingSpace - self.associatedValueClass = associatedValueClass - } -} - -public class PoundKeywordSpec: TokenSpec { - init( - name: String, - kind: String, - nameForDiagnostics: String? = nil, - text: String, - classification: String = "Keyword" - ) { - super.init( - name: name, - kind: "pound_\(kind)", - nameForDiagnostics: nameForDiagnostics ?? text, - unprefixedKind: kind, - text: text, - classification: classification, - isKeyword: true, - requiresTrailingSpace: true - ) - } -} - -public class PoundObjectLiteralSpec: PoundKeywordSpec { - let `protocol`: String - - init( - name: String, - kind: String, - text: String, - classification: String = "ObjectLiteral", - nameForDiagnostics: String, - `protocol`: String - ) { - self.`protocol` = `protocol` - super.init( - name: name, - kind: kind, - nameForDiagnostics: nameForDiagnostics, - text: text, - classification: classification - ) - } -} - -public class PoundConfigSpec: PoundKeywordSpec { } - -public class PoundDirectiveKeywordSpec: PoundKeywordSpec { - init( - name: String, - kind: String, - text: String, - classification: String = "PoundDirectiveKeyword" - ) { - super.init( - name: name, - kind: kind, - text: text, - classification: classification - ) - } -} - -public class PoundConditionalDirectiveKeywordSpec: PoundDirectiveKeywordSpec { - override init( - name: String, - kind: String, - text: String, - classification: String = "PoundDirectiveKeyword" - ) { - super.init( - name: name, - kind: kind, - text: text, - classification: classification - ) - } -} - -public class PunctuatorSpec: TokenSpec { - init( - name: String, - kind: String, - text: String, - classification: String = "None", - requiresLeadingSpace: Bool = false, - requiresTrailingSpace: Bool = false - ) { - super.init( - name: name, - kind: kind, - nameForDiagnostics: text, - unprefixedKind: nil, - text: text, - classification: classification, - isKeyword: false, - requiresLeadingSpace: requiresLeadingSpace, - requiresTrailingSpace: requiresTrailingSpace - ) - } -} - -public class LiteralSpec: TokenSpec { } - -public class MiscSpec: TokenSpec { } - -public let SYNTAX_TOKENS: [TokenSpec] = [ -% for token in sorted(SYNTAX_TOKENS, key=lambda x: x.name): -% class_name = type(token).__name__ -% classification = "classification: \"%s\"" % token.classification.name if token.classification.name not in ['None', 'Keyword', 'ObjectLiteral', 'PoundDirectiveKeyword'] or class_name == 'Misc' and token.classification.name != 'None' else None -% parameters = ["name: \"%s\"" % token.name] -% if class_name in ['Keyword', 'SwiftKeyword', 'DeclKeyword', 'StmtKeyword', 'ExprKeyword', 'PatternKeyword', 'SilKeyword']: -% parameters += ["text: \"%s\"" % token.text] -% elif class_name in ['PoundKeyword', 'PoundConfig', 'PoundDirectiveKeyword', 'PoundConditionalDirectiveKeyword']: -% parameters += ["kind: \"%s\"" % token.kind, "text: \"%s\"" % token.text] -% elif class_name in ['Punctuator', 'Misc', 'Literal']: -% parameters += ["kind: \"%s\"" % token.kind] -% if class_name != 'Punctuator': -% parameters += ["nameForDiagnostics: \"%s\"" % token.name_for_diagnostics] -% end -% if token.text: -% parameters += ["text: \"%s\"" % token.text] -% end -% if classification: -% parameters += [classification] -% end -% elif class_name == 'PoundObjectLiteral': -% parameters += ["kind: \"%s\"" % token.kind, "text: \"%s\"" % token.text] -% if classification: -% parameters += [classification] -% end -% parameters += ["nameForDiagnostics: \"%s\"" % token.name_for_diagnostics, "protocol: \"%s\"" % token.protocol] -% else: -% print("Unknown token `%s`", (token.name), file=sys.stderr) -% sys.exit(1) -% end -% if class_name in ['Keyword', 'SwiftKeyword', 'DeclKeyword', 'StmtKeyword', 'ExprKeyword', 'PatternKeyword', 'SilKeyword', 'Punctuator', 'Misc', 'Literal']: -% if token.requires_leading_space: -% parameters += ['requiresLeadingSpace: true'] -% end -% if token.requires_trailing_space: -% parameters += ['requiresTrailingSpace: true'] -% end -% end -% if token.associated_value_class: -% parameters += [f'associatedValueClass: "{token.associated_value_class}"'] -% end - ${class_name}Spec(${", ".join(parameters)}), -% end -] - -public let SYNTAX_TOKEN_MAP = Dictionary(uniqueKeysWithValues: SYNTAX_TOKENS.map { ("\($0.name)Token", $0) }) diff --git a/CodeGeneration/Sources/SyntaxSupport/Traits.swift b/CodeGeneration/Sources/SyntaxSupport/Traits.swift new file mode 100644 index 00000000000..697e273ee20 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/Traits.swift @@ -0,0 +1,103 @@ +//// Automatically Generated From Traits.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public class Trait { + public let traitName: String + public let children: [Child] + public let description: String? + + init(traitName: String, children: [Child], description: String? = nil) { + self.traitName = traitName + self.children = children + self.description = description + } +} + +public let TRAITS: [Trait] = [ + Trait( + traitName: "Attributed", + children: [ + Child(name: "Attributes", kind: .node(kind: "AttributeList"), isOptional: true) + ] + ), + Trait( + traitName: "Braced", + children: [ + Child(name: "LeftBrace", kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), + Child(name: "RightBrace", kind: .token(choices: [.token(tokenKind: "RightBraceToken")])), + ] + ), + Trait( + traitName: "DeclGroup", + children: [ + Child(name: "Attributes", kind: .node(kind: "AttributeList"), isOptional: true), + Child(name: "Modifiers", kind: .node(kind: "ModifierList"), isOptional: true), + Child(name: "Members", kind: .node(kind: "MemberDeclBlock")), + ] + ), + Trait( + traitName: "EffectSpecifiers", + children: [ + Child(name: "UnexpectedBeforeAsyncSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), + Child(name: "AsyncSpecifier", kind: .token(choices: [.token(tokenKind: "KeywordToken")]), isOptional: true), + Child(name: "UnexpectedBetweenAsyncSpecifierAndThrowsSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), + Child(name: "ThrowsSpecifier", kind: .token(choices: [.token(tokenKind: "KeywordToken")]), isOptional: true), + Child(name: "UnexpectedAfterThrowsSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), + ] + ), + Trait( + traitName: "FreestandingMacroExpansion", + children: [ + Child(name: "PoundToken", kind: .token(choices: [.token(tokenKind: "PoundToken")])), + Child(name: "Macro", kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), + Child(name: "GenericArguments", kind: .node(kind: "GenericArgumentClause"), isOptional: true), + Child(name: "LeftParen", kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), isOptional: true), + Child(name: "ArgumentList", kind: .node(kind: "TupleExprElementList")), + Child(name: "RightParen", kind: .token(choices: [.token(tokenKind: "RightParenToken")]), isOptional: true), + Child(name: "TrailingClosure", kind: .node(kind: "ClosureExpr"), isOptional: true), + Child(name: "AdditionalTrailingClosures", kind: .node(kind: "MultipleTrailingClosureElementList"), isOptional: true), + ] + ), + Trait( + traitName: "IdentifiedDecl", + children: [ + Child(name: "Identifier", kind: .token(choices: [.token(tokenKind: "IdentifierToken")])) + ] + ), + Trait( + traitName: "Parenthesized", + children: [ + Child(name: "LeftParen", kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), + Child(name: "RightParen", kind: .token(choices: [.token(tokenKind: "RightParenToken")])), + ] + ), + Trait( + traitName: "WithCodeBlock", + children: [ + Child(name: "Body", kind: .node(kind: "CodeBlock")) + ] + ), + Trait( + traitName: "WithStatements", + children: [ + Child(name: "Statements", kind: .node(kind: "CodeBlockItemList")) + ] + ), + Trait( + traitName: "WithTrailingComma", + children: [ + Child(name: "TrailingComma", kind: .token(choices: [.token(tokenKind: "CommaToken")]), isOptional: true) + ] + ), +] diff --git a/CodeGeneration/Sources/SyntaxSupport/Traits.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/Traits.swift.gyb deleted file mode 100644 index e2d1b0fd14a..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/Traits.swift.gyb +++ /dev/null @@ -1,50 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_syntax_support.Traits import * - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From Traits.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public class Trait { - public let traitName: String - public let children: [Child] - public let description: String? - - init(traitName: String, children: [Child], description: String? = nil) { - self.traitName = traitName - self.children = children - self.description = description - } -} - -public let TRAITS: [Trait] = [ -% for trait in sorted(TRAITS, key=lambda x: x.trait_name): - Trait(traitName: "${trait.trait_name}", - children: [ -% for child in trait.children: -% is_optional = ", isOptional: true" if child.is_optional else "" -% description = ", description: %s" % child.description if child.description else "" -% if child.syntax_kind.endswith('Token'): -% kind = f'.token(choices: [.token(tokenKind: "{child.syntax_kind}")])' -% else: -% kind = f'.node(kind: "{child.syntax_kind}")' -% end - Child(name: "${child.name}", kind: ${kind}${is_optional}${description}), -% end - ${"],\n description: %s" % trait.description if trait.description else " ]"} - ), -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/Trivia.swift b/CodeGeneration/Sources/SyntaxSupport/Trivia.swift new file mode 100644 index 00000000000..915d8eaa7da --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/Trivia.swift @@ -0,0 +1,205 @@ +//// Automatically Generated From Trivia.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public class Trivia { + public let name: String + public let comment: String + public let characters: [Character] + public let swiftCharacters: [Character] + public let isNewLine: Bool + public let isComment: Bool + + public var lowerName: String { lowercaseFirstWord(name: name) } + + public var enumCaseName: String { + if self.isCollection { + if lowerName == "backslash" { + return "backslashes" + } else { + return "\(lowerName)s" + } + } else { + return lowerName + } + } + + public var charactersLen: Int { characters.count } + + public var isCollection: Bool { charactersLen > 0 } + + init( + name: String, + comment: String, + characters: [Character] = [], + swiftCharacters: [Character] = [], + isNewLine: Bool = false, + isComment: Bool = false + ) { + self.name = name + self.comment = comment + self.isNewLine = isNewLine + self.isComment = isComment + self.characters = characters + + // Swift sometimes doesn't support escaped characters like \f or \v; + // we should allow specifying alternatives explicitly. + if !swiftCharacters.isEmpty { + self.swiftCharacters = swiftCharacters + } else { + self.swiftCharacters = characters + } + } +} + +public let TRIVIAS: [Trivia] = [ + Trivia( + name: "Backslash", + comment: #"A backslash that is at the end of a line in a multi-line string literal to escape the newline."#, + characters: [ + Character("\\") + ], + swiftCharacters: [ + Character("\\") + ] + ), + + Trivia( + name: "BlockComment", + comment: #"A developer block comment, starting with '/*' and ending with '*/'."#, + isComment: true + ), + + Trivia( + name: "CarriageReturn", + comment: #"A newline '\r' character."#, + characters: [ + Character("\r") + ], + swiftCharacters: [ + Character("\r") + ], + isNewLine: true + ), + + Trivia( + name: "CarriageReturnLineFeed", + comment: #"A newline consists of contiguous '\r' and '\n' characters."#, + characters: [ + Character("\r"), + Character("\n"), + ], + swiftCharacters: [ + Character("\r"), + Character("\n"), + ], + isNewLine: true + ), + + Trivia( + name: "DocBlockComment", + comment: #"A documentation block comment, starting with '/**' and ending with '*/'."#, + isComment: true + ), + + Trivia( + name: "DocLineComment", + comment: #"A documentation line comment, starting with '///'."#, + isComment: true + ), + + // Swift don't support form feed '\f' so we use the raw unicode + Trivia( + name: "Formfeed", + comment: #"A form-feed 'f' character."#, + characters: [ + Character("\u{c}") + ], + swiftCharacters: [ + Character("\u{240C}") + ] + ), + + Trivia( + name: "LineComment", + comment: #"A developer line comment, starting with '//'"#, + isComment: true + ), + + Trivia( + name: "Newline", + comment: #"A newline '\n' character."#, + characters: [ + Character("\n") + ], + swiftCharacters: [ + Character("\n") + ], + isNewLine: true + ), + + Trivia( + name: "Pound", + comment: #"A '#' that is at the end of a line in a multi-line string literal to escape the newline."#, + characters: [ + Character("#") + ], + swiftCharacters: [ + Character("#") + ] + ), + + Trivia( + name: "Shebang", + comment: #"A script command, starting with '#!'."# + ), + + Trivia( + name: "Space", + comment: #"A space ' ' character."#, + characters: [ + Character(" ") + ], + swiftCharacters: [ + Character(" ") + ] + ), + + Trivia( + name: "Tab", + comment: #"A tab '\t' character."#, + characters: [ + Character("\t") + ], + swiftCharacters: [ + Character("\t") + ] + ), + + Trivia( + name: "UnexpectedText", + comment: #"Any skipped unexpected text."# + ), + + // Swift don't support vertical tab '\v' so we use the raw unicode + Trivia( + name: "VerticalTab", + comment: #"A vertical tab '\v' character."#, + characters: [ + Character("\u{b}") + ], + swiftCharacters: [ + Character("\u{2B7F}") + ] + ), +] diff --git a/CodeGeneration/Sources/SyntaxSupport/Trivia.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/Trivia.swift.gyb deleted file mode 100644 index 1754ca8aaa2..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/Trivia.swift.gyb +++ /dev/null @@ -1,92 +0,0 @@ -%{ - from gyb_syntax_support import * - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From Trivia.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public class Trivia { - public let name: String - public let comment: String - public let characters: [Character] - public let swiftCharacters: [Character] - public let isNewLine: Bool - public let isComment: Bool - - public var lowerName: String { lowercaseFirstWord(name: name) } - - public var enumCaseName: String { - if self.isCollection { - if lowerName == "backslash" { - return "backslashes" - } else { - return "\(lowerName)s" - } - } else { - return lowerName - } - } - - public var charactersLen: Int { characters.count } - - public var isCollection: Bool { charactersLen > 0 } - - init(name: String, - comment: String, - characters: [Character] = [], - swiftCharacters: [Character] = [], - isNewLine: Bool = false, - isComment: Bool = false){ - self.name = name - self.comment = comment - self.isNewLine = isNewLine - self.isComment = isComment - self.characters = characters - - // Swift sometimes doesn't support escaped characters like \f or \v; - // we should allow specifying alternatives explicitly. - if !swiftCharacters.isEmpty { - self.swiftCharacters = swiftCharacters - } else { - self.swiftCharacters = characters - } - } -} - -public let TRIVIAS: [Trivia] = [ -% for trivia in sorted(TRIVIAS, key=lambda x: x.name): -% parameters = [ -% 'name: "%s"' % trivia.name, -% 'comment: #"%s"#' % trivia.comment, -% ] -% if trivia.characters: -% spaces = 11 -% mapped_characters = list(map(lambda x: (' ' * spaces) + 'Character("%s")' % x, trivia.characters)) -% parameters += ['characters: [\n%s\n' % ',\n'.join(mapped_characters) + (' ' * (spaces - 2) + ']')] -% end -% if trivia.swift_characters: -% spaces = 10 -% mapped_swift_characters = list(map(lambda x: (' ' * spaces) + 'Character("%s")' % x, trivia.swift_characters)) -% parameters += ['swiftCharacters: [\n%s\n' % ',\n'.join(mapped_swift_characters) + (' ' * (spaces - 2) + ']')] -% end -% if trivia.is_new_line: -% parameters += ['isNewLine: true'] -% end -% if trivia.is_comment: -% parameters += ['isComment: true'] -% end - Trivia(${",\n ".join(parameters)}), -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift new file mode 100644 index 00000000000..e62b580dc72 --- /dev/null +++ b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift @@ -0,0 +1,493 @@ +//// Automatically Generated From GenericNodes.swift.gyb. +//// Do Not Edit Directly! +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +public let TYPE_NODES: [Node] = [ + // array-type -> '[' type ']' + Node( + name: "ArrayType", + nameForDiagnostics: "array type", + kind: "Type", + children: [ + Child( + name: "LeftSquareBracket", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "ElementType", + kind: .node(kind: "Type") + ), + Child( + name: "RightSquareBracket", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + // attributed-type -> type-specifier? attribute-list? type + // type-specifier -> 'inout' | 'borrowing' | 'consuming' | '__owned' | '__shared' + Node( + name: "AttributedType", + nameForDiagnostics: "type", + kind: "Type", + traits: [ + "Attributed" + ], + children: [ + Child( + name: "Specifier", + kind: .token(choices: [.keyword(text: "inout"), .keyword(text: "__shared"), .keyword(text: "__owned"), .keyword(text: "isolated"), .keyword(text: "_const"), .keyword(text: "borrowing"), .keyword(text: "consuming")]), + isOptional: true + ), + Child( + name: "Attributes", + kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), + isOptional: true + ), + Child( + name: "BaseType", + kind: .node(kind: "Type") + ), + ] + ), + // class-restriction-type -> 'class' + Node( + name: "ClassRestrictionType", + nameForDiagnostics: nil, + kind: "Type", + children: [ + Child( + name: "ClassKeyword", + kind: .token(choices: [.keyword(text: "class")]) + ) + ] + ), + + // composition-typeelement-list -> composition-type-element + // composition-type-element-list? + Node( + name: "CompositionTypeElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "CompositionTypeElement" + ), + + // composition-type-element -> type '&' + Node( + name: "CompositionTypeElement", + nameForDiagnostics: nil, + kind: "Syntax", + children: [ + Child( + name: "Type", + kind: .node(kind: "Type") + ), + Child( + name: "Ampersand", + kind: .node(kind: "Token"), + isOptional: true + ), + ] + ), + + // composition-type -> composition-type-element-list + Node( + name: "CompositionType", + nameForDiagnostics: "type composition", + kind: "Type", + children: [ + Child( + name: "Elements", + kind: .collection(kind: "CompositionTypeElementList", collectionElementName: "Element") + ) + ] + ), + + // constrained-sugar-type -> ('some'|'any') type + Node( + name: "ConstrainedSugarType", + nameForDiagnostics: "type", + kind: "Type", + children: [ + Child( + name: "SomeOrAnySpecifier", + kind: .token(choices: [.keyword(text: "some"), .keyword(text: "any")]) + ), + Child( + name: "BaseType", + kind: .node(kind: "Type") + ), + ] + ), + + // dictionary-type -> '[' type ':' type ']' + Node( + name: "DictionaryType", + nameForDiagnostics: "dictionary type", + kind: "Type", + children: [ + Child( + name: "LeftSquareBracket", + kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")]) + ), + Child( + name: "KeyType", + kind: .node(kind: "Type"), + nameForDiagnostics: "key type" + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]) + ), + Child( + name: "ValueType", + kind: .node(kind: "Type"), + nameForDiagnostics: "value type" + ), + Child( + name: "RightSquareBracket", + kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")]) + ), + ] + ), + + // throwing-specifier -> 'throws' | 'rethrows' + // function-type -> attribute-list '(' function-type-argument-list ')' + // type-effect-specifiers? return-clause + Node( + name: "FunctionType", + nameForDiagnostics: "function type", + kind: "Type", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Arguments", + kind: .collection(kind: "TupleTypeElementList", collectionElementName: "Argument"), + isIndented: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + Child( + name: "EffectSpecifiers", + kind: .node(kind: "TypeEffectSpecifiers"), + isOptional: true + ), + Child( + name: "Output", + kind: .node(kind: "ReturnClause") + ), + ] + ), + + // generic-argument-clause -> '<' generic-argument-list '>' + Node( + name: "GenericArgumentClause", + nameForDiagnostics: "generic argument clause", + kind: "Syntax", + children: [ + Child( + name: "LeftAngleBracket", + kind: .token(choices: [.token(tokenKind: "LeftAngleToken")]) + ), + Child( + name: "Arguments", + kind: .collection(kind: "GenericArgumentList", collectionElementName: "Argument") + ), + Child( + name: "RightAngleBracket", + kind: .token(choices: [.token(tokenKind: "RightAngleToken")]) + ), + ] + ), + + // generic-argument-list -> generic-argument generic-argument-list? + Node( + name: "GenericArgumentList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "GenericArgument" + ), + + // A generic argument. + // Dictionary + // ^~~~ ^~~~~~ + Node( + name: "GenericArgument", + nameForDiagnostics: "generic argument", + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "ArgumentType", + kind: .node(kind: "Type") + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // implicitly-unwrapped-optional-type -> type '!' + Node( + name: "ImplicitlyUnwrappedOptionalType", + nameForDiagnostics: "implicitly unwrapped optional type", + kind: "Type", + children: [ + Child( + name: "WrappedType", + kind: .node(kind: "Type") + ), + Child( + name: "ExclamationMark", + kind: .token(choices: [.token(tokenKind: "ExclamationMarkToken")]) + ), + ] + ), + + // member-type-identifier -> type '.' identifier generic-argument-clause? + Node( + name: "MemberTypeIdentifier", + nameForDiagnostics: "member type", + kind: "Type", + children: [ + Child( + name: "BaseType", + kind: .node(kind: "Type"), + nameForDiagnostics: "base type" + ), + Child( + name: "Period", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]) + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")]), + nameForDiagnostics: "name", + classification: "TypeIdentifier" + ), + Child( + name: "GenericArgumentClause", + kind: .node(kind: "GenericArgumentClause"), + isOptional: true + ), + ] + ), + // metatype-type -> type '.' 'Type' + // | type '.' 'Protocol + Node( + name: "MetatypeType", + nameForDiagnostics: "metatype", + kind: "Type", + children: [ + Child( + name: "BaseType", + kind: .node(kind: "Type"), + nameForDiagnostics: "base type" + ), + Child( + name: "Period", + kind: .token(choices: [.token(tokenKind: "PeriodToken")]) + ), + Child( + name: "TypeOrProtocol", + kind: .token(choices: [.keyword(text: "Type"), .keyword(text: "Protocol")]) + ), + ] + ), + + // named-opaque-return-type -> generic-argument-clause type + Node( + name: "NamedOpaqueReturnType", + nameForDiagnostics: "named opaque return type", + kind: "Type", + children: [ + Child( + name: "GenericParameters", + kind: .node(kind: "GenericParameterClause") + ), + Child( + name: "BaseType", + kind: .node(kind: "Type") + ), + ] + ), + + // optional-type -> type '?' + Node( + name: "OptionalType", + nameForDiagnostics: "optional type", + kind: "Type", + children: [ + Child( + name: "WrappedType", + kind: .node(kind: "Type") + ), + Child( + name: "QuestionMark", + kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken")]) + ), + ] + ), + + // pack-expansion-type -> type '...' + Node( + name: "PackExpansionType", + nameForDiagnostics: "variadic expansion", + kind: "Type", + children: [ + Child( + name: "RepeatKeyword", + kind: .token(choices: [.keyword(text: "repeat")]) + ), + Child( + name: "PatternType", + kind: .node(kind: "Type") + ), + ] + ), + + // pack-reference-type -> 'each' type + Node( + name: "PackReferenceType", + nameForDiagnostics: "pack reference", + kind: "Type", + children: [ + Child( + name: "EachKeyword", + kind: .token(choices: [.keyword(text: "each")]) + ), + Child( + name: "PackType", + kind: .node(kind: "Type") + ), + ] + ), + + // simple-type-identifier -> identifier generic-argument-clause? + Node( + name: "SimpleTypeIdentifier", + nameForDiagnostics: "type", + kind: "Type", + children: [ + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "WildcardToken")]), + classification: "TypeIdentifier" + ), + Child( + name: "GenericArgumentClause", + kind: .node(kind: "GenericArgumentClause"), + isOptional: true + ), + ] + ), + + // tuple-type-element-list -> tuple-type-element tuple-type-element-list? + Node( + name: "TupleTypeElementList", + nameForDiagnostics: nil, + kind: "SyntaxCollection", + element: "TupleTypeElement" + ), + + // tuple-type-element -> identifier? ':'? type-annotation ','? + Node( + name: "TupleTypeElement", + nameForDiagnostics: nil, + kind: "Syntax", + traits: [ + "WithTrailingComma" + ], + children: [ + Child( + name: "InOut", + kind: .node(kind: "InoutToken"), + isOptional: true + ), + Child( + name: "Name", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "name", + isOptional: true + ), + Child( + name: "SecondName", + kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), + nameForDiagnostics: "internal name", + isOptional: true + ), + Child( + name: "Colon", + kind: .token(choices: [.token(tokenKind: "ColonToken")]), + isOptional: true + ), + Child( + name: "Type", + kind: .node(kind: "Type") + ), + Child( + name: "Ellipsis", + kind: .token(choices: [.token(tokenKind: "EllipsisToken")]), + isOptional: true + ), + Child( + name: "Initializer", + kind: .node(kind: "InitializerClause"), + isOptional: true + ), + Child( + name: "TrailingComma", + kind: .token(choices: [.token(tokenKind: "CommaToken")]), + isOptional: true + ), + ] + ), + + // tuple-type -> '(' tuple-type-element-list ')' + Node( + name: "TupleType", + nameForDiagnostics: "tuple type", + kind: "Type", + traits: [ + "Parenthesized" + ], + children: [ + Child( + name: "LeftParen", + kind: .token(choices: [.token(tokenKind: "LeftParenToken")]) + ), + Child( + name: "Elements", + kind: .collection(kind: "TupleTypeElementList", collectionElementName: "Element"), + isIndented: true + ), + Child( + name: "RightParen", + kind: .token(choices: [.token(tokenKind: "RightParenToken")]) + ), + ] + ), + +] diff --git a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift.gyb b/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift.gyb deleted file mode 100644 index b76c0968735..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/TypeNodes.swift.gyb +++ /dev/null @@ -1,26 +0,0 @@ -%{ - from gyb_syntax_support import * - from gyb_helpers import make_swift_child, make_swift_node - # -*- mode: Swift -*- - # Ignore the following admonition it applies to the resulting .swift file only -}% -//// Automatically Generated From GenericNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let TYPE_NODES: [Node] = [ -% for node in sorted(TYPE_NODES, key=lambda x: x.name): - ${make_swift_node(node)}, - -% end -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift deleted file mode 100644 index b5627e4ecca..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AttributeNodes.swift +++ /dev/null @@ -1,552 +0,0 @@ -//// Automatically Generated From AttributeNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let ATTRIBUTE_NODES: [Node] = [ - Node(name: "AttributeList", - nameForDiagnostics: "attributes", - kind: "SyntaxCollection", - element: "Syntax", - elementName: "Attribute", - elementChoices: ["Attribute", "IfConfigDecl"], - omitWhenEmpty: true), - - Node(name: "Attribute", - nameForDiagnostics: "attribute", - description: "An `@` attribute.", - kind: "Syntax", - parserFunction: "parseAttribute", - children: [ - Child(name: "AtSignToken", - kind: .token(choices: [.token(tokenKind: "AtSignToken")]), - description: "The `@` sign."), - Child(name: "AttributeName", - kind: .node(kind: "Type"), - nameForDiagnostics: "name", - description: "The name of the attribute.", - classification: "Attribute"), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - description: "If the attribute takes arguments, the opening parenthesis.", - isOptional: true), - Child(name: "Argument", - kind: .nodeChoices(choices: [ - Child(name: "ArgumentList", - kind: .node(kind: "TupleExprElementList")), - Child(name: "Token", - kind: .node(kind: "Token")), - Child(name: "String", - kind: .node(kind: "StringLiteralExpr")), - Child(name: "Availability", - kind: .node(kind: "AvailabilitySpecList")), - Child(name: "SpecializeArguments", - kind: .node(kind: "SpecializeAttributeSpecList")), - Child(name: "ObjCName", - kind: .node(kind: "ObjCSelector")), - Child(name: "ImplementsArguments", - kind: .node(kind: "ImplementsAttributeArguments")), - Child(name: "DifferentiableArguments", - kind: .node(kind: "DifferentiableAttributeArguments")), - Child(name: "DerivativeRegistrationArguments", - kind: .node(kind: "DerivativeRegistrationAttributeArguments")), - Child(name: "BackDeployedArguments", - kind: .node(kind: "BackDeployedAttributeSpecList")), - Child(name: "ConventionArguments", - kind: .node(kind: "ConventionAttributeArguments")), - Child(name: "ConventionWitnessMethodArguments", - kind: .node(kind: "ConventionWitnessMethodAttributeArguments")), - Child(name: "OpaqueReturnTypeOfAttributeArguments", - kind: .node(kind: "OpaqueReturnTypeOfAttributeArguments")), - Child(name: "ExposeAttributeArguments", - kind: .node(kind: "ExposeAttributeArguments")), - Child(name: "OriginallyDefinedInArguments", - kind: .node(kind: "OriginallyDefinedInArguments")), - Child(name: "UnderscorePrivateAttributeArguments", - kind: .node(kind: "UnderscorePrivateAttributeArguments")), - Child(name: "DynamicReplacementArguments", - kind: .node(kind: "DynamicReplacementArguments")), - Child(name: "UnavailableFromAsyncArguments", - kind: .node(kind: "UnavailableFromAsyncArguments")), - Child(name: "EffectsArguments", - kind: .node(kind: "EffectsArguments")), - Child(name: "DocumentationArguments", - kind: .node(kind: "DocumentationAttributeArguments")) - ]), - description: "The arguments of the attribute. In case the attribute takes multiple arguments, they are gather in the appropriate takes first.", - isOptional: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - description: "If the attribute takes arguments, the closing parenthesis.", - isOptional: true) - ]), - - Node(name: "AvailabilityEntry", - nameForDiagnostics: "availability entry", - description: "The availability argument for the _specialize attribute", - kind: "Syntax", - children: [ - Child(name: "Label", - kind: .token(choices: [.keyword(text: "availability")]), - nameForDiagnostics: "label", - description: "The label of the argument"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating the label and the value"), - Child(name: "AvailabilityList", - kind: .collection(kind: "AvailabilitySpecList", collectionElementName: "Availability")), - Child(name: "Semicolon", - kind: .token(choices: [.token(tokenKind: "SemicolonToken")])) - ]), - - Node(name: "AvailabilityVersionRestrictionListEntry", - nameForDiagnostics: "version", - description: "A single platform/version pair in an attribute, e.g. `iOS 10.1`.", - kind: "Syntax", - children: [ - Child(name: "AvailabilityVersionRestriction", - kind: .node(kind: "AvailabilityVersionRestriction"), - classification: "Keyword"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "A trailing comma if the argument is followed by another argument", - isOptional: true) - ]), - - Node(name: "AvailabilityVersionRestrictionList", - nameForDiagnostics: "version list", - kind: "SyntaxCollection", - element: "AvailabilityVersionRestrictionListEntry"), - - Node(name: "BackDeployedAttributeSpecList", - nameForDiagnostics: "'@backDeployed' arguments", - description: "A collection of arguments for the `@backDeployed` attribute", - kind: "Syntax", - children: [ - Child(name: "BeforeLabel", - kind: .token(choices: [.keyword(text: "before")]), - description: "The \"before\" label."), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating \"before\" and the parameter list."), - Child(name: "VersionList", - kind: .collection(kind: "AvailabilityVersionRestrictionList", collectionElementName: "Availability"), - description: "The list of OS versions in which the declaration became ABI stable.") - ]), - - Node(name: "ConventionAttributeArguments", - nameForDiagnostics: "@convention(...) arguments", - description: "The arguments for the '@convention(...)'.", - kind: "Syntax", - children: [ - Child(name: "ConventionLabel", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - description: "The convention label."), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true), - Child(name: "CTypeLabel", - kind: .token(choices: [.keyword(text: "cType")]), - isOptional: true), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "CTypeString", - kind: .node(kind: "StringLiteralExpr"), - isOptional: true) - ]), - - Node(name: "ConventionWitnessMethodAttributeArguments", - nameForDiagnostics: "@convention(...) arguments for witness methods", - description: "The arguments for the '@convention(witness_method: ...)'.", - kind: "Syntax", - children: [ - Child(name: "WitnessMethodLabel", - kind: .token(choices: [.keyword(text: "witness_method")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "ProtocolName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])) - ]), - - Node(name: "DeclName", - nameForDiagnostics: "declaration name", - kind: "Syntax", - children: [ - Child(name: "DeclBaseName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "PrefixOperatorToken"), .keyword(text: "init")]), - nameForDiagnostics: "base name", - description: "The base name of the protocol's requirement."), - Child(name: "DeclNameArguments", - kind: .node(kind: "DeclNameArguments"), - nameForDiagnostics: "arguments", - description: "The argument labels of the protocol's requirement if it is a function requirement.", - isOptional: true) - ]), - - Node(name: "DerivativeRegistrationAttributeArguments", - nameForDiagnostics: "attribute arguments", - description: "The arguments for the '@derivative(of:)' and '@transpose(of:)' attributes: the 'of:' label, the original declaration name, and an optional differentiability parameter list.", - kind: "Syntax", - children: [ - Child(name: "OfLabel", - kind: .token(choices: [.keyword(text: "of")]), - description: "The \"of\" label."), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating the \"of\" label and the original declaration name."), - Child(name: "OriginalDeclName", - kind: .node(kind: "QualifiedDeclName"), - description: "The referenced original declaration name."), - Child(name: "Period", - kind: .token(choices: [.token(tokenKind: "PeriodToken")]), - description: "The period separating the original declaration name and the accessor name.", - isOptional: true), - Child(name: "AccessorKind", - kind: .token(choices: [.keyword(text: "get"), .keyword(text: "set")]), - description: "The accessor name.", - isOptional: true), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true), - Child(name: "DiffParams", - kind: .node(kind: "DifferentiabilityParamsClause"), - isOptional: true) - ]), - - Node(name: "DifferentiabilityParamList", - nameForDiagnostics: "differentiability parameters", - kind: "SyntaxCollection", - element: "DifferentiabilityParam"), - - Node(name: "DifferentiabilityParam", - nameForDiagnostics: "differentiability parameter", - description: "A differentiability parameter: either the \"self\" identifier, a function parameter name, or a function parameter index.", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Parameter", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "IntegerLiteralToken"), .token(tokenKind: "KeywordToken")])), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "DifferentiabilityParamsClause", - nameForDiagnostics: "'@differentiable' argument", - description: "A clause containing differentiability parameters.", - kind: "Syntax", - children: [ - Child(name: "WrtLabel", - kind: .token(choices: [.keyword(text: "wrt")]), - description: "The \"wrt\" label."), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating \"wrt\" and the parameter list."), - Child(name: "Parameters", - kind: .nodeChoices(choices: [ - Child(name: "Parameter", - kind: .node(kind: "DifferentiabilityParam")), - Child(name: "ParameterList", - kind: .node(kind: "DifferentiabilityParams")) - ]), - nameForDiagnostics: "parameters") - ]), - - Node(name: "DifferentiabilityParams", - nameForDiagnostics: "differentiability parameters", - description: "The differentiability parameters.", - kind: "Syntax", - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "DiffParams", - kind: .collection(kind: "DifferentiabilityParamList", collectionElementName: "DifferentiabilityParam"), - description: "The parameters for differentiation."), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "DifferentiableAttributeArguments", - nameForDiagnostics: "'@differentiable' arguments", - description: "The arguments for the `@differentiable` attribute: an optional differentiability kind, an optional differentiability parameter clause, and an optional 'where' clause.", - kind: "Syntax", - children: [ - Child(name: "DiffKind", - kind: .token(choices: [.keyword(text: "forward"), .keyword(text: "reverse"), .keyword(text: "linear")]), - isOptional: true), - Child(name: "DiffKindComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "The comma following the differentiability kind, if it exists.", - isOptional: true), - Child(name: "DiffParams", - kind: .node(kind: "DifferentiabilityParamsClause"), - isOptional: true), - Child(name: "DiffParamsComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "The comma following the differentiability parameters clause, if it exists.", - isOptional: true), - Child(name: "WhereClause", - kind: .node(kind: "GenericWhereClause"), - isOptional: true) - ]), - - Node(name: "DocumentationAttributeArgument", - nameForDiagnostics: "@_documentation argument", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Label", - kind: .token(choices: [.keyword(text: "visibility"), .keyword(text: "metadata")]), - nameForDiagnostics: "label"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Value", - kind: .nodeChoices(choices: [ - Child(name: "Token", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")])), - Child(name: "String", - kind: .node(kind: "StringLiteralExpr")) - ])), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "A trailing comma if this argument is followed by another one", - isOptional: true) - ]), - - Node(name: "DocumentationAttributeArguments", - nameForDiagnostics: "@_documentation arguments", - description: "The arguments of the '@_documentation' attribute", - kind: "SyntaxCollection", - element: "DocumentationAttributeArgument"), - - Node(name: "DynamicReplacementArguments", - nameForDiagnostics: "@_dynamicReplacement argument", - description: "The arguments for the '@_dynamicReplacement' attribute", - kind: "Syntax", - children: [ - Child(name: "ForLabel", - kind: .token(choices: [.keyword(text: "for")], requiresTrailingSpace: false)), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Declname", - kind: .node(kind: "DeclName")) - ]), - - Node(name: "EffectsArguments", - nameForDiagnostics: "@_effects arguments", - description: "The arguments of the '@_effect' attribute. These will be parsed during the SIL stage.", - kind: "SyntaxCollection", - element: "Token"), - - Node(name: "ExposeAttributeArguments", - nameForDiagnostics: "@_expose arguments", - description: "The arguments for the '@_expose' attribute", - kind: "Syntax", - children: [ - Child(name: "Language", - kind: .node(kind: "Token")), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true), - Child(name: "CxxName", - kind: .node(kind: "StringLiteralExpr"), - isOptional: true) - ]), - - Node(name: "ImplementsAttributeArguments", - nameForDiagnostics: "@_implements arguemnts", - description: "The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`", - kind: "Syntax", - children: [ - Child(name: "Type", - kind: .node(kind: "Type"), - nameForDiagnostics: "type", - description: "The type for which the method with this attribute implements a requirement."), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "The comma separating the type and method name"), - Child(name: "DeclBaseName", - kind: .node(kind: "Token"), - nameForDiagnostics: "declaration base name", - description: "The base name of the protocol's requirement."), - Child(name: "DeclNameArguments", - kind: .node(kind: "DeclNameArguments"), - nameForDiagnostics: "declaration name arguments", - description: "The argument labels of the protocol's requirement if it is a function requirement.", - isOptional: true) - ]), - - Node(name: "LabeledSpecializeEntry", - nameForDiagnostics: "attribute argument", - description: "A labeled argument for the `@_specialize` attribute like `exported: true`", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Label", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .keyword(text: "available"), .keyword(text: "exported"), .keyword(text: "kind"), .keyword(text: "spi"), .keyword(text: "spiModule")]), - nameForDiagnostics: "label", - description: "The label of the argument"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating the label and the value"), - Child(name: "Value", - kind: .node(kind: "Token"), - nameForDiagnostics: "value", - description: "The value for this argument"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "A trailing comma if this argument is followed by another one", - isOptional: true) - ]), - - Node(name: "ObjCSelectorPiece", - nameForDiagnostics: "Objective-C selector piece", - description: "A piece of an Objective-C selector. Either consisting of just an identifier for a nullary selector, an identifier and a colon for a labeled argument or just a colon for an unlabeled argument", - kind: "Syntax", - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name", - isOptional: true), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true) - ]), - - Node(name: "ObjCSelector", - nameForDiagnostics: "Objective-C selector", - kind: "SyntaxCollection", - element: "ObjCSelectorPiece"), - - Node(name: "OpaqueReturnTypeOfAttributeArguments", - nameForDiagnostics: "opaque return type arguments", - description: "The arguments for the '@_opaqueReturnTypeOf()'.", - kind: "Syntax", - children: [ - Child(name: "MangledName", - kind: .node(kind: "StringLiteralExpr"), - description: "The mangled name of a declaration."), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")])), - Child(name: "Ordinal", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), - description: "The ordinal corresponding to the 'some' keyword that introduced this opaque type.") - ]), - - Node(name: "OriginallyDefinedInArguments", - nameForDiagnostics: "@_originallyDefinedIn arguments", - description: "The arguments for the '@_originallyDefinedIn' attribute", - kind: "Syntax", - children: [ - Child(name: "ModuleLabel", - kind: .token(choices: [.keyword(text: "module")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "ModuleName", - kind: .node(kind: "StringLiteralExpr")), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")])), - Child(name: "Platforms", - kind: .collection(kind: "AvailabilityVersionRestrictionList", collectionElementName: "Platform")) - ]), - - Node(name: "QualifiedDeclName", - nameForDiagnostics: "declaration name", - description: "An optionally qualified function declaration name (e.g. `+(_:_:)`, `A.B.C.foo(_:_:)`).", - kind: "Syntax", - children: [ - Child(name: "BaseType", - kind: .node(kind: "Type"), - nameForDiagnostics: "base type", - description: "The base type of the qualified name, optionally specified.", - isOptional: true), - Child(name: "Dot", - kind: .token(choices: [.token(tokenKind: "PeriodToken")]), - isOptional: true), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]), - nameForDiagnostics: "base name", - description: "The base name of the referenced function."), - Child(name: "Arguments", - kind: .node(kind: "DeclNameArguments"), - nameForDiagnostics: "arguments", - description: "The argument labels of the referenced function, optionally specified.", - isOptional: true) - ]), - - Node(name: "SpecializeAttributeSpecList", - nameForDiagnostics: "argument to '@_specialize", - description: "A collection of arguments for the `@_specialize` attribute", - kind: "SyntaxCollection", - element: "Syntax", - elementName: "SpecializeAttribute", - elementChoices: ["LabeledSpecializeEntry", "AvailabilityEntry", "TargetFunctionEntry", "GenericWhereClause"]), - - Node(name: "TargetFunctionEntry", - nameForDiagnostics: "attribute argument", - description: "A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Label", - kind: .token(choices: [.keyword(text: "target")]), - nameForDiagnostics: "label", - description: "The label of the argument"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating the label and the value"), - Child(name: "Declname", - kind: .node(kind: "DeclName"), - nameForDiagnostics: "declaration name", - description: "The value for this argument"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "A trailing comma if this argument is followed by another one", - isOptional: true) - ]), - - Node(name: "UnavailableFromAsyncArguments", - nameForDiagnostics: "@_unavailableFromAsync argument", - description: "The arguments for the '@_unavailableFromAsync' attribute", - kind: "Syntax", - children: [ - Child(name: "MessageLabel", - kind: .token(choices: [.keyword(text: "message")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Message", - kind: .node(kind: "StringLiteralExpr")) - ]), - - Node(name: "UnderscorePrivateAttributeArguments", - nameForDiagnostics: "@_private argument", - description: "The arguments for the '@_private' attribute", - kind: "Syntax", - children: [ - Child(name: "SourceFileLabel", - kind: .token(choices: [.keyword(text: "sourceFile")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Filename", - kind: .node(kind: "StringLiteralExpr")) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift deleted file mode 100644 index f7780ab00fd..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/AvailabilityNodes.swift +++ /dev/null @@ -1,99 +0,0 @@ -//// Automatically Generated From AvailabilityNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let AVAILABILITY_NODES: [Node] = [ - Node(name: "AvailabilityArgument", - nameForDiagnostics: "availability argument", - description: "A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.", - kind: "Syntax", - children: [ - Child(name: "Entry", - kind: .nodeChoices(choices: [ - Child(name: "Token", - kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "IdentifierToken")], requiresLeadingSpace: false, requiresTrailingSpace: false)), - Child(name: "AvailabilityVersionRestriction", - kind: .node(kind: "AvailabilityVersionRestriction")), - Child(name: "AvailabilityLabeledArgument", - kind: .node(kind: "AvailabilityLabeledArgument")) - ]), - description: "The actual argument"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "A trailing comma if the argument is followed by another argument", - isOptional: true) - ]), - - Node(name: "AvailabilityLabeledArgument", - nameForDiagnostics: "availability argument", - description: "A argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.", - kind: "Syntax", - children: [ - Child(name: "Label", - kind: .token(choices: [.keyword(text: "message"), .keyword(text: "renamed"), .keyword(text: "introduced"), .keyword(text: "obsoleted"), .keyword(text: "deprecated")]), - nameForDiagnostics: "label", - description: "The label of the argument"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - description: "The colon separating label and value"), - Child(name: "Value", - kind: .nodeChoices(choices: [ - Child(name: "String", - kind: .node(kind: "StringLiteralExpr")), - Child(name: "Version", - kind: .node(kind: "VersionTuple")) - ]), - nameForDiagnostics: "value", - description: "The value of this labeled argument") - ]), - - Node(name: "AvailabilitySpecList", - nameForDiagnostics: "'@availability' arguments", - kind: "SyntaxCollection", - element: "AvailabilityArgument"), - - Node(name: "AvailabilityVersionRestriction", - nameForDiagnostics: "version restriction", - description: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.", - kind: "Syntax", - children: [ - Child(name: "Platform", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "platform", - description: "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.", - classification: "Keyword"), - Child(name: "Version", - kind: .node(kind: "VersionTuple"), - nameForDiagnostics: "version", - isOptional: true) - ]), - - Node(name: "VersionTuple", - nameForDiagnostics: "version tuple", - description: "A version number of the form major.minor.patch in which the minor and patch part may be omitted.", - kind: "Syntax", - children: [ - Child(name: "MajorMinor", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken"), .token(tokenKind: "FloatingLiteralToken")]), - description: "In case the version consists only of the major version, an integer literal that specifies the major version. In case the version consists of major and minor version number, a floating literal in which the decimal part is interpreted as the minor version."), - Child(name: "PatchPeriod", - kind: .token(choices: [.token(tokenKind: "PeriodToken")]), - description: "If the version contains a patch number, the period separating the minor from the patch number.", - isOptional: true), - Child(name: "PatchVersion", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), - description: "The patch version if specified.", - isOptional: true) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift deleted file mode 100644 index 8890f23b827..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/CommonNodes.swift +++ /dev/null @@ -1,159 +0,0 @@ -//// Automatically Generated From CommonNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let COMMON_NODES: [Node] = [ - Node(name: "CodeBlockItemList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "CodeBlockItem", - elementsSeparatedByNewline: true), - - Node(name: "CodeBlockItem", - nameForDiagnostics: nil, - description: "A CodeBlockItem is any Syntax node that appears on its own line inside a CodeBlock.", - kind: "Syntax", - children: [ - Child(name: "Item", - kind: .nodeChoices(choices: [ - Child(name: "Decl", - kind: .node(kind: "Decl")), - Child(name: "Stmt", - kind: .node(kind: "Stmt")), - Child(name: "Expr", - kind: .node(kind: "Expr")) - ]), - description: "The underlying node inside the code block."), - Child(name: "Semicolon", - kind: .token(choices: [.token(tokenKind: "SemicolonToken")]), - description: "If present, the trailing semicolon at the end of the item.", - isOptional: true) - ], - omitWhenEmpty: true), - - Node(name: "CodeBlock", - nameForDiagnostics: "code block", - kind: "Syntax", - traits: [ - "Braced", - "WithStatements" - ], - children: [ - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "Statements", - kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), - nameForDiagnostics: "statements", - isIndented: true), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), - requiresLeadingNewline: true) - ]), - - Node(name: "DeclEffectSpecifiers", - nameForDiagnostics: "effect specifiers", - kind: "Syntax", - traits: [ - "EffectSpecifiers" - ], - children: [ - Child(name: "AsyncSpecifier", - kind: .token(choices: [.keyword(text: "async"), .keyword(text: "reasync")]), - isOptional: true), - Child(name: "ThrowsSpecifier", - kind: .token(choices: [.keyword(text: "throws"), .keyword(text: "rethrows")]), - isOptional: true) - ]), - - Node(name: "Decl", - nameForDiagnostics: "declaration", - kind: "Syntax", - parserFunction: "parseDeclaration"), - - Node(name: "Expr", - nameForDiagnostics: "expression", - kind: "Syntax", - parserFunction: "parseExpression"), - - Node(name: "MissingDecl", - nameForDiagnostics: "declaration", - kind: "Decl", - traits: [ - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - isOptional: true), - Child(name: "Modifiers", - kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), - isOptional: true) - ]), - - Node(name: "MissingExpr", - nameForDiagnostics: "expression", - kind: "Expr"), - - Node(name: "MissingPattern", - nameForDiagnostics: "pattern", - kind: "Pattern"), - - Node(name: "MissingStmt", - nameForDiagnostics: "statement", - kind: "Stmt"), - - Node(name: "Missing", - nameForDiagnostics: nil, - kind: "Syntax"), - - Node(name: "MissingType", - nameForDiagnostics: "type", - kind: "Type"), - - Node(name: "Pattern", - nameForDiagnostics: "pattern", - kind: "Syntax", - parserFunction: "parsePattern"), - - Node(name: "Stmt", - nameForDiagnostics: "statement", - kind: "Syntax", - parserFunction: "parseStatement"), - - Node(name: "TypeEffectSpecifiers", - nameForDiagnostics: "effect specifiers", - kind: "Syntax", - traits: [ - "EffectSpecifiers" - ], - children: [ - Child(name: "AsyncSpecifier", - kind: .token(choices: [.keyword(text: "async")]), - isOptional: true), - Child(name: "ThrowsSpecifier", - kind: .token(choices: [.keyword(text: "throws")]), - isOptional: true) - ]), - - Node(name: "Type", - nameForDiagnostics: "type", - kind: "Syntax", - parserFunction: "parseType"), - - Node(name: "UnexpectedNodes", - nameForDiagnostics: nil, - description: "A collection of syntax nodes that occurred in the source code but could not be used to form a valid syntax tree.", - kind: "SyntaxCollection", - element: "Syntax"), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift deleted file mode 100644 index e49de3788a1..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/DeclNodes.swift +++ /dev/null @@ -1,1224 +0,0 @@ -//// Automatically Generated From DeclNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let DECL_NODES: [Node] = [ - Node(name: "AccessPathComponent", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name"), - Child(name: "TrailingDot", - kind: .token(choices: [.token(tokenKind: "PeriodToken")]), - isOptional: true) - ]), - - Node(name: "AccessPath", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "AccessPathComponent"), - - Node(name: "AccessorBlock", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "Braced" - ], - children: [ - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "Accessors", - kind: .collection(kind: "AccessorList", collectionElementName: "Accessor"), - isIndented: true), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), - requiresLeadingNewline: true) - ]), - - Node(name: "AccessorDecl", - nameForDiagnostics: "accessor", - kind: "Decl", - traits: [ - "Attributed" - ], - parserFunction: "parseAccessorDecl", - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - isOptional: true), - Child(name: "Modifier", - kind: .node(kind: "DeclModifier"), - nameForDiagnostics: "modifiers", - isOptional: true), - Child(name: "AccessorKind", - kind: .token(choices: [.keyword(text: "get"), .keyword(text: "set"), .keyword(text: "didSet"), .keyword(text: "willSet"), .keyword(text: "unsafeAddress"), .keyword(text: "addressWithOwner"), .keyword(text: "addressWithNativeOwner"), .keyword(text: "unsafeMutableAddress"), .keyword(text: "mutableAddressWithOwner"), .keyword(text: "mutableAddressWithNativeOwner"), .keyword(text: "_read"), .keyword(text: "_modify")])), - Child(name: "Parameter", - kind: .node(kind: "AccessorParameter"), - nameForDiagnostics: "parameter", - isOptional: true), - Child(name: "EffectSpecifiers", - kind: .node(kind: "DeclEffectSpecifiers"), - isOptional: true), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - isOptional: true) - ]), - - Node(name: "AccessorList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "AccessorDecl", - elementsSeparatedByNewline: true), - - Node(name: "AccessorParameter", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name"), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "ActorDecl", - nameForDiagnostics: "actor", - kind: "Decl", - traits: [ - "DeclGroup", - "IdentifiedDecl", - "Attributed" - ], - 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: "ActorKeyword", - kind: .token(choices: [.keyword(text: "actor")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "type inheritance clause", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock")) - ]), - - Node(name: "AssociatedtypeDecl", - nameForDiagnostics: "associatedtype declaration", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - 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: "AssociatedtypeKeyword", - kind: .token(choices: [.keyword(text: "associatedtype")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "inheritance clause", - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "TypeInitializerClause"), - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true) - ]), - - Node(name: "ClassDecl", - nameForDiagnostics: "class", - kind: "Decl", - traits: [ - "DeclGroup", - "IdentifiedDecl", - "Attributed" - ], - 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: "ClassKeyword", - kind: .token(choices: [.keyword(text: "class")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "inheritance clause", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock")) - ]), - - Node(name: "DeclModifierDetail", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Detail", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .keyword(text: "set")])), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "DeclModifier", - nameForDiagnostics: "modifier", - kind: "Syntax", - children: [ - Child(name: "Name", - kind: .token(choices: [.keyword(text: "class"), .keyword(text: "convenience"), .keyword(text: "dynamic"), .keyword(text: "final"), .keyword(text: "infix"), .keyword(text: "lazy"), .keyword(text: "optional"), .keyword(text: "override"), .keyword(text: "postfix"), .keyword(text: "prefix"), .keyword(text: "required"), .keyword(text: "static"), .keyword(text: "unowned"), .keyword(text: "weak"), .keyword(text: "private"), .keyword(text: "fileprivate"), .keyword(text: "internal"), .keyword(text: "public"), .keyword(text: "open"), .keyword(text: "mutating"), .keyword(text: "nonmutating"), .keyword(text: "indirect"), .keyword(text: "__consuming"), .keyword(text: "borrowing"), .keyword(text: "consuming"), .keyword(text: "actor"), .keyword(text: "async"), .keyword(text: "distributed"), .keyword(text: "isolated"), .keyword(text: "nonisolated"), .keyword(text: "_const"), .keyword(text: "_local"), .keyword(text: "package")]), - classification: "Attribute"), - Child(name: "Detail", - kind: .node(kind: "DeclModifierDetail"), - isOptional: true) - ]), - - Node(name: "DeinitializerDecl", - nameForDiagnostics: "deinitializer", - kind: "Decl", - traits: [ - "Attributed" - ], - 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: "DeinitKeyword", - kind: .token(choices: [.keyword(text: "deinit")])), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - isOptional: true) - ]), - - Node(name: "DesignatedTypeElement", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "LeadingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")])), - Child(name: "Name", - kind: .node(kind: "Token")) - ]), - - Node(name: "DesignatedTypeList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "DesignatedTypeElement"), - - Node(name: "EditorPlaceholderDecl", - nameForDiagnostics: "editor placeholder", - kind: "Decl", - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])) - ]), - - Node(name: "EnumCaseDecl", - nameForDiagnostics: "enum case", - description: "A `case` declaration of a Swift `enum`. It can have 1 or more `EnumCaseElement`s inside, each declaring a different case of the enum.", - kind: "Decl", - traits: [ - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - description: "The attributes applied to the case declaration.", - isOptional: true), - Child(name: "Modifiers", - kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), - nameForDiagnostics: "modifiers", - description: "The declaration modifiers applied to the case declaration.", - isOptional: true), - Child(name: "CaseKeyword", - kind: .token(choices: [.keyword(text: "case")]), - description: "The `case` keyword for this case."), - Child(name: "Elements", - kind: .collection(kind: "EnumCaseElementList", collectionElementName: "Element"), - nameForDiagnostics: "elements", - description: "The elements this case declares.") - ]), - - Node(name: "EnumCaseElementList", - nameForDiagnostics: nil, - description: "A collection of 0 or more `EnumCaseElement`s.", - kind: "SyntaxCollection", - element: "EnumCaseElement"), - - Node(name: "EnumCaseElement", - nameForDiagnostics: nil, - description: "An element of an enum case, containing the name of the case and, optionally, either associated values or an assignment to a raw value.", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - description: "The name of this case."), - Child(name: "AssociatedValue", - kind: .node(kind: "ParameterClause"), - nameForDiagnostics: "associated values", - description: "The set of associated values of the case.", - isOptional: true), - Child(name: "RawValue", - kind: .node(kind: "InitializerClause"), - description: "The raw value of this enum element, if present.", - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - description: "The trailing comma of this element, if the case has multiple elements.", - isOptional: true) - ]), - - Node(name: "EnumDecl", - nameForDiagnostics: "enum", - description: "A Swift `enum` declaration.", - kind: "Decl", - traits: [ - "DeclGroup", - "IdentifiedDecl", - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - description: "The attributes applied to the enum declaration.", - isOptional: true), - Child(name: "Modifiers", - kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), - nameForDiagnostics: "modifiers", - description: "The declaration modifiers applied to the enum declaration.", - isOptional: true), - Child(name: "EnumKeyword", - kind: .token(choices: [.keyword(text: "enum")]), - description: "The `enum` keyword for this declaration."), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - description: "The name of this enum."), - Child(name: "GenericParameters", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - description: "The generic parameters, if any, for this enum.", - isOptional: true), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "inheritance clause", - description: "The inheritance clause describing conformances or raw values for this enum.", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - description: "The `where` clause that applies to the generic parameters of this enum.", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock"), - description: "The cases and other members of this enum.") - ]), - - Node(name: "ExtensionDecl", - nameForDiagnostics: "extension", - kind: "Decl", - traits: [ - "DeclGroup", - "Attributed" - ], - 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: "ExtensionKeyword", - kind: .token(choices: [.keyword(text: "extension")])), - Child(name: "ExtendedType", - kind: .node(kind: "Type")), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "inheritance clause", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock")) - ]), - - Node(name: "FunctionDecl", - nameForDiagnostics: "function", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - 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: "FuncKeyword", - kind: .token(choices: [.keyword(text: "func")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "Signature", - kind: .node(kind: "FunctionSignature"), - nameForDiagnostics: "function signature"), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - isOptional: true) - ]), - - Node(name: "FunctionParameterList", - nameForDiagnostics: "parameter list", - kind: "SyntaxCollection", - element: "FunctionParameter"), - - Node(name: "FunctionParameter", - nameForDiagnostics: "parameter", - kind: "Syntax", - traits: [ - "WithTrailingComma", - "Attributed" - ], - 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")]), - isOptional: true), - Child(name: "SecondName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "internal name", - isOptional: true), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "Type", - kind: .node(kind: "Type"), - nameForDiagnostics: "type", - isOptional: true), - Child(name: "Ellipsis", - kind: .token(choices: [.token(tokenKind: "EllipsisToken")]), - isOptional: true), - Child(name: "DefaultArgument", - kind: .node(kind: "InitializerClause"), - nameForDiagnostics: "default argument", - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "FunctionSignature", - nameForDiagnostics: "function signature", - kind: "Syntax", - children: [ - Child(name: "Input", - kind: .node(kind: "ParameterClause")), - Child(name: "EffectSpecifiers", - kind: .node(kind: "DeclEffectSpecifiers"), - isOptional: true), - Child(name: "Output", - kind: .node(kind: "ReturnClause"), - isOptional: true) - ]), - - Node(name: "IfConfigClauseList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "IfConfigClause"), - - Node(name: "IfConfigClause", - nameForDiagnostics: "conditional compilation clause", - kind: "Syntax", - children: [ - Child(name: "PoundKeyword", - kind: .token(choices: [.token(tokenKind: "PoundIfToken"), .token(tokenKind: "PoundElseifToken"), .token(tokenKind: "PoundElseToken")]), - classification: "BuildConfigId", - requiresLeadingNewline: true), - Child(name: "Condition", - kind: .node(kind: "Expr"), - nameForDiagnostics: "condition", - isOptional: true, - classification: "BuildConfigId"), - Child(name: "Elements", - kind: .nodeChoices(choices: [ - Child(name: "Statements", - kind: .node(kind: "CodeBlockItemList")), - Child(name: "SwitchCases", - kind: .node(kind: "SwitchCaseList")), - Child(name: "Decls", - kind: .node(kind: "MemberDeclList")), - Child(name: "PostfixExpression", - kind: .node(kind: "Expr")), - Child(name: "Attributes", - kind: .node(kind: "AttributeList")) - ]), - isOptional: true) - ]), - - Node(name: "IfConfigDecl", - nameForDiagnostics: "conditional compilation block", - kind: "Decl", - children: [ - Child(name: "Clauses", - kind: .collection(kind: "IfConfigClauseList", collectionElementName: "Clause")), - Child(name: "PoundEndif", - kind: .token(choices: [.token(tokenKind: "PoundEndifToken")]), - classification: "BuildConfigId", - requiresLeadingNewline: true) - ]), - - Node(name: "ImportDecl", - nameForDiagnostics: "import", - kind: "Decl", - traits: [ - "Attributed" - ], - 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: "ImportTok", - kind: .token(choices: [.keyword(text: "import")])), - Child(name: "ImportKind", - kind: .token(choices: [.keyword(text: "typealias"), .keyword(text: "struct"), .keyword(text: "class"), .keyword(text: "enum"), .keyword(text: "protocol"), .keyword(text: "var"), .keyword(text: "let"), .keyword(text: "func"), .keyword(text: "inout")]), - isOptional: true), - Child(name: "Path", - kind: .collection(kind: "AccessPath", collectionElementName: "PathComponent")) - ]), - - Node(name: "InheritedTypeList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "InheritedType"), - - Node(name: "InheritedType", - nameForDiagnostics: "inherited type", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "TypeName", - kind: .node(kind: "Type")), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "InitializerClause", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Equal", - kind: .token(choices: [.token(tokenKind: "EqualToken")])), - Child(name: "Value", - kind: .node(kind: "Expr")) - ]), - - Node(name: "InitializerDecl", - nameForDiagnostics: "initializer", - kind: "Decl", - traits: [ - "Attributed" - ], - 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: "InitKeyword", - kind: .token(choices: [.keyword(text: "init")])), - Child(name: "OptionalMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "InfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), - isOptional: true), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "Signature", - kind: .node(kind: "FunctionSignature"), - nameForDiagnostics: "function signature"), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - isOptional: true) - ]), - - Node(name: "MacroDecl", - nameForDiagnostics: "macro", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - 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: "MacroKeyword", - kind: .token(choices: [.keyword(text: "macro")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "Signature", - kind: .nodeChoices(choices: [ - Child(name: "FunctionLike", - kind: .node(kind: "FunctionSignature"), - nameForDiagnostics: "macro signature"), - Child(name: "ValueLike", - kind: .node(kind: "TypeAnnotation"), - nameForDiagnostics: "macro signature") - ]), - nameForDiagnostics: "macro signature"), - Child(name: "Definition", - kind: .node(kind: "InitializerClause"), - nameForDiagnostics: "macro definition", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true) - ]), - - Node(name: "MacroExpansionDecl", - nameForDiagnostics: "macro expansion", - kind: "Decl", - traits: [ - "FreestandingMacroExpansion" - ], - children: [ - Child(name: "PoundToken", - kind: .token(choices: [.token(tokenKind: "PoundToken")]), - description: "The `#` sign."), - Child(name: "Macro", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericArguments", - kind: .node(kind: "GenericArgumentClause"), - isOptional: true), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - isOptional: true), - Child(name: "ArgumentList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - isOptional: true), - Child(name: "TrailingClosure", - kind: .node(kind: "ClosureExpr"), - isOptional: true), - Child(name: "AdditionalTrailingClosures", - kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), - isOptional: true) - ]), - - Node(name: "MemberDeclBlock", - nameForDiagnostics: "member block", - kind: "Syntax", - traits: [ - "Braced" - ], - parserFunction: "parseMemberDeclList", - children: [ - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "Members", - kind: .collection(kind: "MemberDeclList", collectionElementName: "Member"), - isIndented: true), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), - requiresLeadingNewline: true) - ]), - - Node(name: "MemberDeclListItem", - nameForDiagnostics: nil, - description: "A member declaration of a type consisting of a declaration and an optional semicolon;", - kind: "Syntax", - children: [ - Child(name: "Decl", - kind: .node(kind: "Decl"), - description: "The declaration of the type member."), - Child(name: "Semicolon", - kind: .token(choices: [.token(tokenKind: "SemicolonToken")]), - description: "An optional trailing semicolon.", - isOptional: true) - ], - omitWhenEmpty: true), - - Node(name: "MemberDeclList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "MemberDeclListItem", - elementsSeparatedByNewline: true), - - Node(name: "ModifierList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "DeclModifier", - elementName: "Modifier", - omitWhenEmpty: true), - - Node(name: "OperatorDecl", - nameForDiagnostics: "operator declaration", - description: "A Swift `operator` declaration.", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - description: "The attributes applied to the 'operator' declaration.", - isOptional: true), - Child(name: "Modifiers", - kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), - nameForDiagnostics: "modifiers", - description: "The declaration modifiers applied to the 'operator' declaration.", - isOptional: true, - classification: "Attribute"), - Child(name: "OperatorKeyword", - kind: .token(choices: [.keyword(text: "operator")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")]), - classification: "OperatorIdentifier"), - Child(name: "OperatorPrecedenceAndTypes", - kind: .node(kind: "OperatorPrecedenceAndTypes"), - description: "Optionally specify a precedence group and designated types.", - isOptional: true) - ]), - - Node(name: "OperatorPrecedenceAndTypes", - nameForDiagnostics: nil, - description: "A clause to specify precedence group in infix operator declarations, and designated types in any operator declaration.", - kind: "Syntax", - children: [ - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "PrecedenceGroup", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "precedence group", - description: "The precedence group for this operator"), - Child(name: "DesignatedTypes", - kind: .collection(kind: "DesignatedTypeList", collectionElementName: "DesignatedTypeElement"), - description: "The designated types associated with this operator.") - ]), - - Node(name: "ParameterClause", - nameForDiagnostics: "parameter clause", - kind: "Syntax", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "ParameterList", - kind: .collection(kind: "FunctionParameterList", collectionElementName: "Parameter"), - nameForDiagnostics: "parameters", - isIndented: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "PatternBindingList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "PatternBinding"), - - Node(name: "PatternBinding", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "TypeAnnotation", - kind: .node(kind: "TypeAnnotation"), - nameForDiagnostics: "type annotation", - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "InitializerClause"), - isOptional: true), - Child(name: "Accessor", - kind: .nodeChoices(choices: [ - Child(name: "Accessors", - kind: .node(kind: "AccessorBlock")), - Child(name: "Getter", - kind: .node(kind: "CodeBlock")) - ]), - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "PoundSourceLocationArgs", - nameForDiagnostics: "'#sourceLocation' arguments", - kind: "Syntax", - children: [ - Child(name: "FileArgLabel", - kind: .token(choices: [.keyword(text: "file")])), - Child(name: "FileArgColon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "FileName", - kind: .node(kind: "StringLiteralExpr"), - nameForDiagnostics: "file name"), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")])), - Child(name: "LineArgLabel", - kind: .token(choices: [.keyword(text: "line")])), - Child(name: "LineArgColon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "LineNumber", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), - nameForDiagnostics: "line number") - ]), - - Node(name: "PoundSourceLocation", - nameForDiagnostics: "'#sourceLocation' directive", - kind: "Decl", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "PoundSourceLocation", - kind: .token(choices: [.token(tokenKind: "PoundSourceLocationToken")])), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Args", - kind: .node(kind: "PoundSourceLocationArgs"), - nameForDiagnostics: "arguments", - isOptional: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "PrecedenceGroupAssignment", - nameForDiagnostics: "'assignment' property of precedencegroup", - description: "Specifies the precedence of an operator when used in an operation that includes optional chaining.", - kind: "Syntax", - children: [ - Child(name: "AssignmentKeyword", - kind: .token(choices: [.keyword(text: "assignment")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Flag", - kind: .token(choices: [.keyword(text: "true"), .keyword(text: "false")]), - description: "When true, an operator in the corresponding precedence group uses the same grouping rules during optional chaining as the assignment operators from the standard library. Otherwise, operators in the precedence group follows the same optional chaining rules as operators that don't perform assignment.") - ]), - - Node(name: "PrecedenceGroupAssociativity", - nameForDiagnostics: "'associativity' property of precedencegroup", - description: "Specifies how a sequence of operators with the same precedence level are grouped together in the absence of grouping parentheses.", - kind: "Syntax", - children: [ - Child(name: "AssociativityKeyword", - kind: .token(choices: [.keyword(text: "associativity")]), - classification: "Keyword"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Value", - kind: .token(choices: [.keyword(text: "left"), .keyword(text: "right"), .keyword(text: "none")]), - description: "Operators that are `left`-associative group left-to-right. Operators that are `right`-associative group right-to-left. Operators that are specified with an associativity of `none` don't associate at all") - ]), - - Node(name: "PrecedenceGroupAttributeList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "Syntax", - elementName: "PrecedenceGroupAttribute", - elementChoices: ["PrecedenceGroupRelation", "PrecedenceGroupAssignment", "PrecedenceGroupAssociativity"]), - - Node(name: "PrecedenceGroupDecl", - nameForDiagnostics: "precedencegroup", - description: "A Swift `precedencegroup` declaration.", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - description: "The attributes applied to the 'precedencegroup' declaration.", - isOptional: true), - Child(name: "Modifiers", - kind: .collection(kind: "ModifierList", collectionElementName: "Modifier"), - nameForDiagnostics: "modifiers", - description: "The declaration modifiers applied to the 'precedencegroup' declaration.", - isOptional: true), - Child(name: "PrecedencegroupKeyword", - kind: .token(choices: [.keyword(text: "precedencegroup")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - description: "The name of this precedence group."), - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "GroupAttributes", - kind: .collection(kind: "PrecedenceGroupAttributeList", collectionElementName: "GroupAttribute"), - description: "The characteristics of this precedence group."), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")])) - ]), - - Node(name: "PrecedenceGroupNameElement", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "PrecedenceGroupNameList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "PrecedenceGroupNameElement"), - - Node(name: "PrecedenceGroupRelation", - nameForDiagnostics: "'relation' property of precedencegroup", - description: "Specify the new precedence group's relation to existing precedence groups.", - kind: "Syntax", - children: [ - Child(name: "HigherThanOrLowerThan", - kind: .token(choices: [.keyword(text: "higherThan"), .keyword(text: "lowerThan")]), - description: "The relation to specified other precedence groups.", - classification: "Keyword"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "OtherNames", - kind: .collection(kind: "PrecedenceGroupNameList", collectionElementName: "OtherName"), - description: "The name of other precedence group to which this precedence group relates.") - ]), - - Node(name: "ProtocolDecl", - nameForDiagnostics: "protocol", - kind: "Decl", - traits: [ - "DeclGroup", - "IdentifiedDecl", - "Attributed" - ], - 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: "ProtocolKeyword", - kind: .token(choices: [.keyword(text: "protocol")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "PrimaryAssociatedTypeClause", - kind: .node(kind: "PrimaryAssociatedTypeClause"), - nameForDiagnostics: "primary associated type clause", - isOptional: true), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "inheritance clause", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock")) - ]), - - Node(name: "ReturnClause", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Arrow", - kind: .token(choices: [.token(tokenKind: "ArrowToken")])), - Child(name: "ReturnType", - kind: .node(kind: "Type"), - nameForDiagnostics: "return type") - ]), - - Node(name: "SourceFile", - nameForDiagnostics: "source file", - kind: "Syntax", - traits: [ - "WithStatements" - ], - parserFunction: "parseSourceFile", - children: [ - Child(name: "Statements", - kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement")), - Child(name: "EOFToken", - kind: .node(kind: "EOFToken")) - ]), - - Node(name: "StructDecl", - nameForDiagnostics: "struct", - kind: "Decl", - traits: [ - "DeclGroup", - "IdentifiedDecl", - "Attributed" - ], - 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: "StructKeyword", - kind: .token(choices: [.keyword(text: "struct")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "InheritanceClause", - kind: .node(kind: "TypeInheritanceClause"), - nameForDiagnostics: "type inheritance clause", - isOptional: true), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Members", - kind: .node(kind: "MemberDeclBlock")) - ]), - - Node(name: "SubscriptDecl", - nameForDiagnostics: "subscript", - kind: "Decl", - traits: [ - "Attributed" - ], - 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: "SubscriptKeyword", - kind: .token(choices: [.keyword(text: "subscript")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "Indices", - kind: .node(kind: "ParameterClause")), - Child(name: "Result", - kind: .node(kind: "ReturnClause")), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true), - Child(name: "Accessor", - kind: .nodeChoices(choices: [ - Child(name: "Accessors", - kind: .node(kind: "AccessorBlock")), - Child(name: "Getter", - kind: .node(kind: "CodeBlock")) - ]), - isOptional: true) - ]), - - Node(name: "TypeInheritanceClause", - nameForDiagnostics: "inheritance clause", - kind: "Syntax", - children: [ - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "InheritedTypeCollection", - kind: .collection(kind: "InheritedTypeList", collectionElementName: "InheritedType")) - ]), - - Node(name: "TypeInitializerClause", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Equal", - kind: .token(choices: [.token(tokenKind: "EqualToken")])), - Child(name: "Value", - kind: .node(kind: "Type"), - nameForDiagnostics: "type") - ]), - - Node(name: "TypealiasDecl", - nameForDiagnostics: "typealias declaration", - kind: "Decl", - traits: [ - "IdentifiedDecl", - "Attributed" - ], - 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: "TypealiasKeyword", - kind: .token(choices: [.keyword(text: "typealias")])), - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericParameterClause", - kind: .node(kind: "GenericParameterClause"), - nameForDiagnostics: "generic parameter clause", - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "TypeInitializerClause")), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - nameForDiagnostics: "generic where clause", - isOptional: true) - ]), - - Node(name: "VariableDecl", - nameForDiagnostics: "variable", - kind: "Decl", - traits: [ - "Attributed" - ], - 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: "BindingKeyword", - kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")])), - Child(name: "Bindings", - kind: .collection(kind: "PatternBindingList", collectionElementName: "Binding")) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift deleted file mode 100644 index 0d0de8bc4c1..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/ExprNodes.swift +++ /dev/null @@ -1,1037 +0,0 @@ -//// Automatically Generated From ExprNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let EXPR_NODES: [Node] = [ - Node(name: "ArrayElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "ArrayElement"), - - Node(name: "ArrayElement", - nameForDiagnostics: "array element", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "value"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ArrayExpr", - nameForDiagnostics: "array", - kind: "Expr", - children: [ - Child(name: "LeftSquare", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "Elements", - kind: .collection(kind: "ArrayElementList", collectionElementName: "Element"), - isIndented: true), - Child(name: "RightSquare", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "ArrowExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "EffectSpecifiers", - kind: .node(kind: "TypeEffectSpecifiers"), - isOptional: true), - Child(name: "ArrowToken", - kind: .token(choices: [.token(tokenKind: "ArrowToken")])) - ]), - - Node(name: "AsExpr", - nameForDiagnostics: "'as'", - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "AsTok", - kind: .token(choices: [.keyword(text: "as")])), - Child(name: "QuestionOrExclamationMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), - isOptional: true), - Child(name: "TypeName", - kind: .node(kind: "Type")) - ]), - - Node(name: "AssignmentExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "AssignToken", - kind: .token(choices: [.token(tokenKind: "EqualToken")])) - ]), - - Node(name: "AwaitExpr", - nameForDiagnostics: "'await' expression", - kind: "Expr", - children: [ - Child(name: "AwaitKeyword", - kind: .token(choices: [.keyword(text: "await")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "BinaryOperatorExpr", - nameForDiagnostics: "operator", - kind: "Expr", - children: [ - Child(name: "OperatorToken", - kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken")])) - ]), - - Node(name: "BooleanLiteralExpr", - nameForDiagnostics: "bool literal", - kind: "Expr", - children: [ - Child(name: "BooleanLiteral", - kind: .token(choices: [.keyword(text: "true"), .keyword(text: "false")])) - ]), - - Node(name: "BorrowExpr", - nameForDiagnostics: "'_borrow' expression", - kind: "Expr", - children: [ - Child(name: "BorrowKeyword", - kind: .token(choices: [.keyword(text: "_borrow")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "CaseItem", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "WhereClause", - kind: .node(kind: "WhereClause"), - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ClosureCaptureItemList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "ClosureCaptureItem"), - - Node(name: "ClosureCaptureItemSpecifier", - nameForDiagnostics: "closure capture specifier", - kind: "Syntax", - children: [ - Child(name: "Specifier", - kind: .token(choices: [.keyword(text: "weak"), .keyword(text: "unowned")])), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - isOptional: true), - Child(name: "Detail", - kind: .token(choices: [.keyword(text: "safe"), .keyword(text: "unsafe")]), - isOptional: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - isOptional: true) - ]), - - Node(name: "ClosureCaptureItem", - nameForDiagnostics: "closure capture item", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Specifier", - kind: .node(kind: "ClosureCaptureItemSpecifier"), - isOptional: true), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - isOptional: true), - Child(name: "AssignToken", - kind: .token(choices: [.token(tokenKind: "EqualToken")]), - isOptional: true), - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ClosureCaptureSignature", - nameForDiagnostics: "closure capture signature", - kind: "Syntax", - children: [ - Child(name: "LeftSquare", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "Items", - kind: .collection(kind: "ClosureCaptureItemList", collectionElementName: "Item"), - isOptional: true), - Child(name: "RightSquare", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "ClosureExpr", - nameForDiagnostics: "closure", - kind: "Expr", - traits: [ - "Braced", - "WithStatements" - ], - children: [ - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "Signature", - kind: .node(kind: "ClosureSignature"), - isOptional: true), - Child(name: "Statements", - kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), - isIndented: true), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), - requiresLeadingNewline: true) - ]), - - Node(name: "ClosureParamList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "ClosureParam"), - - Node(name: "ClosureParam", - nameForDiagnostics: "closure parameter", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "name"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ClosureSignature", - nameForDiagnostics: "closure signature", - kind: "Syntax", - traits: [ - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - nameForDiagnostics: "attributes", - isOptional: true), - Child(name: "Capture", - kind: .node(kind: "ClosureCaptureSignature"), - isOptional: true), - Child(name: "Input", - kind: .nodeChoices(choices: [ - Child(name: "SimpleInput", - kind: .node(kind: "ClosureParamList")), - Child(name: "Input", - kind: .node(kind: "ParameterClause")) - ]), - isOptional: true), - Child(name: "EffectSpecifiers", - kind: .node(kind: "TypeEffectSpecifiers"), - isOptional: true), - Child(name: "Output", - kind: .node(kind: "ReturnClause"), - isOptional: true), - Child(name: "InTok", - kind: .token(choices: [.keyword(text: "in")])) - ]), - - Node(name: "DeclNameArgumentList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "DeclNameArgument"), - - Node(name: "DeclNameArgument", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Name", - kind: .node(kind: "Token")), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false)) - ]), - - Node(name: "DeclNameArguments", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Arguments", - kind: .collection(kind: "DeclNameArgumentList", collectionElementName: "Argument")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "DictionaryElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "DictionaryElement"), - - Node(name: "DictionaryElement", - nameForDiagnostics: "dictionary element", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "KeyExpression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "key"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "ValueExpression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "value", - isIndented: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "DictionaryExpr", - nameForDiagnostics: "dictionary", - kind: "Expr", - children: [ - Child(name: "LeftSquare", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "Content", - kind: .nodeChoices(choices: [ - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false)), - Child(name: "Elements", - kind: .node(kind: "DictionaryElementList")) - ]), - isIndented: true), - Child(name: "RightSquare", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "DiscardAssignmentExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Wildcard", - kind: .token(choices: [.token(tokenKind: "WildcardToken")])) - ]), - - Node(name: "EditorPlaceholderExpr", - nameForDiagnostics: "editor placeholder", - kind: "Expr", - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])) - ]), - - Node(name: "ExprList", - nameForDiagnostics: nil, - description: "A list of expressions connected by operators. This list is contained by a `SequenceExprSyntax`.", - kind: "SyntaxCollection", - element: "Expr", - elementName: "Expression"), - - Node(name: "ExpressionSegment", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "Backslash", - kind: .token(choices: [.token(tokenKind: "BackslashToken")])), - Child(name: "Delimiter", - kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), - isOptional: true), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - classification: "StringInterpolationAnchor", - forceClassification: true), - Child(name: "Expressions", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Expression")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - classification: "StringInterpolationAnchor", - forceClassification: true) - ]), - - Node(name: "FloatLiteralExpr", - nameForDiagnostics: "floating literal", - kind: "Expr", - children: [ - Child(name: "FloatingDigits", - kind: .token(choices: [.token(tokenKind: "FloatingLiteralToken")])) - ]), - - Node(name: "ForcedValueExpr", - nameForDiagnostics: "force unwrap", - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "ExclamationMark", - kind: .token(choices: [.token(tokenKind: "ExclamationMarkToken")])) - ]), - - Node(name: "FunctionCallExpr", - nameForDiagnostics: "function call", - kind: "Expr", - children: [ - Child(name: "CalledExpression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "called expression"), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - isOptional: true), - Child(name: "ArgumentList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), - nameForDiagnostics: "arguments", - isIndented: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - isOptional: true), - Child(name: "TrailingClosure", - kind: .node(kind: "ClosureExpr"), - nameForDiagnostics: "trailing closure", - isOptional: true), - Child(name: "AdditionalTrailingClosures", - kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), - nameForDiagnostics: "trailing closures", - isOptional: true) - ]), - - Node(name: "IdentifierExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "DollarIdentifierToken"), .token(tokenKind: "BinaryOperatorToken")])), - Child(name: "DeclNameArguments", - kind: .node(kind: "DeclNameArguments"), - isOptional: true) - ]), - - Node(name: "IfExpr", - nameForDiagnostics: "'if' statement", - kind: "Expr", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "IfKeyword", - kind: .token(choices: [.keyword(text: "if")])), - Child(name: "Conditions", - kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition")), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - nameForDiagnostics: "body"), - Child(name: "ElseKeyword", - kind: .node(kind: "ElseToken"), - isOptional: true), - Child(name: "ElseBody", - kind: .nodeChoices(choices: [ - Child(name: "IfExpr", - kind: .node(kind: "IfExpr")), - Child(name: "CodeBlock", - kind: .node(kind: "CodeBlock")) - ]), - nameForDiagnostics: "else body", - isOptional: true) - ]), - - Node(name: "InOutExpr", - nameForDiagnostics: "inout expression", - kind: "Expr", - children: [ - Child(name: "Ampersand", - kind: .token(choices: [.token(tokenKind: "PrefixAmpersandToken")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "InfixOperatorExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "LeftOperand", - kind: .node(kind: "Expr")), - Child(name: "OperatorOperand", - kind: .node(kind: "Expr")), - Child(name: "RightOperand", - kind: .node(kind: "Expr")) - ]), - - Node(name: "IntegerLiteralExpr", - nameForDiagnostics: "integer literal", - kind: "Expr", - children: [ - Child(name: "Digits", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")])) - ]), - - Node(name: "IsExpr", - nameForDiagnostics: "'is'", - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "IsTok", - kind: .token(choices: [.keyword(text: "is")])), - Child(name: "TypeName", - kind: .node(kind: "Type")) - ]), - - Node(name: "KeyPathComponentList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "KeyPathComponent"), - - Node(name: "KeyPathComponent", - nameForDiagnostics: "key path component", - kind: "Syntax", - children: [ - Child(name: "Period", - kind: .token(choices: [.token(tokenKind: "PeriodToken")]), - isOptional: true), - Child(name: "Component", - kind: .nodeChoices(choices: [ - Child(name: "Property", - kind: .node(kind: "KeyPathPropertyComponent")), - Child(name: "Subscript", - kind: .node(kind: "KeyPathSubscriptComponent")), - Child(name: "Optional", - kind: .node(kind: "KeyPathOptionalComponent")) - ])) - ]), - - Node(name: "KeyPathExpr", - nameForDiagnostics: "key path", - kind: "Expr", - children: [ - Child(name: "Backslash", - kind: .token(choices: [.token(tokenKind: "BackslashToken")])), - Child(name: "Root", - kind: .node(kind: "Type"), - nameForDiagnostics: "root", - isOptional: true), - Child(name: "Components", - kind: .collection(kind: "KeyPathComponentList", collectionElementName: "KeyPathComponent")) - ]), - - Node(name: "KeyPathOptionalComponent", - nameForDiagnostics: "key path optional component", - kind: "Syntax", - children: [ - Child(name: "QuestionOrExclamationMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")])) - ]), - - Node(name: "KeyPathPropertyComponent", - nameForDiagnostics: "key path property component", - kind: "Syntax", - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "DollarIdentifierToken"), .token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "IntegerLiteralToken")])), - Child(name: "DeclNameArguments", - kind: .node(kind: "DeclNameArguments"), - isOptional: true), - Child(name: "GenericArgumentClause", - kind: .node(kind: "GenericArgumentClause"), - isOptional: true) - ]), - - Node(name: "KeyPathSubscriptComponent", - nameForDiagnostics: "key path subscript component", - kind: "Syntax", - children: [ - Child(name: "LeftBracket", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "ArgumentList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), - nameForDiagnostics: "arguments"), - Child(name: "RightBracket", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "MacroExpansionExpr", - nameForDiagnostics: "macro expansion", - kind: "Expr", - traits: [ - "FreestandingMacroExpansion" - ], - children: [ - Child(name: "PoundToken", - kind: .token(choices: [.token(tokenKind: "PoundToken")]), - description: "The `#` sign."), - Child(name: "Macro", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericArguments", - kind: .node(kind: "GenericArgumentClause"), - isOptional: true), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - isOptional: true), - Child(name: "ArgumentList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - isOptional: true), - Child(name: "TrailingClosure", - kind: .node(kind: "ClosureExpr"), - isOptional: true), - Child(name: "AdditionalTrailingClosures", - kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), - isOptional: true) - ]), - - Node(name: "MemberAccessExpr", - nameForDiagnostics: "member access", - kind: "Expr", - children: [ - Child(name: "Base", - kind: .node(kind: "Expr"), - nameForDiagnostics: "base", - isOptional: true), - Child(name: "Dot", - kind: .token(choices: [.token(tokenKind: "PeriodToken")])), - Child(name: "Name", - kind: .node(kind: "Token"), - nameForDiagnostics: "name"), - Child(name: "DeclNameArguments", - kind: .node(kind: "DeclNameArguments"), - isOptional: true) - ]), - - Node(name: "MoveExpr", - nameForDiagnostics: "'_move' expression", - kind: "Expr", - children: [ - Child(name: "MoveKeyword", - kind: .token(choices: [.keyword(text: "_move"), .keyword(text: "consume")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "MultipleTrailingClosureElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "MultipleTrailingClosureElement"), - - Node(name: "MultipleTrailingClosureElement", - nameForDiagnostics: "trailing closure", - kind: "Syntax", - children: [ - Child(name: "Label", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "label"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Closure", - kind: .node(kind: "ClosureExpr")) - ]), - - Node(name: "NilLiteralExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "NilKeyword", - kind: .token(choices: [.keyword(text: "nil")])) - ]), - - Node(name: "OptionalChainingExpr", - nameForDiagnostics: "optional chaining", - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "QuestionMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken")])) - ]), - - Node(name: "PackElementExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "EachKeyword", - kind: .token(choices: [.keyword(text: "each")])), - Child(name: "PackRefExpr", - kind: .node(kind: "Expr")) - ]), - - Node(name: "PackExpansionExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "RepeatKeyword", - kind: .token(choices: [.keyword(text: "repeat")])), - Child(name: "PatternExpr", - kind: .node(kind: "Expr")) - ]), - - Node(name: "PostfixIfConfigExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Base", - kind: .node(kind: "Expr"), - isOptional: true), - Child(name: "Config", - kind: .node(kind: "IfConfigDecl")) - ]), - - Node(name: "PostfixUnaryExpr", - nameForDiagnostics: "postfix expression", - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "OperatorToken", - kind: .token(choices: [.token(tokenKind: "PostfixOperatorToken")])) - ]), - - Node(name: "PrefixOperatorExpr", - nameForDiagnostics: "operator", - kind: "Expr", - children: [ - Child(name: "OperatorToken", - kind: .token(choices: [.token(tokenKind: "PrefixOperatorToken")]), - isOptional: true), - Child(name: "PostfixExpression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "RegexLiteralExpr", - nameForDiagnostics: "regex literal", - kind: "Expr", - children: [ - Child(name: "Regex", - kind: .token(choices: [.token(tokenKind: "RegexLiteralToken")])) - ]), - - Node(name: "SequenceExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Elements", - kind: .collection(kind: "ExprList", collectionElementName: "Element")) - ]), - - Node(name: "SpecializeExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "GenericArgumentClause", - kind: .node(kind: "GenericArgumentClause")) - ]), - - Node(name: "StringLiteralExpr", - nameForDiagnostics: "string literal", - kind: "Expr", - children: [ - Child(name: "OpenDelimiter", - kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), - isOptional: true), - Child(name: "OpenQuote", - kind: .token(choices: [.token(tokenKind: "StringQuoteToken"), .token(tokenKind: "MultilineStringQuoteToken"), .token(tokenKind: "SingleQuoteToken")])), - Child(name: "Segments", - kind: .collection(kind: "StringLiteralSegments", collectionElementName: "Segment")), - Child(name: "CloseQuote", - kind: .token(choices: [.token(tokenKind: "StringQuoteToken"), .token(tokenKind: "MultilineStringQuoteToken"), .token(tokenKind: "SingleQuoteToken")])), - Child(name: "CloseDelimiter", - kind: .token(choices: [.token(tokenKind: "RawStringDelimiterToken")]), - isOptional: true) - ]), - - Node(name: "StringLiteralSegments", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "Syntax", - elementName: "Segment", - elementChoices: ["StringSegment", "ExpressionSegment"]), - - Node(name: "StringSegment", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Content", - kind: .token(choices: [.token(tokenKind: "StringSegmentToken")])) - ]), - - Node(name: "SubscriptExpr", - nameForDiagnostics: "subscript", - kind: "Expr", - children: [ - Child(name: "CalledExpression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "called expression"), - Child(name: "LeftBracket", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "ArgumentList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Argument"), - nameForDiagnostics: "arguments"), - Child(name: "RightBracket", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])), - Child(name: "TrailingClosure", - kind: .node(kind: "ClosureExpr"), - nameForDiagnostics: "trailing closure", - isOptional: true), - Child(name: "AdditionalTrailingClosures", - kind: .collection(kind: "MultipleTrailingClosureElementList", collectionElementName: "AdditionalTrailingClosure"), - nameForDiagnostics: "trailing closures", - isOptional: true) - ]), - - Node(name: "SuperRefExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "SuperKeyword", - kind: .token(choices: [.keyword(text: "super")])) - ]), - - Node(name: "SwitchCaseLabel", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "CaseKeyword", - kind: .token(choices: [.keyword(text: "case")])), - Child(name: "CaseItems", - kind: .collection(kind: "CaseItemList", collectionElementName: "CaseItem")), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false)) - ]), - - Node(name: "SwitchCaseList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "Syntax", - elementName: "SwitchCase", - elementChoices: ["SwitchCase", "IfConfigDecl"], - elementsSeparatedByNewline: true), - - Node(name: "SwitchCase", - nameForDiagnostics: "switch case", - kind: "Syntax", - traits: [ - "WithStatements" - ], - parserFunction: "parseSwitchCase", - children: [ - Child(name: "UnknownAttr", - kind: .node(kind: "Attribute"), - isOptional: true), - Child(name: "Label", - kind: .nodeChoices(choices: [ - Child(name: "Default", - kind: .node(kind: "SwitchDefaultLabel")), - Child(name: "Case", - kind: .node(kind: "SwitchCaseLabel")) - ]), - nameForDiagnostics: "label"), - Child(name: "Statements", - kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement"), - isIndented: true) - ]), - - Node(name: "SwitchDefaultLabel", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "DefaultKeyword", - kind: .token(choices: [.keyword(text: "default")])), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")], requiresTrailingSpace: false)) - ]), - - Node(name: "SwitchExpr", - nameForDiagnostics: "'switch' statement", - kind: "Expr", - traits: [ - "Braced" - ], - children: [ - Child(name: "SwitchKeyword", - kind: .token(choices: [.keyword(text: "switch")])), - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "LeftBrace", - kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "Cases", - kind: .collection(kind: "SwitchCaseList", collectionElementName: "Case")), - Child(name: "RightBrace", - kind: .token(choices: [.token(tokenKind: "RightBraceToken")]), - requiresLeadingNewline: true) - ]), - - Node(name: "TernaryExpr", - nameForDiagnostics: "ternay expression", - kind: "Expr", - children: [ - Child(name: "ConditionExpression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "condition"), - Child(name: "QuestionMark", - kind: .token(choices: [.token(tokenKind: "InfixQuestionMarkToken")])), - Child(name: "FirstChoice", - kind: .node(kind: "Expr"), - nameForDiagnostics: "first choice"), - Child(name: "ColonMark", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "SecondChoice", - kind: .node(kind: "Expr"), - nameForDiagnostics: "second choice") - ]), - - Node(name: "TryExpr", - nameForDiagnostics: "'try' expression", - kind: "Expr", - children: [ - Child(name: "TryKeyword", - kind: .token(choices: [.keyword(text: "try")])), - Child(name: "QuestionOrExclamationMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")], requiresTrailingSpace: true), - isOptional: true), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "TupleExprElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "TupleExprElement"), - - Node(name: "TupleExprElement", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Label", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "label", - isOptional: true), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "Expression", - kind: .node(kind: "Expr"), - nameForDiagnostics: "value"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "TupleExpr", - nameForDiagnostics: "tuple", - kind: "Expr", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "ElementList", - kind: .collection(kind: "TupleExprElementList", collectionElementName: "Element"), - isIndented: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "TypeExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Type", - kind: .node(kind: "Type")) - ]), - - Node(name: "UnresolvedAsExpr", - nameForDiagnostics: "'as'", - kind: "Expr", - children: [ - Child(name: "AsTok", - kind: .token(choices: [.keyword(text: "as")])), - Child(name: "QuestionOrExclamationMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken"), .token(tokenKind: "ExclamationMarkToken")]), - isOptional: true) - ]), - - Node(name: "UnresolvedIsExpr", - nameForDiagnostics: "'is'", - kind: "Expr", - children: [ - Child(name: "IsTok", - kind: .token(choices: [.keyword(text: "is")])) - ]), - - Node(name: "UnresolvedPatternExpr", - nameForDiagnostics: nil, - kind: "Expr", - children: [ - Child(name: "Pattern", - kind: .node(kind: "Pattern")) - ]), - - Node(name: "UnresolvedTernaryExpr", - nameForDiagnostics: "ternary operator", - kind: "Expr", - children: [ - Child(name: "QuestionMark", - kind: .token(choices: [.token(tokenKind: "InfixQuestionMarkToken")])), - Child(name: "FirstChoice", - kind: .node(kind: "Expr")), - Child(name: "ColonMark", - kind: .token(choices: [.token(tokenKind: "ColonToken")])) - ]), - - Node(name: "YieldExprListElement", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "YieldExprList", - nameForDiagnostics: "yield list", - kind: "SyntaxCollection", - element: "YieldExprListElement", - elementName: "Yields"), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/GenericNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/GenericNodes.swift deleted file mode 100644 index 5908cb96b8b..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/GenericNodes.swift +++ /dev/null @@ -1,192 +0,0 @@ -//// Automatically Generated From GenericNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let GENERIC_NODES: [Node] = [ - Node(name: "ConformanceRequirement", - nameForDiagnostics: "conformance requirement", - kind: "Syntax", - children: [ - Child(name: "LeftTypeIdentifier", - kind: .node(kind: "Type")), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "RightTypeIdentifier", - kind: .node(kind: "Type")) - ]), - - Node(name: "GenericParameterClause", - nameForDiagnostics: "generic parameter clause", - kind: "Syntax", - parserFunction: "parseGenericParameters", - children: [ - Child(name: "LeftAngleBracket", - kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])), - Child(name: "GenericParameterList", - kind: .collection(kind: "GenericParameterList", collectionElementName: "GenericParameter")), - Child(name: "GenericWhereClause", - kind: .node(kind: "GenericWhereClause"), - isOptional: true), - Child(name: "RightAngleBracket", - kind: .token(choices: [.token(tokenKind: "RightAngleToken")])) - ]), - - Node(name: "GenericParameterList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "GenericParameter"), - - Node(name: "GenericParameter", - nameForDiagnostics: "generic parameter", - kind: "Syntax", - traits: [ - "WithTrailingComma", - "Attributed" - ], - children: [ - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - isOptional: true), - Child(name: "Each", - kind: .token(choices: [.keyword(text: "each")]), - nameForDiagnostics: "parameter pack specifier", - isOptional: true), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "InheritedType", - kind: .node(kind: "Type"), - nameForDiagnostics: "inherited type", - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "GenericRequirementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "GenericRequirement", - elementName: "GenericRequirement"), - - Node(name: "GenericRequirement", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Body", - kind: .nodeChoices(choices: [ - Child(name: "SameTypeRequirement", - kind: .node(kind: "SameTypeRequirement")), - Child(name: "ConformanceRequirement", - kind: .node(kind: "ConformanceRequirement")), - Child(name: "LayoutRequirement", - kind: .node(kind: "LayoutRequirement")) - ])), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "GenericWhereClause", - nameForDiagnostics: "'where' clause", - kind: "Syntax", - children: [ - Child(name: "WhereKeyword", - kind: .token(choices: [.keyword(text: "where")])), - Child(name: "RequirementList", - kind: .collection(kind: "GenericRequirementList", collectionElementName: "Requirement")) - ]), - - Node(name: "LayoutRequirement", - nameForDiagnostics: "layout requirement", - kind: "Syntax", - children: [ - Child(name: "TypeIdentifier", - kind: .node(kind: "Type"), - nameForDiagnostics: "constrained type"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "LayoutConstraint", - kind: .token(choices: [.keyword(text: "_Trivial"), .keyword(text: "_TrivialAtMost"), .keyword(text: "_UnknownLayout"), .keyword(text: "_RefCountedObject"), .keyword(text: "_NativeRefCountedObject"), .keyword(text: "_Class"), .keyword(text: "_NativeClass")])), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), - isOptional: true), - Child(name: "Size", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), - nameForDiagnostics: "size", - isOptional: true), - Child(name: "Comma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true), - Child(name: "Alignment", - kind: .token(choices: [.token(tokenKind: "IntegerLiteralToken")]), - nameForDiagnostics: "alignment", - isOptional: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")]), - isOptional: true) - ]), - - Node(name: "PrimaryAssociatedTypeClause", - nameForDiagnostics: "primary associated type clause", - kind: "Syntax", - children: [ - Child(name: "LeftAngleBracket", - kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])), - Child(name: "PrimaryAssociatedTypeList", - kind: .collection(kind: "PrimaryAssociatedTypeList", collectionElementName: "PrimaryAssociatedType")), - Child(name: "RightAngleBracket", - kind: .token(choices: [.token(tokenKind: "RightAngleToken")])) - ]), - - Node(name: "PrimaryAssociatedTypeList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "PrimaryAssociatedType"), - - Node(name: "PrimaryAssociatedType", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "name"), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "SameTypeRequirement", - nameForDiagnostics: "same type requirement", - kind: "Syntax", - children: [ - Child(name: "LeftTypeIdentifier", - kind: .node(kind: "Type"), - nameForDiagnostics: "left-hand type"), - Child(name: "EqualityToken", - kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")])), - Child(name: "RightTypeIdentifier", - kind: .node(kind: "Type"), - nameForDiagnostics: "right-hand type") - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/PatternNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/PatternNodes.swift deleted file mode 100644 index 29f5af9b850..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/PatternNodes.swift +++ /dev/null @@ -1,114 +0,0 @@ -//// Automatically Generated From PatternNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let PATTERN_NODES: [Node] = [ - Node(name: "ExpressionPattern", - nameForDiagnostics: "pattern", - kind: "Pattern", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "IdentifierPattern", - nameForDiagnostics: "pattern", - kind: "Pattern", - children: [ - Child(name: "Identifier", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")])) - ]), - - Node(name: "IsTypePattern", - nameForDiagnostics: "'is' pattern", - kind: "Pattern", - children: [ - Child(name: "IsKeyword", - kind: .token(choices: [.keyword(text: "is")])), - Child(name: "Type", - kind: .node(kind: "Type")) - ]), - - Node(name: "TuplePatternElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "TuplePatternElement"), - - Node(name: "TuplePatternElement", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "LabelName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "label", - isOptional: true), - Child(name: "LabelColon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "TuplePattern", - nameForDiagnostics: "tuple pattern", - kind: "Pattern", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Elements", - kind: .collection(kind: "TuplePatternElementList", collectionElementName: "Element")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "TypeAnnotation", - nameForDiagnostics: "type annotation", - kind: "Syntax", - children: [ - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Type", - kind: .node(kind: "Type")) - ]), - - Node(name: "ValueBindingPattern", - nameForDiagnostics: "value binding pattern", - kind: "Pattern", - children: [ - Child(name: "BindingKeyword", - kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")])), - Child(name: "ValuePattern", - kind: .node(kind: "Pattern")) - ]), - - Node(name: "WildcardPattern", - nameForDiagnostics: "wildcard pattern", - kind: "Pattern", - children: [ - Child(name: "Wildcard", - kind: .token(choices: [.token(tokenKind: "WildcardToken")])), - Child(name: "TypeAnnotation", - kind: .node(kind: "TypeAnnotation"), - isOptional: true) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift deleted file mode 100644 index 3712351619f..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/StmtNodes.swift +++ /dev/null @@ -1,379 +0,0 @@ -//// Automatically Generated From StmtNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let STMT_NODES: [Node] = [ - Node(name: "AvailabilityCondition", - nameForDiagnostics: "availability condition", - kind: "Syntax", - children: [ - Child(name: "AvailabilityKeyword", - kind: .token(choices: [.token(tokenKind: "PoundAvailableToken"), .token(tokenKind: "PoundUnavailableToken")])), - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "AvailabilitySpec", - kind: .collection(kind: "AvailabilitySpecList", collectionElementName: "AvailabilityArgument")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "BreakStmt", - nameForDiagnostics: "'break' statement", - kind: "Stmt", - children: [ - Child(name: "BreakKeyword", - kind: .token(choices: [.keyword(text: "break")], requiresTrailingSpace: false)), - Child(name: "Label", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "label", - isOptional: true) - ]), - - Node(name: "CaseItemList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "CaseItem"), - - Node(name: "CatchClauseList", - nameForDiagnostics: "'catch' clause", - kind: "SyntaxCollection", - element: "CatchClause"), - - Node(name: "CatchClause", - nameForDiagnostics: "'catch' clause", - kind: "Syntax", - traits: [ - "WithCodeBlock" - ], - parserFunction: "parseCatchClause", - children: [ - Child(name: "CatchKeyword", - kind: .token(choices: [.keyword(text: "catch")])), - Child(name: "CatchItems", - kind: .collection(kind: "CatchItemList", collectionElementName: "CatchItem"), - isOptional: true), - Child(name: "Body", - kind: .node(kind: "CodeBlock")) - ]), - - Node(name: "CatchItemList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "CatchItem"), - - Node(name: "CatchItem", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Pattern", - kind: .node(kind: "Pattern"), - isOptional: true), - Child(name: "WhereClause", - kind: .node(kind: "WhereClause"), - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ConditionElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "ConditionElement"), - - Node(name: "ConditionElement", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "Condition", - kind: .nodeChoices(choices: [ - Child(name: "Expression", - kind: .node(kind: "Expr")), - Child(name: "Availability", - kind: .node(kind: "AvailabilityCondition")), - Child(name: "MatchingPattern", - kind: .node(kind: "MatchingPatternCondition")), - Child(name: "OptionalBinding", - kind: .node(kind: "OptionalBindingCondition")) - ])), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ContinueStmt", - nameForDiagnostics: "'continue' statement", - kind: "Stmt", - children: [ - Child(name: "ContinueKeyword", - kind: .token(choices: [.keyword(text: "continue")])), - Child(name: "Label", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "label", - isOptional: true) - ]), - - Node(name: "DeferStmt", - nameForDiagnostics: "'defer' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "DeferKeyword", - kind: .token(choices: [.keyword(text: "defer")])), - Child(name: "Body", - kind: .node(kind: "CodeBlock")) - ]), - - Node(name: "DoStmt", - nameForDiagnostics: "'do' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "DoKeyword", - kind: .token(choices: [.keyword(text: "do")])), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - nameForDiagnostics: "body"), - Child(name: "CatchClauses", - kind: .collection(kind: "CatchClauseList", collectionElementName: "CatchClause"), - isOptional: true) - ]), - - Node(name: "ExpressionStmt", - nameForDiagnostics: "expression", - kind: "Stmt", - children: [ - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "FallthroughStmt", - nameForDiagnostics: "'fallthrough' statement", - kind: "Stmt", - children: [ - Child(name: "FallthroughKeyword", - kind: .token(choices: [.keyword(text: "fallthrough")])) - ]), - - Node(name: "ForInStmt", - nameForDiagnostics: "'for' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "ForKeyword", - kind: .token(choices: [.keyword(text: "for")])), - Child(name: "TryKeyword", - kind: .node(kind: "TryToken"), - isOptional: true), - Child(name: "AwaitKeyword", - kind: .token(choices: [.keyword(text: "await")]), - isOptional: true, - classification: "Keyword"), - Child(name: "CaseKeyword", - kind: .node(kind: "CaseToken"), - isOptional: true), - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "TypeAnnotation", - kind: .node(kind: "TypeAnnotation"), - isOptional: true), - Child(name: "InKeyword", - kind: .token(choices: [.keyword(text: "in")])), - Child(name: "SequenceExpr", - kind: .node(kind: "Expr")), - Child(name: "WhereClause", - kind: .node(kind: "WhereClause"), - isOptional: true), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - nameForDiagnostics: "body") - ]), - - Node(name: "ForgetStmt", - nameForDiagnostics: "'forget' statement", - kind: "Stmt", - children: [ - Child(name: "ForgetKeyword", - kind: .token(choices: [.keyword(text: "_forget")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "GuardStmt", - nameForDiagnostics: "'guard' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "GuardKeyword", - kind: .token(choices: [.keyword(text: "guard")])), - Child(name: "Conditions", - kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition"), - nameForDiagnostics: "condition"), - Child(name: "ElseKeyword", - kind: .token(choices: [.keyword(text: "else")])), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - nameForDiagnostics: "body") - ]), - - Node(name: "LabeledStmt", - nameForDiagnostics: "labeled statement", - kind: "Stmt", - children: [ - Child(name: "LabelName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken")]), - nameForDiagnostics: "label name"), - Child(name: "LabelColon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "Statement", - kind: .node(kind: "Stmt")) - ]), - - Node(name: "MatchingPatternCondition", - nameForDiagnostics: "pattern matching", - kind: "Syntax", - children: [ - Child(name: "CaseKeyword", - kind: .token(choices: [.keyword(text: "case")])), - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "TypeAnnotation", - kind: .node(kind: "TypeAnnotation"), - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "InitializerClause")) - ]), - - Node(name: "OptionalBindingCondition", - nameForDiagnostics: "optional binding", - kind: "Syntax", - children: [ - Child(name: "BindingKeyword", - kind: .token(choices: [.keyword(text: "let"), .keyword(text: "var"), .keyword(text: "inout")])), - Child(name: "Pattern", - kind: .node(kind: "Pattern")), - Child(name: "TypeAnnotation", - kind: .node(kind: "TypeAnnotation"), - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "InitializerClause"), - isOptional: true) - ]), - - Node(name: "RepeatWhileStmt", - nameForDiagnostics: "'repeat' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "RepeatKeyword", - kind: .token(choices: [.keyword(text: "repeat")])), - Child(name: "Body", - kind: .node(kind: "CodeBlock"), - nameForDiagnostics: "body"), - Child(name: "WhileKeyword", - kind: .token(choices: [.keyword(text: "while")])), - Child(name: "Condition", - kind: .node(kind: "Expr"), - nameForDiagnostics: "condition") - ]), - - Node(name: "ReturnStmt", - nameForDiagnostics: "'return' statement", - kind: "Stmt", - children: [ - Child(name: "ReturnKeyword", - kind: .token(choices: [.keyword(text: "return")])), - Child(name: "Expression", - kind: .node(kind: "Expr"), - isOptional: true) - ]), - - Node(name: "ThrowStmt", - nameForDiagnostics: "'throw' statement", - kind: "Stmt", - children: [ - Child(name: "ThrowKeyword", - kind: .token(choices: [.keyword(text: "throw")])), - Child(name: "Expression", - kind: .node(kind: "Expr")) - ]), - - Node(name: "WhereClause", - nameForDiagnostics: "'where' clause", - kind: "Syntax", - children: [ - Child(name: "WhereKeyword", - kind: .token(choices: [.keyword(text: "where")])), - Child(name: "GuardResult", - kind: .node(kind: "Expr")) - ]), - - Node(name: "WhileStmt", - nameForDiagnostics: "'while' statement", - kind: "Stmt", - traits: [ - "WithCodeBlock" - ], - children: [ - Child(name: "WhileKeyword", - kind: .token(choices: [.keyword(text: "while")])), - Child(name: "Conditions", - kind: .collection(kind: "ConditionElementList", collectionElementName: "Condition")), - Child(name: "Body", - kind: .node(kind: "CodeBlock")) - ]), - - Node(name: "YieldList", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "ElementList", - kind: .collection(kind: "YieldExprList", collectionElementName: "Element")), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - - Node(name: "YieldStmt", - nameForDiagnostics: "'yield' statement", - kind: "Stmt", - children: [ - Child(name: "YieldKeyword", - kind: .token(choices: [.keyword(text: "yield")])), - Child(name: "Yields", - kind: .nodeChoices(choices: [ - Child(name: "YieldList", - kind: .node(kind: "YieldList")), - Child(name: "SimpleYield", - kind: .node(kind: "Expr")) - ])) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Traits.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Traits.swift deleted file mode 100644 index 651902f33fd..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Traits.swift +++ /dev/null @@ -1,93 +0,0 @@ -//// Automatically Generated From Traits.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public class Trait { - public let traitName: String - public let children: [Child] - public let description: String? - - init(traitName: String, children: [Child], description: String? = nil) { - self.traitName = traitName - self.children = children - self.description = description - } -} - -public let TRAITS: [Trait] = [ - Trait(traitName: "Attributed", - children: [ - Child(name: "Attributes", kind: .node(kind: "AttributeList"), isOptional: true), - ] - ), - Trait(traitName: "Braced", - children: [ - Child(name: "LeftBrace", kind: .token(choices: [.token(tokenKind: "LeftBraceToken")])), - Child(name: "RightBrace", kind: .token(choices: [.token(tokenKind: "RightBraceToken")])), - ] - ), - Trait(traitName: "DeclGroup", - children: [ - Child(name: "Attributes", kind: .node(kind: "AttributeList"), isOptional: true), - Child(name: "Modifiers", kind: .node(kind: "ModifierList"), isOptional: true), - Child(name: "Members", kind: .node(kind: "MemberDeclBlock")), - ] - ), - Trait(traitName: "EffectSpecifiers", - children: [ - Child(name: "UnexpectedBeforeAsyncSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), - Child(name: "AsyncSpecifier", kind: .token(choices: [.token(tokenKind: "KeywordToken")]), isOptional: true), - Child(name: "UnexpectedBetweenAsyncSpecifierAndThrowsSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), - Child(name: "ThrowsSpecifier", kind: .token(choices: [.token(tokenKind: "KeywordToken")]), isOptional: true), - Child(name: "UnexpectedAfterThrowsSpecifier", kind: .node(kind: "UnexpectedNodes"), isOptional: true), - ] - ), - Trait(traitName: "FreestandingMacroExpansion", - children: [ - Child(name: "PoundToken", kind: .token(choices: [.token(tokenKind: "PoundToken")])), - Child(name: "Macro", kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - Child(name: "GenericArguments", kind: .node(kind: "GenericArgumentClause"), isOptional: true), - Child(name: "LeftParen", kind: .token(choices: [.token(tokenKind: "LeftParenToken")]), isOptional: true), - Child(name: "ArgumentList", kind: .node(kind: "TupleExprElementList")), - Child(name: "RightParen", kind: .token(choices: [.token(tokenKind: "RightParenToken")]), isOptional: true), - Child(name: "TrailingClosure", kind: .node(kind: "ClosureExpr"), isOptional: true), - Child(name: "AdditionalTrailingClosures", kind: .node(kind: "MultipleTrailingClosureElementList"), isOptional: true), - ] - ), - Trait(traitName: "IdentifiedDecl", - children: [ - Child(name: "Identifier", kind: .token(choices: [.token(tokenKind: "IdentifierToken")])), - ] - ), - Trait(traitName: "Parenthesized", - children: [ - Child(name: "LeftParen", kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "RightParen", kind: .token(choices: [.token(tokenKind: "RightParenToken")])), - ] - ), - Trait(traitName: "WithCodeBlock", - children: [ - Child(name: "Body", kind: .node(kind: "CodeBlock")), - ] - ), - Trait(traitName: "WithStatements", - children: [ - Child(name: "Statements", kind: .node(kind: "CodeBlockItemList")), - ] - ), - Trait(traitName: "WithTrailingComma", - children: [ - Child(name: "TrailingComma", kind: .token(choices: [.token(tokenKind: "CommaToken")]), isOptional: true), - ] - ), -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Trivia.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Trivia.swift deleted file mode 100644 index f24941fcda5..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/Trivia.swift +++ /dev/null @@ -1,157 +0,0 @@ -//// Automatically Generated From Trivia.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public class Trivia { - public let name: String - public let comment: String - public let characters: [Character] - public let swiftCharacters: [Character] - public let isNewLine: Bool - public let isComment: Bool - - public var lowerName: String { lowercaseFirstWord(name: name) } - - public var enumCaseName: String { - if self.isCollection { - if lowerName == "backslash" { - return "backslashes" - } else { - return "\(lowerName)s" - } - } else { - return lowerName - } - } - - public var charactersLen: Int { characters.count } - - public var isCollection: Bool { charactersLen > 0 } - - init(name: String, - comment: String, - characters: [Character] = [], - swiftCharacters: [Character] = [], - isNewLine: Bool = false, - isComment: Bool = false){ - self.name = name - self.comment = comment - self.isNewLine = isNewLine - self.isComment = isComment - self.characters = characters - - // Swift sometimes doesn't support escaped characters like \f or \v; - // we should allow specifying alternatives explicitly. - if !swiftCharacters.isEmpty { - self.swiftCharacters = swiftCharacters - } else { - self.swiftCharacters = characters - } - } -} - -public let TRIVIAS: [Trivia] = [ - Trivia(name: "Backslash", - comment: #"A backslash that is at the end of a line in a multi-line string literal to escape the newline."#, - characters: [ - Character("\\") - ], - swiftCharacters: [ - Character("\\") - ]), - Trivia(name: "BlockComment", - comment: #"A developer block comment, starting with '/*' and ending with '*/'."#, - isComment: true), - Trivia(name: "CarriageReturn", - comment: #"A newline '\r' character."#, - characters: [ - Character("\r") - ], - swiftCharacters: [ - Character("\r") - ], - isNewLine: true), - Trivia(name: "CarriageReturnLineFeed", - comment: #"A newline consists of contiguous '\r' and '\n' characters."#, - characters: [ - Character("\r"), - Character("\n") - ], - swiftCharacters: [ - Character("\r"), - Character("\n") - ], - isNewLine: true), - Trivia(name: "DocBlockComment", - comment: #"A documentation block comment, starting with '/**' and ending with '*/'."#, - isComment: true), - Trivia(name: "DocLineComment", - comment: #"A documentation line comment, starting with '///'."#, - isComment: true), - Trivia(name: "Formfeed", - comment: #"A form-feed 'f' character."#, - characters: [ - Character("\u{c}") - ], - swiftCharacters: [ - Character("\u{240C}") - ]), - Trivia(name: "LineComment", - comment: #"A developer line comment, starting with '//'"#, - isComment: true), - Trivia(name: "Newline", - comment: #"A newline '\n' character."#, - characters: [ - Character("\n") - ], - swiftCharacters: [ - Character("\n") - ], - isNewLine: true), - Trivia(name: "Pound", - comment: #"A '#' that is at the end of a line in a multi-line string literal to escape the newline."#, - characters: [ - Character("#") - ], - swiftCharacters: [ - Character("#") - ]), - Trivia(name: "Shebang", - comment: #"A script command, starting with '#!'."#), - Trivia(name: "Space", - comment: #"A space ' ' character."#, - characters: [ - Character(" ") - ], - swiftCharacters: [ - Character(" ") - ]), - Trivia(name: "Tab", - comment: #"A tab '\t' character."#, - characters: [ - Character("\t") - ], - swiftCharacters: [ - Character("\t") - ]), - Trivia(name: "UnexpectedText", - comment: #"Any skipped unexpected text."#), - Trivia(name: "VerticalTab", - comment: #"A vertical tab '\v' character."#, - characters: [ - Character("\u{b}") - ], - swiftCharacters: [ - Character("\u{2B7F}") - ]), -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/TypeNodes.swift b/CodeGeneration/Sources/SyntaxSupport/gyb_generated/TypeNodes.swift deleted file mode 100644 index 95b1f3c065a..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_generated/TypeNodes.swift +++ /dev/null @@ -1,305 +0,0 @@ -//// Automatically Generated From GenericNodes.swift.gyb. -//// Do Not Edit Directly! -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -public let TYPE_NODES: [Node] = [ - Node(name: "ArrayType", - nameForDiagnostics: "array type", - kind: "Type", - children: [ - Child(name: "LeftSquareBracket", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "ElementType", - kind: .node(kind: "Type")), - Child(name: "RightSquareBracket", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "AttributedType", - nameForDiagnostics: "type", - kind: "Type", - traits: [ - "Attributed" - ], - children: [ - Child(name: "Specifier", - kind: .token(choices: [.keyword(text: "inout"), .keyword(text: "__shared"), .keyword(text: "__owned"), .keyword(text: "isolated"), .keyword(text: "_const"), .keyword(text: "borrowing"), .keyword(text: "consuming")]), - isOptional: true), - Child(name: "Attributes", - kind: .collection(kind: "AttributeList", collectionElementName: "Attribute"), - isOptional: true), - Child(name: "BaseType", - kind: .node(kind: "Type")) - ]), - - Node(name: "ClassRestrictionType", - nameForDiagnostics: nil, - kind: "Type", - children: [ - Child(name: "ClassKeyword", - kind: .token(choices: [.keyword(text: "class")])) - ]), - - Node(name: "CompositionTypeElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "CompositionTypeElement"), - - Node(name: "CompositionTypeElement", - nameForDiagnostics: nil, - kind: "Syntax", - children: [ - Child(name: "Type", - kind: .node(kind: "Type")), - Child(name: "Ampersand", - kind: .node(kind: "Token"), - isOptional: true) - ]), - - Node(name: "CompositionType", - nameForDiagnostics: "type composition", - kind: "Type", - children: [ - Child(name: "Elements", - kind: .collection(kind: "CompositionTypeElementList", collectionElementName: "Element")) - ]), - - Node(name: "ConstrainedSugarType", - nameForDiagnostics: "type", - kind: "Type", - children: [ - Child(name: "SomeOrAnySpecifier", - kind: .token(choices: [.keyword(text: "some"), .keyword(text: "any")])), - Child(name: "BaseType", - kind: .node(kind: "Type")) - ]), - - Node(name: "DictionaryType", - nameForDiagnostics: "dictionary type", - kind: "Type", - children: [ - Child(name: "LeftSquareBracket", - kind: .token(choices: [.token(tokenKind: "LeftSquareBracketToken")])), - Child(name: "KeyType", - kind: .node(kind: "Type"), - nameForDiagnostics: "key type"), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")])), - Child(name: "ValueType", - kind: .node(kind: "Type"), - nameForDiagnostics: "value type"), - Child(name: "RightSquareBracket", - kind: .token(choices: [.token(tokenKind: "RightSquareBracketToken")])) - ]), - - Node(name: "FunctionType", - nameForDiagnostics: "function type", - kind: "Type", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Arguments", - kind: .collection(kind: "TupleTypeElementList", collectionElementName: "Argument"), - isIndented: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])), - Child(name: "EffectSpecifiers", - kind: .node(kind: "TypeEffectSpecifiers"), - isOptional: true), - Child(name: "Output", - kind: .node(kind: "ReturnClause")) - ]), - - Node(name: "GenericArgumentClause", - nameForDiagnostics: "generic argument clause", - kind: "Syntax", - children: [ - Child(name: "LeftAngleBracket", - kind: .token(choices: [.token(tokenKind: "LeftAngleToken")])), - Child(name: "Arguments", - kind: .collection(kind: "GenericArgumentList", collectionElementName: "Argument")), - Child(name: "RightAngleBracket", - kind: .token(choices: [.token(tokenKind: "RightAngleToken")])) - ]), - - Node(name: "GenericArgumentList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "GenericArgument"), - - Node(name: "GenericArgument", - nameForDiagnostics: "generic argument", - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "ArgumentType", - kind: .node(kind: "Type")), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "ImplicitlyUnwrappedOptionalType", - nameForDiagnostics: "implicitly unwrapped optional type", - kind: "Type", - children: [ - Child(name: "WrappedType", - kind: .node(kind: "Type")), - Child(name: "ExclamationMark", - kind: .token(choices: [.token(tokenKind: "ExclamationMarkToken")])) - ]), - - Node(name: "MemberTypeIdentifier", - nameForDiagnostics: "member type", - kind: "Type", - children: [ - Child(name: "BaseType", - kind: .node(kind: "Type"), - nameForDiagnostics: "base type"), - Child(name: "Period", - kind: .token(choices: [.token(tokenKind: "PeriodToken")])), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken")]), - nameForDiagnostics: "name", - classification: "TypeIdentifier"), - Child(name: "GenericArgumentClause", - kind: .node(kind: "GenericArgumentClause"), - isOptional: true) - ]), - - Node(name: "MetatypeType", - nameForDiagnostics: "metatype", - kind: "Type", - children: [ - Child(name: "BaseType", - kind: .node(kind: "Type"), - nameForDiagnostics: "base type"), - Child(name: "Period", - kind: .token(choices: [.token(tokenKind: "PeriodToken")])), - Child(name: "TypeOrProtocol", - kind: .token(choices: [.keyword(text: "Type"), .keyword(text: "Protocol")])) - ]), - - Node(name: "NamedOpaqueReturnType", - nameForDiagnostics: "named opaque return type", - kind: "Type", - children: [ - Child(name: "GenericParameters", - kind: .node(kind: "GenericParameterClause")), - Child(name: "BaseType", - kind: .node(kind: "Type")) - ]), - - Node(name: "OptionalType", - nameForDiagnostics: "optional type", - kind: "Type", - children: [ - Child(name: "WrappedType", - kind: .node(kind: "Type")), - Child(name: "QuestionMark", - kind: .token(choices: [.token(tokenKind: "PostfixQuestionMarkToken")])) - ]), - - Node(name: "PackExpansionType", - nameForDiagnostics: "variadic expansion", - kind: "Type", - children: [ - Child(name: "RepeatKeyword", - kind: .token(choices: [.keyword(text: "repeat")])), - Child(name: "PatternType", - kind: .node(kind: "Type")) - ]), - - Node(name: "PackReferenceType", - nameForDiagnostics: "pack reference", - kind: "Type", - children: [ - Child(name: "EachKeyword", - kind: .token(choices: [.keyword(text: "each")])), - Child(name: "PackType", - kind: .node(kind: "Type")) - ]), - - Node(name: "SimpleTypeIdentifier", - nameForDiagnostics: "type", - kind: "Type", - children: [ - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "KeywordToken"), .token(tokenKind: "WildcardToken")]), - classification: "TypeIdentifier"), - Child(name: "GenericArgumentClause", - kind: .node(kind: "GenericArgumentClause"), - isOptional: true) - ]), - - Node(name: "TupleTypeElementList", - nameForDiagnostics: nil, - kind: "SyntaxCollection", - element: "TupleTypeElement"), - - Node(name: "TupleTypeElement", - nameForDiagnostics: nil, - kind: "Syntax", - traits: [ - "WithTrailingComma" - ], - children: [ - Child(name: "InOut", - kind: .node(kind: "InoutToken"), - isOptional: true), - Child(name: "Name", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "name", - isOptional: true), - Child(name: "SecondName", - kind: .token(choices: [.token(tokenKind: "IdentifierToken"), .token(tokenKind: "WildcardToken")]), - nameForDiagnostics: "internal name", - isOptional: true), - Child(name: "Colon", - kind: .token(choices: [.token(tokenKind: "ColonToken")]), - isOptional: true), - Child(name: "Type", - kind: .node(kind: "Type")), - Child(name: "Ellipsis", - kind: .token(choices: [.token(tokenKind: "EllipsisToken")]), - isOptional: true), - Child(name: "Initializer", - kind: .node(kind: "InitializerClause"), - isOptional: true), - Child(name: "TrailingComma", - kind: .token(choices: [.token(tokenKind: "CommaToken")]), - isOptional: true) - ]), - - Node(name: "TupleType", - nameForDiagnostics: "tuple type", - kind: "Type", - traits: [ - "Parenthesized" - ], - children: [ - Child(name: "LeftParen", - kind: .token(choices: [.token(tokenKind: "LeftParenToken")])), - Child(name: "Elements", - kind: .collection(kind: "TupleTypeElementList", collectionElementName: "Element"), - isIndented: true), - Child(name: "RightParen", - kind: .token(choices: [.token(tokenKind: "RightParenToken")])) - ]), - -] diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/BuilderInitializableTypes.py b/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/BuilderInitializableTypes.py deleted file mode 100644 index bf7f8b1178d..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/BuilderInitializableTypes.py +++ /dev/null @@ -1,20 +0,0 @@ -BUILDER_INITIALIZABLE_TYPES = { - 'CodeBlock': 'CodeBlockItemList', - 'MemberDeclBlock': 'MemberDeclList', - 'CodeBlockItemList': None, - 'MemberDeclList': None, - 'PatternBindingList': None, - 'SwitchCaseList': None, - 'ArrayElementList': None, - 'TupleExprElementList': None, - 'EnumCaseElementList': None, - 'FunctionParameterList': None, - 'GenericParameterList': None, - 'GenericRequirementList': None, - 'InheritedTypeList': None, - 'ClosureCaptureItemList': None, - 'CaseItemList': None, - 'GenericArgumentList': None, - 'TuplePatternElementList': None, - 'ExprList': None, -} diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/__init__.py b/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/__init__.py deleted file mode 100644 index 2c9f9d51a69..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from .utils import make_swift_child, make_swift_node -from .BuilderInitializableTypes import BUILDER_INITIALIZABLE_TYPES diff --git a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/utils.py b/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/utils.py deleted file mode 100644 index ee60c62d9ee..00000000000 --- a/CodeGeneration/Sources/SyntaxSupport/gyb_helpers/utils.py +++ /dev/null @@ -1,109 +0,0 @@ -from gyb_syntax_support import dedented_lines - -def make_swift_node(node): - """ - Given a Python `Node` from `gyb_syntax_support`, return the source code for matching node definition in Swift. - """ - spaces = 9 - parameters = ['name: "%s"' % node.syntax_kind] - if node.name_for_diagnostics: - parameters += [f'nameForDiagnostics: "{node.name_for_diagnostics}"'] - else: - parameters += ['nameForDiagnostics: nil'] - - if node.description: - parameters += ['description: "%s"' % flat_documentation(node.description)] - - parameters += ['kind: "%s"' % node.kind] - - if node.traits: - mapped_traits = map(lambda x: (' ' * spaces) + '"%s"' % x, node.traits) - parameters += ['traits: [\n%s\n' % ',\n'.join(mapped_traits) + (' ' * (spaces - 2)) + ']'] - - if node.parser_function: - parameters += ['parserFunction: "%s"' % node.parser_function] - - if node.non_unexpected_children: - children = [] - for child in node.non_unexpected_children: - children += [make_swift_child(child, spaces)] - parameters += ['children: [\n%s\n' % ',\n'.join(children) + (' ' * (spaces - 2)) + ']'] - - if node.collection_element != '': - parameters += ['element: "%s"' % node.collection_element] - - if node.element_name: - parameters += ['elementName: "%s"' % node.element_name] - - if node.collection_element_choices : - mapped_collection_element_choices = map(lambda x: '"%s"' % x, node.collection_element_choices) - parameters += ['elementChoices: [%s]' % ', '.join(mapped_collection_element_choices)] - - if node.omit_when_empty: - parameters += ['omitWhenEmpty: true'] - - if node.elements_separated_by_newline: - parameters += ['elementsSeparatedByNewline: true'] - - return 'Node(%s)' % ',\n '.join(parameters) - - -def make_swift_child(child, spaces): - """ - Given a Python `Child` from `gyb_syntax_support`, return the source code for matching child definition in Swift. - """ - parameter_spaces = 8 - parameters = ['name: "%s"' % child.name] - - if child.token_choices: - mapped_choices = [f'.token(tokenKind: "{choice.name}Token")' for (choice, text) in child.token_choices if text is None] - mapped_choices += [f'.keyword(text: "{text}")' for (choice, text) in child.token_choices if text is not None] - joined_choices = ', '.join(mapped_choices) - token_arguments = [f'choices: [{joined_choices}]'] - if child.requires_leading_space is not None: - token_arguments += ['requiresLeadingSpace: ' + ('true' if child.requires_leading_space else 'false')] - if child.requires_trailing_space is not None: - token_arguments += ['requiresTrailingSpace: ' + ('true' if child.requires_trailing_space else 'false')] - arguments = ', '.join(token_arguments) - kind = f'.token({arguments})' - elif child.collection_element_name: - kind = f'.collection(kind: "{child.syntax_kind}", collectionElementName: "{child.collection_element_name}")' - elif child.node_choices: - mapped_node_choices = [make_swift_child(x, 17) for x in child.node_choices] - kind = f'.nodeChoices(choices: [\n%s\n' % (',\n').join(mapped_node_choices) + (' ' * (spaces + parameter_spaces - 2)) + '])' - else: - kind = f'.node(kind: "{child.syntax_kind}")' - - parameters += ['kind: %s' % kind] - - if child.name_for_diagnostics: - parameters += [f'nameForDiagnostics: "{child.name_for_diagnostics}"'] - - if child.description: - parameters += ['description: "%s"' % flat_documentation(child.description)] - - if child.is_optional: - parameters += ['isOptional: true'] - - if child.classification: - parameters += ['classification: "%s"' % child.classification.name] - - if child.force_classification: - parameters += ['forceClassification: true'] - - if child.is_indented: - parameters += ['isIndented: true'] - - if child.requires_leading_newline: - parameters += ['requiresLeadingNewline: true'] - - parameter_spacing = ' ' * (spaces + 6) - return (' ' * spaces) + 'Child(%s)' % (',\n%s' % parameter_spacing).join(parameters) - - -def flat_documentation(indented_documentation): - """ - Creates a single-line documentation string from indented documentation as written in 'gyb_syntax_support' - """ - return " ".join(dedented_lines(indented_documentation)).replace("\n", "").replace('"','\\"').strip() - diff --git a/Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md.gyb b/Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md similarity index 51% rename from Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md.gyb rename to Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md index 25188c569d2..0c82be1603a 100644 --- a/Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md.gyb +++ b/Sources/SwiftSyntax/Documentation.docc/SwiftSyntax.md @@ -58,93 +58,6 @@ allows Swift tools to parse, inspect, generate, and transform Swift source code. - - -### Declarations - -- -- -% for node in SYNTAX_NODES: -% if not node.is_missing() and node.base_type == 'DeclSyntax': -- -% end -% end - -### Statements - -- -- -% for node in SYNTAX_NODES: -% if not node.is_missing() and node.base_type == 'StmtSyntax': -- -% end -% end - -### Expressions - -- -- -% for node in SYNTAX_NODES: -% if not node.is_missing() and node.base_type == 'ExprSyntax': -- -% end -% end - -### Types - -- -- -% for node in SYNTAX_NODES: -% if not node.is_missing() and node.base_type == 'TypeSyntax': -- -% end -% end - -### Patterns - -- -- -% for node in SYNTAX_NODES: -% if not node.is_missing() and node.base_type == 'PatternSyntax': -- -% end -% end - -### Collections - -- -% for node in SYNTAX_NODES: -% if node.collection_element: -% element_node = NODE_MAP.get(node.collection_element) -% if element_node: -- -- -% end -% end -% end -- -- - -### Miscellaneous Syntax - -% for node in SYNTAX_NODES: -% if not node.is_missing() and not node.is_base() and node.base_type == 'Syntax': -- -% end -% end - -### Missing and Unknown Syntax - -% for node in SYNTAX_NODES: -% if node.is_missing(): -- -% end -% end - -### Traits - -% for trait in TRAITS: -- -% end - ### Syntax Position - diff --git a/Sources/SwiftSyntax/Documentation.docc/gyb_generated/SwiftSyntax.md b/Sources/SwiftSyntax/Documentation.docc/gyb_generated/SwiftSyntax.md deleted file mode 100644 index 1c6af00f877..00000000000 --- a/Sources/SwiftSyntax/Documentation.docc/gyb_generated/SwiftSyntax.md +++ /dev/null @@ -1,466 +0,0 @@ -# ``SwiftSyntax`` - -@Comment { - Automatically Generated From SwiftSyntax.md.gyb. - Do Not Edit Directly! -} - -A library for working with Swift code. - -## Overview - -SwiftSyntax is a source accurate tree representation of Swift source code. It -allows Swift tools to parse, inspect, generate, and transform Swift source code. - -## Topics - -### Articles - -- -- -- - -### Tutorials - -- - -### Syntax - -- -- - -### Trivia - -- -- -- - -### Tokens - -- -- -- -- - -### Syntax Visitors - -- -- -- -- -- -- - -### Declarations - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Statements - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Expressions - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Types - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Patterns - -- -- -- -- -- -- -- -- - -### Collections - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Miscellaneous Syntax - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - -### Missing and Unknown Syntax - -- -- -- -- -- -- - -### Traits - -- -- -- -- -- -- -- -- -- -- - -### Syntax Position - -- -- -- -- -- -- - -### Incremental Parsing - -- -- -- -- -- -- - -### Internals - -- -- -- -- -- -- diff --git a/build-script.py b/build-script.py index bfed21efec7..aa81531ced7 100755 --- a/build-script.py +++ b/build-script.py @@ -36,8 +36,6 @@ PACKAGE_DIR, "utils", "incrparse", "incr_transfer_round_trip.py" ) -GYB_EXEC = os.path.join(SWIFT_DIR, "utils", "gyb") - LIT_EXEC = os.path.join(LLVM_DIR, "utils", "lit", "lit.py") GROUP_INFO_PATH = os.path.join(PACKAGE_DIR, "utils", "group.json") @@ -123,157 +121,6 @@ def realpath(path: Optional[str]) -> Optional[str]: # Generating gyb Files -def check_gyb_exec(gyb_exec: str) -> None: - if not os.path.exists(gyb_exec): - fatal_error( - """ -Error: Could not find gyb. -Looking at '%s'. - -Make sure you have the main swift repo checked out next to the swift-syntax -repository. -Refer to README.md for more information. -""" - % gyb_exec - ) - - -def check_rsync() -> None: - if call(["rsync", "--version"], stdout=subprocess.DEVNULL) != 0: - fatal_error("Error: Could not find rsync.") - - -def generate_single_gyb_file( - gyb_exec: str, - gyb_file: str, - output_file_name: str, - destination: str, - temp_files_dir: str, - add_source_locations: bool, - additional_gyb_flags: List[str], - verbose: bool, -) -> None: - # Source locations are added by default by gyb, and cleared by passing - # `--line-directive=` (nothing following the `=`) to the generator. Our - # flag is the reverse; we don't want them by default, only if requested. - line_directive_flags = [] if add_source_locations else ["--line-directive="] - - # Generate the new file - gyb_command = [ - sys.executable, - gyb_exec, - gyb_file, - "-o", - os.path.join(temp_files_dir, output_file_name), - ] - gyb_command += line_directive_flags - gyb_command += additional_gyb_flags - - env = dict() - env["PYTHONPATH"] = PACKAGE_DIR - check_call(gyb_command, env=env, verbose=verbose) - - # Copy the file if different from the file already present in - # gyb_generated - rsync_command = [ - "rsync", - "--checksum", - os.path.join(temp_files_dir, output_file_name), - os.path.join(destination, output_file_name), - ] - - check_call(rsync_command, verbose=verbose) - - -# Generate the `.swift` files for all `.gyb` files in `sources_dir`. If -# `destination_dir` is not `None`, the resulting files will be written to -# `destination_dir`, otherwise they will be written to -# `sources_dir/gyb_generated`. -def generate_gyb_files_helper( - sources_dir: str, - destination_dir: str, - gyb_exec: str, - add_source_locations: bool, - verbose: bool, -) -> None: - temp_files_dir = tempfile.gettempdir() - make_dir_if_needed(temp_files_dir) - make_dir_if_needed(destination_dir) - - # Clear any *.swift files that are relics from the previous run. - clear_gyb_files_from_previous_run( - sources_dir, destination_dir, verbose) - - def generate_gyb_file(gyb_file: str) -> None: - gyb_file_path = os.path.join(sources_dir, gyb_file) - - # Slice off the '.gyb' to get the name for the output file - output_file_name = gyb_file[:-4] - - generate_single_gyb_file( - gyb_exec, - gyb_file_path, - output_file_name, - destination_dir, - temp_files_dir, - add_source_locations, - additional_gyb_flags=[], - verbose=verbose, - ) - - # Generate the new .swift files in `temp_files_dir` and only copy them - # to `destiantion_dir` if they are different than the - # files already residing there. This way we don't touch the generated .swift - # files if they haven't changed and don't trigger a rebuild. - gyb_files = [file for file in os.listdir(sources_dir) if file.endswith(".gyb")] - with ThreadPoolExecutor() as executor: - results = executor.map(generate_gyb_file, gyb_files) - # An exception raised in a thread managed by `ThreadPoolExecutor` only gets - # raised if its value is retrieved. Iterate over all the 'None' results to cause - # the exceptions to be propagated. - for _ in results: - pass - - -# If `temp_directories` is True, creates a dictionary that maps every source dir in -# `source_dirs` to a unique temporary directory. -# If `temp_directories` is False, it maps each source dir to the corresponding -# gyb_generated directory. -def gyb_dir_mapping(temp_directories: bool) -> Dict[str, str]: - source_dirs = [ - SYNTAXSUPPORT_DIR, - SWIFTSYNTAX_DOCUMENTATION_DIR, - ] - mapping = {} - for source_dir in source_dirs: - if temp_directories: - mapping[source_dir] = tempfile.mkdtemp() - else: - mapping[source_dir] = os.path.join(source_dir, "gyb_generated") - return mapping - - -def generate_gyb_files( - gyb_exec: str, gyb_dir_mapping: Dict[str, str], - add_source_locations: bool, verbose: bool, -) -> None: - print("** Generating gyb Files **") - - check_gyb_exec(gyb_exec) - check_rsync() - - for source_dir, destination_dir in gyb_dir_mapping.items(): - generate_gyb_files_helper( - source_dir, - destination_dir, - gyb_exec, - add_source_locations, - verbose - ) - - print("** Done Generating gyb Files **") - - def run_code_generation( source_dir: str, toolchain: str, @@ -297,29 +144,6 @@ def run_code_generation( check_call(swiftpm_call, env=env, verbose=verbose) -def make_dir_if_needed(path: str) -> None: - if not os.path.exists(path): - os.makedirs(path) - - -# Remove any files in the `gyb_generated` directory that no longer have a -# corresponding `.gyb` file in the `Sources` directory. -def clear_gyb_files_from_previous_run( - sources_dir: str, destination_dir: str, verbose: bool -) -> None: - for previous_gyb_gen_file in os.listdir(destination_dir): - if previous_gyb_gen_file.endswith(".swift"): - gyb_file = os.path.join( - sources_dir, previous_gyb_gen_file + ".gyb" - ) - if not os.path.exists(gyb_file): - check_call( - ["rm", previous_gyb_gen_file], - cwd=destination_dir, - verbose=verbose - ) - - # ----------------------------------------------------------------------------- # Building SwiftSyntax @@ -408,27 +232,6 @@ def __build(self, package_dir: str, product_name: str) -> None: # Testing -def verify_gyb_generated_files(gyb_exec: str, verbose: bool) -> None: - gyb_dirs = gyb_dir_mapping(temp_directories=True) - - generate_gyb_files( - gyb_exec, - gyb_dir_mapping=gyb_dirs, - add_source_locations=False, - verbose=verbose, - ) - - for source_dir, destination_dir in gyb_dirs.items(): - if destination_dir is None: - raise ValueError('gyb_dir_mapping should have custom temp dirs') - - pre_generated_dir = os.path.join(source_dir, "gyb_generated") - check_generated_files_match( - pre_generated_dir, - destination_dir - ) - - def verify_code_generated_files( toolchain: str, verbose: bool ) -> None: @@ -627,22 +430,11 @@ def generate_xcodeproj(args: argparse.Namespace) -> None: def generate_source_code_command(args: argparse.Namespace) -> None: try: - generate_gyb_files( - args.gyb_exec, - gyb_dir_mapping=gyb_dir_mapping(temp_directories=False), - add_source_locations=args.add_source_locations, - verbose=args.verbose, + run_code_generation( + source_dir=SOURCES_DIR, + toolchain=args.toolchain, + verbose=args.verbose ) - except subprocess.CalledProcessError as e: - fail_for_called_process_error("Generating .gyb files failed", e) - - try: - if not args.gyb_only: - run_code_generation( - source_dir=SOURCES_DIR, - toolchain=args.toolchain, - verbose=args.verbose - ) except subprocess.CalledProcessError as e: fail_for_called_process_error( "Source generation using SwiftSyntaxBuilder failed", e) @@ -650,18 +442,15 @@ def generate_source_code_command(args: argparse.Namespace) -> None: def verify_source_code_command(args: argparse.Namespace) -> None: try: - verify_gyb_generated_files(args.gyb_exec, verbose=args.verbose) - - if not args.gyb_only: - verify_code_generated_files( - toolchain=args.toolchain, - verbose=args.verbose, - ) + verify_code_generated_files( + toolchain=args.toolchain, + verbose=args.verbose, + ) except subprocess.CalledProcessError: printerr( - "FAIL: Gyb-generated files committed to repository do " + + "FAIL: code-generated files committed to repository do " + "not match generated ones. Please re-generate the " + - "gyb-files using the following command, open a PR to the " + + "code-generated-files using the following command, open a PR to the " + "SwiftSyntax project and merge it alongside the main PR." + "$ swift-syntax/build-script.py generate-source-code " + "--toolchain /path/to/toolchain.xctoolchain/usr" @@ -790,20 +579,6 @@ def add_generate_source_code_args(parser: argparse.ArgumentParser) -> None: help="The path to the toolchain that shall be used to build SwiftSyntax.", ) - parser.add_argument( - "--gyb-exec", - default=GYB_EXEC, - help="Path to the gyb tool (default: %(default)s).", - ) - - parser.add_argument( - "--gyb-only", - action="store_true", - help=""" - Only generate gyb templates (and not generate-swift-syntax-builder's templates) - """, - ) - parser.add_argument( "-v", "--verbose", action="store_true", help="Enable verbose logging." ) diff --git a/gyb_syntax_support/AttributeKinds.py b/gyb_syntax_support/AttributeKinds.py deleted file mode 100644 index 7ed8de63102..00000000000 --- a/gyb_syntax_support/AttributeKinds.py +++ /dev/null @@ -1,933 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 -from .Utils import error - -class Attribute(object): - def __init__(self, name, swift_name=None): - self.name = name - self.swift_name = swift_name or name - -class TypeAttribute(Attribute): - def __init__(self, name): - super().__init__(name, name) - -class DeclAttribute(Attribute): - def __init__(self, name, class_name, *options, code, swift_name=None): - super().__init__(name, swift_name) - self.class_name = class_name - self.options = options - self.code = code - -class SimpleDeclAttribute(DeclAttribute): - def __init__(self, name, class_name, *options, code, swift_name=None): - super().__init__(name, class_name, *options, code=code, swift_name=swift_name) - -class ContextualDeclAttribute(DeclAttribute): - def __init__(self, name, class_name, *options, code): - super().__init__(name, class_name, *options, code=code) - -class ContextualSimpleDeclAttribute(SimpleDeclAttribute): - def __init__(self, name, class_name, *options, code): - super().__init__(name, class_name, *options, code=code) - -class DeclAttributeAlias(Attribute): - def __init__(self, name, class_name, swift_name=None): - super().__init__(name, swift_name) - self.class_name = class_name - -class ContextualDeclAttributeAlias(DeclAttributeAlias): - def __init__(self, name, class_name, swift_name=None): - super().__init__(name, class_name, swift_name) - -class BuiltinDeclModifier(Attribute): - def __init__(self, name, swift_name=None): - super().__init__(name, swift_name) - -# Abstract class aggregations for use in Attr.def. -OnValue = 'OnValue' -OnTypeAlias = 'OnTypeAlias' -OnEnumElement = 'OnEnumElement' -OnMacro = 'OnMacro' -OnSubscript = 'OnSubscript' -OnVar = 'OnVar' -OnExtension = 'OnExtension' -OnClass = 'OnClass' -OnFunc = 'OnFunc' -OnAccessor = 'OnAccessor' -OnEnum = 'OnEnum' -OnConstructor = 'OnConstructor' -OnStruct = 'OnStruct' -OnImport = 'OnImport' -OnAssociatedType = 'OnAssociatedType' -OnGenericTypeParam = 'OnGenericTypeParam' -OnParam = 'OnParam' -OnNominalType = 'OnNominalType' -OnProtocol = 'OnProtocol' -OnConcreteNominalType = 'OnConcreteNominalType' -OnGenericType = 'OnGenericType' -OnAbstractFunction = 'OnAbstractFunction' -OnOperator = 'OnOperator' -OnAnyDecl = 'OnAnyDecl' - -# True if multiple instances of this attribute are allowed on a single -# declaration. -AllowMultipleAttributes = 'AllowMultipleAttributes' - -# True if this is a decl modifier - i.e., that it should not be spelled -# with an @. -DeclModifier = 'DeclModifier' - -# True if this is a long attribute that should be printed on its own line. -# -# Currently has no effect on DeclModifier attributes. -LongAttribute = 'LongAttribute' - -# True if this shouldn't be serialized. -NotSerialized = 'NotSerialized' - -# True if this attribute is only valid when parsing a .sil file. -SILOnly = 'SILOnly' - -# The attribute should be reported by parser as unknown. -RejectByParser = 'RejectByParser' - -# Whether client code cannot use the attribute. -UserInaccessible = 'UserInaccessible' - -# Whether adding this attribute can break API -APIBreakingToAdd = 'APIBreakingToAdd' - -# Whether removing this attribute can break API -APIBreakingToRemove = 'APIBreakingToRemove' - -# Whether adding this attribute can break ABI -ABIBreakingToAdd = 'ABIBreakingToAdd' - -# Whether removing this attribute can break ABI -ABIBreakingToRemove = 'ABIBreakingToRemove' - -# The opposite of APIBreakingToAdd -APIStableToAdd = 'APIStableToAdd' - -# The opposite of APIBreakingToRemove -APIStableToRemove = 'APIStableToRemove' - -# The opposite of ABIBreakingToAdd -ABIStableToAdd = 'ABIStableToAdd' - -# The opposite of ABIBreakingToRemove -ABIStableToRemove = 'ABIStableToRemove' - -# Whether this attribute is only valid when concurrency is enabled. -ConcurrencyOnly = 'ConcurrencyOnly' - -# Whether this attribute is valid on additional decls in ClangImporter. -OnAnyClangDecl = 'OnAnyClangDecl' - -# Type attributes -TYPE_ATTR_KINDS = [ - TypeAttribute('autoclosure'), - TypeAttribute('convention'), - TypeAttribute('noescape'), - TypeAttribute('escaping'), - TypeAttribute('differentiable'), - TypeAttribute('noDerivative'), - TypeAttribute('async'), - TypeAttribute('Sendable'), - TypeAttribute('unchecked'), - TypeAttribute('_local'), - TypeAttribute('_noMetadata'), - - # Generated interface attributes - TypeAttribute('_opaqueReturnTypeOf'), -] - -# Schema for `DeclAttribute`s: -# -# - Attribute name. -# - C++ class name without the 'Attr' suffix -# - Options for the attribute, including: -# * the declarations the attribute can appear on -# * whether duplicates are allowed -# - Unique attribute identifier used for serialization. This -# can never be changed. -# -# SimpleDeclAttribute is the same, but the class becomes -# SimpleDeclAttr on the C++ side. -# -# Please help ease code review/audits: -# - Please place the "OnXYZ" flags together on the next line. -# - Please place the non-OnXYZ flags together on the next to last line. -# - Please place the unique code number on the last line. -# - Please sort attributes by serialization number. -# - Please create a "NOTE" comment if a unique number is skipped. -# -# If you're adding a new kind of "attribute" that is spelled without a leading -# '@' symbol, add an entry to the `DECL_MODIFIER_KINDS` array instead. -# -# If you're adding a new underscored attribute here, please document it in -# docs/ReferenceGuides/UnderscoredAttributes.md. -DECL_ATTR_KINDS = [ - DeclAttribute('_silgen_name', 'SILGenName', - OnAbstractFunction, - LongAttribute, UserInaccessible, ABIStableToAdd, ABIStableToRemove, - APIStableToAdd, APIStableToRemove, - code=0), - DeclAttribute('available', 'Available', - OnAbstractFunction, OnGenericType, OnVar, OnSubscript, OnEnumElement, OnMacro, - OnExtension, AllowMultipleAttributes, LongAttribute, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=1), - DeclAttribute('objc', 'ObjC', - OnAbstractFunction, OnClass, OnProtocol, OnExtension, OnVar, - OnSubscript, OnEnum, OnEnumElement, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=3), - SimpleDeclAttribute('dynamicCallable', 'DynamicCallable', - OnNominalType, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=6), - DeclAttribute('main', 'MainType', - OnClass, OnStruct, OnEnum, OnExtension, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=7), - SimpleDeclAttribute('_exported', 'Exported', - OnImport, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=8), - SimpleDeclAttribute('dynamicMemberLookup', 'DynamicMemberLookup', - OnNominalType, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=9), - SimpleDeclAttribute('NSCopying', 'NSCopying', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=10), - SimpleDeclAttribute('IBAction', 'IBAction', - OnFunc, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=11), - SimpleDeclAttribute('IBDesignable', 'IBDesignable', - OnClass, OnExtension, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=12), - SimpleDeclAttribute('IBInspectable', 'IBInspectable', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=13), - SimpleDeclAttribute('IBOutlet', 'IBOutlet', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=14), - SimpleDeclAttribute('NSManaged', 'NSManaged', - OnVar, OnFunc, OnAccessor, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=15), - SimpleDeclAttribute('LLDBDebuggerFunction', 'LLDBDebuggerFunction', - OnFunc, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=17), - SimpleDeclAttribute('UIApplicationMain', 'UIApplicationMain', - OnClass, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=18), - SimpleDeclAttribute('unsafe_no_objc_tagged_pointer', 'UnsafeNoObjCTaggedPointer', - OnProtocol, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=19), - DeclAttribute('inline', 'Inline', - OnVar, OnSubscript, OnAbstractFunction, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=20), - DeclAttribute('_semantics', 'Semantics', - OnAbstractFunction, OnSubscript, OnNominalType, OnVar, - AllowMultipleAttributes, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=21), - SimpleDeclAttribute('_transparent', 'Transparent', - OnFunc, OnAccessor, OnConstructor, OnVar, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=26), - SimpleDeclAttribute('requires_stored_property_inits', 'RequiresStoredPropertyInits', - OnClass, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=27), - SimpleDeclAttribute('nonobjc', 'NonObjC', - OnExtension, OnFunc, OnAccessor, OnVar, OnSubscript, OnConstructor, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=30), - SimpleDeclAttribute('_fixed_layout', 'FixedLayout', - OnVar, OnClass, OnStruct, OnProtocol, - UserInaccessible, ABIBreakingToAdd, ABIBreakingToRemove, - APIStableToAdd, APIStableToRemove, - code=31), - SimpleDeclAttribute('inlinable', 'Inlinable', - OnVar, OnSubscript, OnAbstractFunction, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=32), - DeclAttribute('_specialize', 'Specialize', - OnConstructor, OnFunc, OnAccessor, - AllowMultipleAttributes, LongAttribute, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=33), - SimpleDeclAttribute('objcMembers', 'ObjCMembers', - OnClass, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=34), - ContextualSimpleDeclAttribute('_compilerInitialized', 'CompilerInitialized', - OnVar, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=35), - SimpleDeclAttribute('_hasStorage', 'HasStorage', - OnVar, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=45), - DeclAttribute('__raw_doc_comment', 'RawDocComment', - OnAnyDecl, - UserInaccessible, - RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=48), - DeclAttribute('_effects', 'Effects', - OnAbstractFunction, - AllowMultipleAttributes, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=50), - DeclAttribute('__objc_bridged', 'ObjCBridged', - OnClass, - UserInaccessible, - RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=51), - SimpleDeclAttribute('NSApplicationMain', 'NSApplicationMain', - OnClass, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=52), - SimpleDeclAttribute('_objc_non_lazy_realization', 'ObjCNonLazyRealization', - OnClass, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=53), - DeclAttribute('__synthesized_protocol', 'SynthesizedProtocol', - OnConcreteNominalType, - UserInaccessible, - RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=54), - SimpleDeclAttribute('testable', 'Testable', - OnImport, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=55), - DeclAttribute('_alignment', 'Alignment', - OnStruct, OnEnum, - UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=56), - SimpleDeclAttribute('rethrows', 'AtRethrows', - OnProtocol, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - swift_name='atRethrows', - code=58), - DeclAttribute('_swift_native_objc_runtime_base', 'SwiftNativeObjCRuntimeBase', - OnClass, - UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=59), - SimpleDeclAttribute('warn_unqualified_access', 'WarnUnqualifiedAccess', - OnFunc, OnAccessor, #| OnVar - LongAttribute, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=61), - SimpleDeclAttribute('_show_in_interface', 'ShowInInterface', - OnProtocol, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=62), - DeclAttribute('_cdecl', 'CDecl', - OnFunc, OnAccessor, - LongAttribute, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=63), - SimpleDeclAttribute('usableFromInline', 'UsableFromInline', - OnAbstractFunction, OnVar, OnSubscript, OnNominalType, OnTypeAlias, - LongAttribute, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=64), - SimpleDeclAttribute('discardableResult', 'DiscardableResult', - OnFunc, OnAccessor, OnConstructor, - LongAttribute, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=65), - SimpleDeclAttribute('GKInspectable', 'GKInspectable', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=66), - DeclAttribute('_implements', 'Implements', - OnFunc, OnAccessor, OnVar, OnSubscript, OnTypeAlias, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=67), - DeclAttribute('_objcRuntimeName', 'ObjCRuntimeName', - OnClass, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=68), - SimpleDeclAttribute('_staticInitializeObjCMetadata', 'StaticInitializeObjCMetadata', - OnClass, - UserInaccessible, - LongAttribute, RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=69), - DeclAttribute('_restatedObjCConformance', 'RestatedObjCConformance', - OnProtocol, - UserInaccessible, - LongAttribute, RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=70), - # NOTE: 71 is unused - DeclAttribute('_objcImplementation', 'ObjCImplementation', - OnExtension, - UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=72), - DeclAttribute('_optimize', 'Optimize', - OnAbstractFunction, OnSubscript, OnVar, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=73), - DeclAttribute('_clangImporterSynthesizedType', 'ClangImporterSynthesizedType', - OnGenericType, - LongAttribute, RejectByParser, UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=74), - SimpleDeclAttribute('_weakLinked', 'WeakLinked', - OnNominalType, OnAssociatedType, OnFunc, OnAccessor, OnVar, - OnSubscript, OnConstructor, OnEnumElement, OnExtension, OnImport, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=75), - SimpleDeclAttribute('frozen', 'Frozen', - OnEnum, OnStruct, ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToRemove, APIStableToAdd, - code=76), - DeclAttributeAlias('_frozen', 'Frozen'), - SimpleDeclAttribute('_forbidSerializingReference', 'ForbidSerializingReference', - OnAnyDecl, - LongAttribute, RejectByParser, UserInaccessible, NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=77), - SimpleDeclAttribute('_hasInitialValue', 'HasInitialValue', - OnVar, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=78), - SimpleDeclAttribute('_nonoverride', 'NonOverride', - OnFunc, OnAccessor, OnVar, OnSubscript, OnConstructor, OnAssociatedType, - UserInaccessible, NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=79), - DeclAttribute('_dynamicReplacement', 'DynamicReplacement', - OnAbstractFunction, OnVar, OnSubscript, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=80), - SimpleDeclAttribute('_borrowed', 'Borrowed', - OnVar, OnSubscript, UserInaccessible, - NotSerialized, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=81), - DeclAttribute('_private', 'PrivateImport', - OnImport, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=82), - SimpleDeclAttribute('_alwaysEmitIntoClient', 'AlwaysEmitIntoClient', - OnVar, OnSubscript, OnAbstractFunction, UserInaccessible, - ABIBreakingToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=83), - - SimpleDeclAttribute('_implementationOnly', 'ImplementationOnly', - OnImport, OnFunc, OnConstructor, OnVar, OnSubscript, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=84), - DeclAttribute('_custom', 'Custom', - OnAnyDecl, RejectByParser, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=85), - SimpleDeclAttribute('propertyWrapper', 'PropertyWrapper', - OnStruct, OnClass, OnEnum, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=86), - SimpleDeclAttribute('_disfavoredOverload', 'DisfavoredOverload', - OnAbstractFunction, OnVar, OnSubscript, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=87), - SimpleDeclAttribute('resultBuilder', 'ResultBuilder', - OnNominalType, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=88), - DeclAttribute('_projectedValueProperty', 'ProjectedValueProperty', - OnVar, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=89), - SimpleDeclAttribute('_nonEphemeral', 'NonEphemeral', - OnParam, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIBreakingToAdd, APIStableToRemove, - code=90), - - DeclAttribute('differentiable', 'Differentiable', - OnAccessor, OnConstructor, OnFunc, OnVar, OnSubscript, LongAttribute, - AllowMultipleAttributes, - ABIStableToAdd, ABIBreakingToRemove, APIStableToAdd, APIBreakingToRemove, - code=91), - - SimpleDeclAttribute('_hasMissingDesignatedInitializers', - 'HasMissingDesignatedInitializers', - OnClass, UserInaccessible, NotSerialized, - APIBreakingToAdd, ABIBreakingToAdd, APIStableToRemove, ABIStableToRemove, - code=92), - - SimpleDeclAttribute('_inheritsConvenienceInitializers', - 'InheritsConvenienceInitializers', - OnClass, UserInaccessible, NotSerialized, - APIStableToAdd, ABIStableToAdd, APIBreakingToRemove, ABIBreakingToRemove, - code=93), - - DeclAttribute('_typeEraser', 'TypeEraser', - OnProtocol, UserInaccessible, - ABIStableToAdd, ABIBreakingToRemove, APIStableToAdd, APIBreakingToRemove, - code=94), - - SimpleDeclAttribute('IBSegueAction', 'IBSegueAction', - OnFunc, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=95), - - DeclAttribute('_originallyDefinedIn', 'OriginallyDefinedIn', - OnNominalType, OnFunc, OnVar, OnExtension, UserInaccessible, - AllowMultipleAttributes, LongAttribute, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=96), - - DeclAttribute('derivative', 'Derivative', - OnFunc, LongAttribute, AllowMultipleAttributes, - ABIStableToAdd, ABIBreakingToRemove, APIStableToAdd, APIBreakingToRemove, - code=97), - - DeclAttribute('_spi', 'SPIAccessControl', - OnAbstractFunction, OnExtension, OnGenericType, OnVar, OnSubscript, - OnImport, OnAccessor, OnEnumElement, OnMacro, - AllowMultipleAttributes, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIBreakingToAdd, APIStableToRemove, - code=98), - - DeclAttribute('transpose', 'Transpose', - OnFunc, LongAttribute, AllowMultipleAttributes, - ABIStableToAdd, ABIBreakingToRemove, APIStableToAdd, APIBreakingToRemove, - code=99), - - SimpleDeclAttribute('noDerivative', 'NoDerivative', - OnAbstractFunction, OnVar, OnSubscript, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=100), - - # 101 was @asyncHandler and is now unused - - SimpleDeclAttribute('globalActor', 'GlobalActor', - OnClass, OnStruct, OnEnum, - ABIStableToAdd, ABIBreakingToRemove, - APIStableToAdd, APIBreakingToRemove, - code=104), - - SimpleDeclAttribute('_specializeExtension', 'SpecializeExtension', - OnExtension, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=105), - - SimpleDeclAttribute('Sendable', 'Sendable', - OnFunc, OnConstructor, OnAccessor, OnAnyClangDecl, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=107), - - SimpleDeclAttribute('_marker', 'Marker', - OnProtocol, UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=108), - - SimpleDeclAttribute('reasync', 'AtReasync', - OnProtocol, ConcurrencyOnly, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - swift_name='atReasync', - code=110), - - # 111 was an experimental @completionHandlerAsync and is now unused - - # 113 was experimental _unsafeSendable and is now unused - - SimpleDeclAttribute('_unsafeInheritExecutor', 'UnsafeInheritExecutor', - OnFunc, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, - code=114), # previously experimental _unsafeMainActor - - SimpleDeclAttribute('_implicitSelfCapture', 'ImplicitSelfCapture', - OnParam, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, - code=115), - - SimpleDeclAttribute('_inheritActorContext', 'InheritActorContext', - OnParam, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=116), - - SimpleDeclAttribute('_eagerMove', 'EagerMove', - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, - APIStableToAdd, APIStableToRemove, - OnFunc, OnParam, OnVar, OnNominalType, - code=117), - - SimpleDeclAttribute('_lexicalLifetimes', 'LexicalLifetimes', - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, - APIStableToAdd, APIStableToRemove, - OnFunc, code=36), - - SimpleDeclAttribute('_noEagerMove', 'NoEagerMove', - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, - APIStableToAdd, APIStableToRemove, - OnFunc, OnParam, OnVar, OnNominalType, - code=119), - - SimpleDeclAttribute('_assemblyVision', 'EmitAssemblyVisionRemarks', - OnFunc, UserInaccessible, NotSerialized, OnNominalType, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=120), - - DeclAttribute('_nonSendable', 'NonSendable', - OnNominalType, - UserInaccessible, AllowMultipleAttributes, - ABIStableToAdd, ABIBreakingToRemove, - APIStableToAdd, APIBreakingToRemove, - code=121), - - SimpleDeclAttribute('_noImplicitCopy', 'NoImplicitCopy', - UserInaccessible, - ABIStableToAdd, ABIBreakingToRemove, - APIStableToAdd, APIBreakingToRemove, - OnFunc, OnParam, OnVar, - code=122), - - SimpleDeclAttribute('_noLocks', 'NoLocks', - OnAbstractFunction, OnSubscript, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=123), - - SimpleDeclAttribute('_noAllocation', 'NoAllocation', - OnAbstractFunction, OnSubscript, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=124), - - SimpleDeclAttribute('preconcurrency', 'Preconcurrency', - OnFunc, OnConstructor, OnProtocol, OnGenericType, OnVar, OnSubscript, - OnEnumElement, OnImport, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=125), - - DeclAttribute('_unavailableFromAsync', 'UnavailableFromAsync', - OnFunc, OnConstructor, OnMacro, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, - APIBreakingToAdd, APIStableToRemove, - code=127), - - DeclAttribute('exclusivity', 'Exclusivity', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=128), - - DeclAttribute('backDeployed', 'BackDeployed', - OnAbstractFunction, OnAccessor, OnSubscript, OnVar, - AllowMultipleAttributes, LongAttribute, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIBreakingToRemove, - code=129), - DeclAttributeAlias('_backDeploy', 'BackDeployed'), - - SimpleDeclAttribute('_moveOnly', 'MoveOnly', - OnNominalType, - UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=131), - - SimpleDeclAttribute('_alwaysEmitConformanceMetadata', 'AlwaysEmitConformanceMetadata', - OnProtocol, UserInaccessible, ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=132), - - DeclAttribute('_expose', 'Expose', - OnFunc, OnNominalType, OnVar, OnConstructor, - LongAttribute, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=133), - - SimpleDeclAttribute('typeWrapper', 'TypeWrapper', - OnStruct, OnClass, OnEnum, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=134), - - SimpleDeclAttribute('_spiOnly', 'SPIOnly', - OnImport, UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=135), - DeclAttribute('_documentation', 'Documentation', - OnAnyDecl, UserInaccessible, - APIBreakingToAdd, APIStableToRemove, ABIStableToAdd, ABIStableToRemove, - code=136), - - SimpleDeclAttribute('typeWrapperIgnored', 'TypeWrapperIgnored', - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=137), - - SimpleDeclAttribute('_noMetadata', 'NoMetadata', - OnGenericTypeParam, - UserInaccessible, - NotSerialized, - ABIStableToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=138), - - SimpleDeclAttribute('runtimeMetadata', 'RuntimeMetadata', - OnStruct, OnClass, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=139) -] - -# Schema for declaration modifiers: -# -# - Modifier name. -# - C++ class name without the 'Attr' suffix -# - Options for the attribute, including: -# * the declarations the attribute can appear on -# * whether duplicates are allowed -# - Unique attribute identifier used for serialization. This -# can never be changed. -# -# SimpleDeclAttribute is the same, but the class becomes -# SimpleDeclAttr on the C++ side. -# -# Please help ease code review/audits: -# - Please place the "OnXYZ" flags together on the next line. -# - Please place the non-OnXYZ flags together on the next to last line. -# - Please place the unique code number on the last line. -# - Please sort attributes by serialization number. -# - Please create a "NOTE" comment if a unique number is skipped. -# -# If you're adding a new kind of attribute that is spelled with a leading -# '@' symbol, add an entry to the `DECL_ATTR_KINDS` array instead. -DECL_MODIFIER_KINDS = [ - # These are not really attributes or modifiers in the C++ AST and they are - # serialized directly into the ASTs they are attached to rather than using - # the generic attribute serialization infrastructure. - BuiltinDeclModifier('static', swift_name='`static`'), - BuiltinDeclModifier('class', swift_name='`class`'), - - ContextualSimpleDeclAttribute('final', 'Final', - OnClass, OnFunc, OnAccessor, OnVar, OnSubscript, - DeclModifier, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=2), - ContextualSimpleDeclAttribute('required', 'Required', - OnConstructor, - DeclModifier, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=4), - ContextualSimpleDeclAttribute('optional', 'Optional', - OnConstructor, OnFunc, OnAccessor, OnVar, OnSubscript, - DeclModifier, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=5), - ContextualSimpleDeclAttribute('lazy', 'Lazy', DeclModifier, - OnVar, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=16), - ContextualSimpleDeclAttribute('dynamic', 'Dynamic', - OnFunc, OnAccessor, OnVar, OnSubscript, OnConstructor, - DeclModifier, ABIBreakingToAdd, ABIBreakingToRemove, - APIStableToAdd, APIStableToRemove, - code=22), - ContextualSimpleDeclAttribute('infix', 'Infix', - OnFunc, OnOperator, - DeclModifier, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=23), - ContextualSimpleDeclAttribute('prefix', 'Prefix', - OnFunc, OnOperator, - DeclModifier, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=24), - ContextualSimpleDeclAttribute('postfix', 'Postfix', - OnFunc, OnOperator, - DeclModifier, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=25), - ContextualSimpleDeclAttribute('__consuming', 'LegacyConsuming', - OnFunc, OnAccessor, - DeclModifier, - UserInaccessible, - NotSerialized, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=40), - ContextualSimpleDeclAttribute('mutating', 'Mutating', - OnFunc, OnAccessor, - DeclModifier, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=41), - ContextualSimpleDeclAttribute('nonmutating', 'NonMutating', - OnFunc, OnAccessor, - DeclModifier, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=42), - ContextualSimpleDeclAttribute('convenience', 'Convenience', - OnConstructor, - DeclModifier, - NotSerialized, - ABIBreakingToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=43), - ContextualSimpleDeclAttribute('override', 'Override', - OnFunc, OnAccessor, OnVar, OnSubscript, OnConstructor, OnAssociatedType, - DeclModifier, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=44), - DeclAttribute('private', 'AccessControl', - OnFunc, OnAccessor, OnExtension, OnGenericType, OnVar, OnSubscript, - OnConstructor, OnMacro, OnImport, - DeclModifier, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - swift_name='`private`', - code=46), - DeclAttributeAlias('fileprivate', 'AccessControl', swift_name='`fileprivate`'), - DeclAttributeAlias('internal', 'AccessControl', swift_name='`internal`'), - DeclAttributeAlias('public', 'AccessControl', swift_name='`public`'), - ContextualDeclAttributeAlias('package', 'AccessControl'), - ContextualDeclAttributeAlias('open', 'AccessControl'), - DeclAttribute('__setter_access', 'SetterAccess', - OnVar, OnSubscript, - DeclModifier, RejectByParser, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=47), - ContextualDeclAttribute('weak', 'ReferenceOwnership', - OnVar, - DeclModifier, - NotSerialized, - ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, - code=49), - ContextualDeclAttributeAlias('unowned', 'ReferenceOwnership', swift_name='unowned'), - - SimpleDeclAttribute('rethrows', 'Rethrows', - OnFunc, OnConstructor, - RejectByParser, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=57, - swift_name='`rethrows`'), - - ContextualSimpleDeclAttribute('indirect', 'Indirect', DeclModifier, - OnEnum, OnEnumElement, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=60), - - ContextualSimpleDeclAttribute('isolated', 'Isolated', - DeclModifier, OnParam, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=103), - - ContextualSimpleDeclAttribute('async', 'Async', - DeclModifier, OnVar, OnFunc, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=106), - - SimpleDeclAttribute('reasync', 'Reasync', - OnFunc, OnConstructor, - RejectByParser, - ABIBreakingToAdd, ABIBreakingToRemove, APIBreakingToAdd, APIBreakingToRemove, - code=109), - - ContextualSimpleDeclAttribute('nonisolated', 'Nonisolated', - DeclModifier, OnFunc, OnConstructor, OnVar, OnSubscript, - ABIStableToAdd, ABIStableToRemove, - APIBreakingToAdd, APIStableToRemove, - code=112), - - ContextualSimpleDeclAttribute('distributed', 'DistributedActor', - DeclModifier, OnClass, OnFunc, OnAccessor, OnVar, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=118), - - ContextualSimpleDeclAttribute('_const', 'CompileTimeConst', - DeclModifier, OnParam, OnVar, - UserInaccessible, - ABIStableToAdd, ABIStableToRemove, APIBreakingToAdd, APIStableToRemove, - code=126), - - ContextualSimpleDeclAttribute('_local', 'KnownToBeLocal', - DeclModifier, OnFunc, OnParam, OnVar, - UserInaccessible, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=130), - - ContextualSimpleDeclAttribute('consuming', 'Consuming', - OnFunc, OnAccessor, - DeclModifier, - UserInaccessible, - NotSerialized, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=140), - ContextualSimpleDeclAttribute('borrowing', 'Borrowing', - OnFunc, OnAccessor, - DeclModifier, - UserInaccessible, - NotSerialized, - ABIBreakingToAdd, ABIBreakingToRemove, APIStableToAdd, APIStableToRemove, - code=141), -] - -DEPRECATED_MODIFIER_KINDS = [ - # TODO: Remove this once we don't need to support 'actor' as a modifier - ContextualSimpleDeclAttribute('actor', 'Actor', - DeclModifier, OnClass, ConcurrencyOnly, - ABIBreakingToAdd, ABIBreakingToRemove, - APIBreakingToAdd, APIBreakingToRemove, - code=102), -] - -def verify_attribute_serialization_codes(nodes): - # Verify that no serialization code is used twice - used_codes = set() - for node in nodes: - if isinstance(node, DeclAttribute): - if node.code in used_codes: - error("Serialization code %d used twice" % node.code) - used_codes.add(node.code) diff --git a/gyb_syntax_support/AttributeNodes.py b/gyb_syntax_support/AttributeNodes.py deleted file mode 100644 index c7b1428a84e..00000000000 --- a/gyb_syntax_support/AttributeNodes.py +++ /dev/null @@ -1,539 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -ATTRIBUTE_NODES = [ - # attribute -> '@' identifier '('? - # ( identifier - # | string-literal - # | integer-literal - # | availability-spec-list - # | specialize-attr-spec-list - # | implements-attr-arguments - # | named-attribute-string-argument - # | back-deploy-attr-spec-list - # )? ')'? - Node('Attribute', name_for_diagnostics='attribute', kind='Syntax', - description=''' - An `@` attribute. - ''', - parser_function='parseAttribute', - children=[ - Child('AtSignToken', kind='AtSignToken', - description='The `@` sign.'), - Child('AttributeName', kind='Type', name_for_diagnostics='name', - classification='Attribute', - description='The name of the attribute.'), - Child('LeftParen', kind='LeftParenToken', is_optional=True, - description=''' - If the attribute takes arguments, the opening parenthesis. - '''), - Child('Argument', kind='Syntax', is_optional=True, - node_choices=[ - Child('ArgumentList', kind='TupleExprElementList'), - Child('Token', kind='Token'), - Child('String', kind='StringLiteralExpr'), - Child('Availability', kind='AvailabilitySpecList'), - Child('SpecializeArguments', - kind='SpecializeAttributeSpecList'), - Child('ObjCName', kind='ObjCSelector'), - Child('ImplementsArguments', - kind='ImplementsAttributeArguments'), - Child('DifferentiableArguments', - kind='DifferentiableAttributeArguments'), - Child('DerivativeRegistrationArguments', - kind='DerivativeRegistrationAttributeArguments'), - Child('BackDeployedArguments', - kind='BackDeployedAttributeSpecList'), - Child('ConventionArguments', - kind='ConventionAttributeArguments'), - Child('ConventionWitnessMethodArguments', - kind='ConventionWitnessMethodAttributeArguments'), - Child('OpaqueReturnTypeOfAttributeArguments', - kind='OpaqueReturnTypeOfAttributeArguments'), - Child('ExposeAttributeArguments', - kind='ExposeAttributeArguments'), - Child('OriginallyDefinedInArguments', - kind='OriginallyDefinedInArguments'), - Child('UnderscorePrivateAttributeArguments', - kind='UnderscorePrivateAttributeArguments'), - Child('DynamicReplacementArguments', - kind='DynamicReplacementArguments'), - Child('UnavailableFromAsyncArguments', - kind='UnavailableFromAsyncArguments'), - Child('EffectsArguments', - kind='EffectsArguments'), - Child('DocumentationArguments', - kind='DocumentationAttributeArguments') - ], description=''' - The arguments of the attribute. In case the attribute - takes multiple arguments, they are gather in the - appropriate takes first. - '''), - Child('RightParen', kind='RightParenToken', is_optional=True, - description=''' - If the attribute takes arguments, the closing parenthesis. - ''') - ]), - - # attribute-list -> attribute attribute-list? - Node('AttributeList', name_for_diagnostics='attributes', kind='SyntaxCollection', - omit_when_empty=True, - element='Syntax', element_name='Attribute', - element_choices=[ - 'Attribute', - 'IfConfigDecl', - ]), - - # The argument of '@_specialize(...)' - # specialize-attr-spec-list -> labeled-specialize-entry - # specialize-spec-attr-list? - # | generic-where-clause - # specialize-spec-attr-list? - Node('SpecializeAttributeSpecList', - name_for_diagnostics="argument to '@_specialize", kind='SyntaxCollection', - description=''' - A collection of arguments for the `@_specialize` attribute - ''', - element='Syntax', element_name='SpecializeAttribute', - element_choices=[ - 'LabeledSpecializeEntry', - 'AvailabilityEntry', - 'TargetFunctionEntry', - 'GenericWhereClause', - ]), - - Node('AvailabilityEntry', name_for_diagnostics='availability entry', kind='Syntax', - description=''' - The availability argument for the _specialize attribute - ''', - children=[ - Child('Label', kind='KeywordToken', token_choices=['KeywordToken|availability'], name_for_diagnostics='label', - description='The label of the argument'), - Child('Colon', kind='ColonToken', - description='The colon separating the label and the value'), - Child('AvailabilityList', kind='AvailabilitySpecList', - collection_element_name='Availability'), - Child('Semicolon', kind='SemicolonToken'), - ]), - - # Representation of e.g. 'exported: true,' - # labeled-specialize-entry -> identifier ':' token ','? - Node('LabeledSpecializeEntry', kind='Syntax', - name_for_diagnostics='attribute argument', - description=''' - A labeled argument for the `@_specialize` attribute like - `exported: true` - ''', - traits=['WithTrailingComma'], - children=[ - Child('Label', kind='Token', name_for_diagnostics='label', - token_choices=['KeywordToken|available', 'KeywordToken|exported', 'KeywordToken|kind', 'KeywordToken|spi', 'KeywordToken|spiModule', 'IdentifierToken'], - description='The label of the argument'), - Child('Colon', kind='ColonToken', - description='The colon separating the label and the value'), - Child('Value', kind='Token', name_for_diagnostics='value', - description='The value for this argument'), - Child('TrailingComma', kind='CommaToken', - is_optional=True, description=''' - A trailing comma if this argument is followed by another one - '''), - ]), - # Representation of e.g. 'exported: true,' - # labeled-specialize-entry -> identifier ':' token ','? - Node('TargetFunctionEntry', kind='Syntax', - name_for_diagnostics='attribute argument', - description=''' - A labeled argument for the `@_specialize` attribute with a function - decl value like - `target: myFunc(_:)` - ''', - traits=['WithTrailingComma'], - children=[ - Child('Label', kind='KeywordToken', token_choices=['KeywordToken|target'], name_for_diagnostics='label', - description='The label of the argument'), - Child('Colon', kind='ColonToken', - description='The colon separating the label and the value'), - Child('Declname', kind='DeclName', name_for_diagnostics='declaration name', - description='The value for this argument'), - Child('TrailingComma', kind='CommaToken', - is_optional=True, description=''' - A trailing comma if this argument is followed by another one - '''), - ]), - - Node('DeclName', name_for_diagnostics='declaration name', kind='Syntax', children=[ - Child('DeclBaseName', kind='Token', name_for_diagnostics='base name', - token_choices=['IdentifierToken', 'PrefixOperatorToken', 'KeywordToken|init'], - description=''' - The base name of the protocol\'s requirement. - '''), - Child('DeclNameArguments', kind='DeclNameArguments', name_for_diagnostics='arguments', - is_optional=True, description=''' - The argument labels of the protocol\'s requirement if it - is a function requirement. - '''), - ]), - # The argument of '@_implements(...)' - # implements-attr-arguments -> simple-type-identifier ',' - # (identifier | operator) decl-name-arguments - Node('ImplementsAttributeArguments', name_for_diagnostics='@_implements arguemnts', - kind='Syntax', - description=''' - The arguments for the `@_implements` attribute of the form - `Type, methodName(arg1Label:arg2Label:)` - ''', - children=[ - Child('Type', kind='Type', name_for_diagnostics='type', description=''' - The type for which the method with this attribute - implements a requirement. - '''), - Child('Comma', kind='CommaToken', - description=''' - The comma separating the type and method name - '''), - Child('DeclBaseName', kind='Token', name_for_diagnostics='declaration base name', description=''' - The base name of the protocol\'s requirement. - '''), - Child('DeclNameArguments', name_for_diagnostics='declaration name arguments', kind='DeclNameArguments', - is_optional=True, description=''' - The argument labels of the protocol\'s requirement if it - is a function requirement. - '''), - ]), - - # objc-selector-piece -> identifier? ':'? - Node('ObjCSelectorPiece', name_for_diagnostics='Objective-C selector piece', - kind='Syntax', - description=''' - A piece of an Objective-C selector. Either consisting of just an - identifier for a nullary selector, an identifier and a colon for a - labeled argument or just a colon for an unlabeled argument - ''', - children=[ - Child('Name', kind='IdentifierToken', name_for_diagnostics='name', is_optional=True), - Child('Colon', kind='ColonToken', is_optional=True), - ]), - - # objc-selector -> objc-selector-piece objc-selector? - Node('ObjCSelector', name_for_diagnostics='Objective-C selector', - kind='SyntaxCollection', element='ObjCSelectorPiece'), - - # The argument of '@differentiable(...)'. - # differentiable-attr-arguments -> - # differentiability-kind? '.'? differentiability-params-clause? ','? - # generic-where-clause? - Node('DifferentiableAttributeArguments', - name_for_diagnostics="'@differentiable' arguments", kind='Syntax', - description=''' - The arguments for the `@differentiable` attribute: an optional - differentiability kind, an optional differentiability parameter clause, - and an optional 'where' clause. - ''', - children=[ - Child('DiffKind', kind='KeywordToken', - token_choices=['KeywordToken|forward', 'KeywordToken|reverse', 'KeywordToken|linear'], - is_optional=True), - Child('DiffKindComma', kind='CommaToken', description=''' - The comma following the differentiability kind, if it exists. - ''', is_optional=True), - Child('DiffParams', kind='DifferentiabilityParamsClause', - is_optional=True), - Child('DiffParamsComma', kind='CommaToken', description=''' - The comma following the differentiability parameters clause, - if it exists. - ''', is_optional=True), - Child('WhereClause', kind='GenericWhereClause', is_optional=True), - ]), - - # differentiability-params-clause -> - # 'wrt' ':' (differentiability-param | differentiability-params) - Node('DifferentiabilityParamsClause', - name_for_diagnostics="'@differentiable' argument", kind='Syntax', - description='A clause containing differentiability parameters.', - children=[ - Child('WrtLabel', kind='KeywordToken', - token_choices=['KeywordToken|wrt'], description='The "wrt" label.'), - Child('Colon', kind='ColonToken', description=''' - The colon separating "wrt" and the parameter list. - '''), - Child('Parameters', kind='Syntax', name_for_diagnostics='parameters', - node_choices=[ - Child('Parameter', kind='DifferentiabilityParam'), - Child('ParameterList', kind='DifferentiabilityParams'), - ]), - ]), - - # differentiability-params -> '(' differentiability-param-list ')' - Node('DifferentiabilityParams', name_for_diagnostics='differentiability parameters', - kind='Syntax', - description='The differentiability parameters.', - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('DiffParams', kind='DifferentiabilityParamList', - collection_element_name='DifferentiabilityParam', - description='The parameters for differentiation.'), - Child('RightParen', kind='RightParenToken'), - ]), - - # differentiability-param-list -> - # differentiability-param differentiability-param-list? - Node('DifferentiabilityParamList', - name_for_diagnostics='differentiability parameters', kind='SyntaxCollection', - element='DifferentiabilityParam'), - - # differentiability-param -> ('self' | identifier | integer-literal) ','? - Node('DifferentiabilityParam', name_for_diagnostics='differentiability parameter', - kind='Syntax', - description=''' - A differentiability parameter: either the "self" identifier, a function - parameter name, or a function parameter index. - ''', - traits=['WithTrailingComma'], - children=[ - Child('Parameter', kind='Token', token_choices=['IdentifierToken', 'IntegerLiteralToken', 'KeywordToken']), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - # The argument of the derivative registration attribute - # '@derivative(of: ...)' and the transpose registration attribute - # '@transpose(of: ...)'. - # - # derivative-registration-attr-arguments -> - # 'of' ':' func-decl-name ','? differentiability-params-clause? - Node('DerivativeRegistrationAttributeArguments', - name_for_diagnostics='attribute arguments', - kind='Syntax', - description=''' - The arguments for the '@derivative(of:)' and '@transpose(of:)' - attributes: the 'of:' label, the original declaration name, and an - optional differentiability parameter list. - ''', - children=[ - Child('OfLabel', kind='KeywordToken', token_choices=['KeywordToken|of'], - description='The "of" label.'), - Child('Colon', kind='ColonToken', description=''' - The colon separating the "of" label and the original - declaration name. - '''), - Child('OriginalDeclName', kind='QualifiedDeclName', - description='The referenced original declaration name.'), - Child('Period', kind='PeriodToken', - description=''' - The period separating the original declaration name and the - accessor name. - ''', is_optional=True), - Child('AccessorKind', kind='KeywordToken', - description='The accessor name.', - token_choices=['KeywordToken|get', 'KeywordToken|set'], - is_optional=True), - Child('Comma', kind='CommaToken', is_optional=True), - Child('DiffParams', kind='DifferentiabilityParamsClause', - is_optional=True), - ]), - - # An optionally qualified declaration name. - # Currently used only for `@derivative` and `@transpose` attribute. - # TODO(TF-1066): Use module qualified name syntax/parsing instead of custom - # qualified name syntax/parsing. - # - # qualified-decl-name -> - # base-type? '.'? (identifier | operator) decl-name-arguments? - # base-type -> - # member-type-identifier | base-type-identifier - Node('QualifiedDeclName', kind='Syntax', - name_for_diagnostics='declaration name', - description=''' - An optionally qualified function declaration name (e.g. `+(_:_:)`, - `A.B.C.foo(_:_:)`). - ''', - children=[ - Child('BaseType', kind='Type', name_for_diagnostics='base type', description=''' - The base type of the qualified name, optionally specified. - ''', is_optional=True), - Child('Dot', kind='PeriodToken', is_optional=True), - Child('Name', kind='Token', name_for_diagnostics='base name', description=''' - The base name of the referenced function. - ''', - token_choices=[ - 'IdentifierToken', - 'BinaryOperatorToken', - 'PrefixOperatorToken', - 'PostfixOperatorToken', - ]), - Child('Arguments', name_for_diagnostics='arguments', kind='DeclNameArguments', - is_optional=True, description=''' - The argument labels of the referenced function, optionally - specified. - '''), - ]), - - # The arguments of '@backDeployed(...)' - # back-deployed-attr-spec-list -> 'before' ':' back-deployed-version-list - Node('BackDeployedAttributeSpecList', kind='Syntax', - name_for_diagnostics="'@backDeployed' arguments", - description=''' - A collection of arguments for the `@backDeployed` attribute - ''', - children=[ - Child('BeforeLabel', kind='KeywordToken', - token_choices=['KeywordToken|before'], description='The "before" label.'), - Child('Colon', kind='ColonToken', description=''' - The colon separating "before" and the parameter list. - '''), - Child('VersionList', kind='AvailabilityVersionRestrictionList', - collection_element_name='Availability', description=''' - The list of OS versions in which the declaration became ABI - stable. - '''), - ]), - - # back-deploy-version-list -> - # back-deploy-version-entry back-deploy-version-list? - Node('AvailabilityVersionRestrictionList', name_for_diagnostics='version list', - kind='SyntaxCollection', element='AvailabilityVersionRestrictionListEntry'), - - # back-deploy-version-entry -> availability-version-restriction ','? - Node('AvailabilityVersionRestrictionListEntry', name_for_diagnostics='version', kind='Syntax', - description=''' - A single platform/version pair in an attribute, e.g. `iOS 10.1`. - ''', - children=[ - Child('AvailabilityVersionRestriction', - kind='AvailabilityVersionRestriction', - classification='Keyword'), - Child('TrailingComma', kind='CommaToken', is_optional=True, - description=''' - A trailing comma if the argument is followed by another - argument - '''), - ]), - # opaque-return-type-of-arguments -> string-literal ',' integer-literal - Node('OpaqueReturnTypeOfAttributeArguments', - name_for_diagnostics='opaque return type arguments', - kind='Syntax', - description=''' - The arguments for the '@_opaqueReturnTypeOf()'. - ''', - children=[ - Child('MangledName', kind='StringLiteralExpr', - description='The mangled name of a declaration.'), - Child('Comma', kind='CommaToken'), - Child('Ordinal', kind='IntegerLiteralToken', - description="The ordinal corresponding to the 'some' keyword that introduced this opaque type."), - ]), - - # convention-attribute-arguments -> token ',' 'cType'? ':' string-literal - Node('ConventionAttributeArguments', - name_for_diagnostics='@convention(...) arguments', - kind='Syntax', - description=''' - The arguments for the '@convention(...)'. - ''', - children=[ - Child('ConventionLabel', kind='IdentifierToken', - description='The convention label.'), - Child('Comma', kind='CommaToken', is_optional=True), - Child('CTypeLabel', kind='KeywordToken', - token_choices=['KeywordToken|cType'], is_optional=True), - Child('Colon', kind='ColonToken', is_optional=True), - Child('CTypeString', kind='StringLiteralExpr', is_optional=True), - ]), - - # convention-attribute-arguments -> 'witness_method' ':' identifier - Node('ConventionWitnessMethodAttributeArguments', - name_for_diagnostics='@convention(...) arguments for witness methods', - kind='Syntax', - description=''' - The arguments for the '@convention(witness_method: ...)'. - ''', - children=[ - Child('WitnessMethodLabel', kind='KeywordToken', token_choices=['KeywordToken|witness_method']), - Child('Colon', kind='ColonToken'), - Child('ProtocolName', kind='IdentifierToken'), - ]), - - Node('ExposeAttributeArguments', name_for_diagnostics='@_expose arguments', - kind='Syntax', - description=''' - The arguments for the '@_expose' attribute - ''', - children=[ - Child('Language', kind='Token'), - Child('Comma', kind='CommaToken', is_optional=True), - Child('CxxName', kind='StringLiteralExpr', is_optional=True) - ]), - - Node('OriginallyDefinedInArguments', name_for_diagnostics='@_originallyDefinedIn arguments', - kind='Syntax', - description=''' - The arguments for the '@_originallyDefinedIn' attribute - ''', - children=[ - Child('ModuleLabel', kind='KeywordToken', token_choices=['KeywordToken|module']), - Child('Colon', kind='ColonToken'), - Child('ModuleName', kind='StringLiteralExpr'), - Child('Comma', kind='CommaToken'), - Child('Platforms', kind='AvailabilityVersionRestrictionList', collection_element_name='Platform') - ]), - - Node('UnderscorePrivateAttributeArguments', name_for_diagnostics='@_private argument', - kind='Syntax', - description=''' - The arguments for the '@_private' attribute - ''', - children=[ - Child('SourceFileLabel', kind='KeywordToken', token_choices=['KeywordToken|sourceFile']), - Child('Colon', kind='ColonToken'), - Child('Filename', kind='StringLiteralExpr'), - ]), - - Node('DynamicReplacementArguments', name_for_diagnostics='@_dynamicReplacement argument', - kind='Syntax', - description=''' - The arguments for the '@_dynamicReplacement' attribute - ''', - children=[ - Child('ForLabel', kind='KeywordToken', token_choices=['KeywordToken|for'], - requires_trailing_space=False), - Child('Colon', kind='ColonToken'), - Child('Declname', kind='DeclName'), - ]), - - Node('UnavailableFromAsyncArguments', name_for_diagnostics='@_unavailableFromAsync argument', - kind='Syntax', - description=''' - The arguments for the '@_unavailableFromAsync' attribute - ''', - children=[ - Child('MessageLabel', kind='KeywordToken', token_choices=['KeywordToken|message']), - Child('Colon', kind='ColonToken'), - Child('Message', kind='StringLiteralExpr'), - ]), - - Node('EffectsArguments', name_for_diagnostics='@_effects arguments', kind='SyntaxCollection', - description=''' - The arguments of the '@_effect' attribute. These will be parsed during the SIL stage. - ''', - element='Token'), - - Node('DocumentationAttributeArgument', name_for_diagnostics='@_documentation argument', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Label', kind='KeywordToken', token_choices=['KeywordToken|visibility', 'KeywordToken|metadata'], name_for_diagnostics='label'), - Child('Colon', kind='ColonToken'), - Child('Value', kind='Syntax', node_choices=[ - Child('Token', kind='Token', token_choices=['IdentifierToken', 'KeywordToken']), # Keywords can be: public, internal, private, fileprivate, open - Child('String', kind='StringLiteralExpr') - ]), - Child('TrailingComma', kind='CommaToken', - is_optional=True, description=''' - A trailing comma if this argument is followed by another one - '''), - ]), - - Node('DocumentationAttributeArguments', name_for_diagnostics='@_documentation arguments', kind='SyntaxCollection', - description=''' - The arguments of the '@_documentation' attribute - ''', - element='DocumentationAttributeArgument'), -] diff --git a/gyb_syntax_support/AvailabilityNodes.py b/gyb_syntax_support/AvailabilityNodes.py deleted file mode 100644 index 2edb7c6e6a9..00000000000 --- a/gyb_syntax_support/AvailabilityNodes.py +++ /dev/null @@ -1,107 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -AVAILABILITY_NODES = [ - # availability-spec-list -> availability-entry availability-spec-list? - Node('AvailabilitySpecList', name_for_diagnostics="'@availability' arguments", - kind='SyntaxCollection', element='AvailabilityArgument'), - - # Wrapper for all the different entries that may occur inside @available - # availability-entry -> '*' ','? - # | identifier ','? - # | availability-version-restriction ','? - # | availability-versioned-argument ','? - Node('AvailabilityArgument', name_for_diagnostics="availability argument", - kind='Syntax', - description=''' - A single argument to an `@available` argument like `*`, `iOS 10.1`, - or `message: "This has been deprecated"`. - ''', - children=[ - Child('Entry', kind='Syntax', - description='The actual argument', - node_choices=[ - Child('Token', kind='Token', - token_choices=['BinaryOperatorToken', 'IdentifierToken'], - requires_leading_space=False, - requires_trailing_space=False), - Child('AvailabilityVersionRestriction', - kind='AvailabilityVersionRestriction'), - Child('AvailabilityLabeledArgument', - kind='AvailabilityLabeledArgument'), - ]), - Child('TrailingComma', kind='CommaToken', is_optional=True, - description=''' - A trailing comma if the argument is followed by another - argument - '''), - ]), - - # Representation of 'deprecated: 2.3', 'message: "Hello world"' etc. - # availability-versioned-argument -> identifier ':' version-tuple - Node('AvailabilityLabeledArgument', name_for_diagnostics="availability argument", - kind='Syntax', - description=''' - A argument to an `@available` attribute that consists of a label and - a value, e.g. `message: "This has been deprecated"`. - ''', - children=[ - Child('Label', kind='KeywordToken', name_for_diagnostics='label', - token_choices=['KeywordToken|message', 'KeywordToken|renamed', 'KeywordToken|introduced', 'KeywordToken|obsoleted', 'KeywordToken|deprecated'], - description='The label of the argument'), - Child('Colon', kind='ColonToken', - description='The colon separating label and value'), - Child('Value', kind='Syntax', name_for_diagnostics='value', - node_choices=[ - Child('String', 'StringLiteralExpr'), - Child('Version', 'VersionTuple'), - ], description='The value of this labeled argument',), - ]), - - # Representation for 'iOS 10', 'swift 3.4' etc. - # availability-version-restriction -> identifier version-tuple - Node('AvailabilityVersionRestriction', name_for_diagnostics="version restriction", - kind='Syntax', - description=''' - 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('Platform', kind='IdentifierToken', name_for_diagnostics='platform', - classification='Keyword', - description=''' - 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('Version', kind='VersionTuple', name_for_diagnostics='version', is_optional=True), - ]), - - # version-tuple -> integer-literal - # | float-literal - # | float-literal '.' integer-literal - Node('VersionTuple', name_for_diagnostics='version tuple', kind='Syntax', - description=''' - A version number of the form major.minor.patch in which the minor - and patch part may be omitted. - ''', - children=[ - Child('MajorMinor', kind='Token', token_choices=['IntegerLiteralToken', 'FloatingLiteralToken'], - description=''' - In case the version consists only of the major version, an - integer literal that specifies the major version. In case - the version consists of major and minor version number, a - floating literal in which the decimal part is interpreted - as the minor version. - '''), - Child('PatchPeriod', kind='PeriodToken', is_optional=True, - description=''' - If the version contains a patch number, the period - separating the minor from the patch number. - '''), - Child('PatchVersion', kind='IntegerLiteralToken', - is_optional=True, description=''' - The patch version if specified. - '''), - ]), -] diff --git a/gyb_syntax_support/Child.py b/gyb_syntax_support/Child.py deleted file mode 100644 index 62d0b15a9eb..00000000000 --- a/gyb_syntax_support/Child.py +++ /dev/null @@ -1,148 +0,0 @@ -# flake8: noqa I201 -from .Classification import classification_by_name -from .Token import SYNTAX_TOKEN_MAP -from .kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word - - -class Child(object): - """ - A child of a node, that may be declared optional or a token with a - restricted subset of acceptable kinds or texts. - """ - def __init__(self, name, kind, name_for_diagnostics=None, description=None, is_optional=False, - token_choices=None, text_choices=None, node_choices=None, - collection_element_name=None, - classification=None, force_classification=False, - is_indented=False, requires_leading_newline=False, - requires_leading_space=None, - requires_trailing_space=None): - """ - If a classification is passed, it specifies the color identifiers in - that subtree should inherit for syntax coloring. Must be a member of - SyntaxClassification in SyntaxClassifier.h.gyb - If force_classification is also set to true, all child nodes (not only - identifiers) inherit the syntax classification. - """ - self.name = name - self.name_for_diagnostics = name_for_diagnostics - self.swift_name = lowercase_first_word(name) - self.syntax_kind = kind - self.description = description - self.swift_syntax_kind = lowercase_first_word(self.syntax_kind) - self.type_name = kind_to_type(self.syntax_kind) - self.collection_element_name = collection_element_name - self.classification = classification_by_name(classification) - self.force_classification = force_classification - self.is_indented = is_indented - self.requires_leading_newline = requires_leading_newline - self.requires_leading_space = requires_leading_space - self.requires_trailing_space = requires_trailing_space - - # If the child ends with "token" in the kind, it's considered - # a token node. Grab the existing reference to that token from the - # global list. - self.token_kind = \ - self.syntax_kind if self.syntax_kind.endswith("Token") else None - self.token = SYNTAX_TOKEN_MAP.get(self.token_kind) - - self.is_optional = is_optional - - # A restricted set of token kinds that will be accepted for this - # child. - self.token_choices = [] - if self.token and not token_choices: - self.token_choices.append((self.token, None)) - for choice in token_choices or []: - pipe_index = choice.find('|') - choice_text = None - if pipe_index != -1: - full_choice = choice - choice = full_choice[:pipe_index] - choice_text = full_choice[(pipe_index+1):] - token = SYNTAX_TOKEN_MAP[choice] - self.token_choices.append((token, choice_text)) - - # A list of valid choices for a child - self.node_choices = node_choices or [] - - # Check the choices are either empty or multiple - assert len(self.node_choices) != 1 - - # Check node choices are well-formed - existing_type_names = set() - for choice in self.node_choices: - assert not choice.is_optional, \ - "node choice %s cannot be optional" % choice.name - assert not choice.node_choices, \ - "node choice %s cannot have further choices" % choice.name - - assert not choice.type_name in existing_type_names, \ - f"{name} cannot have multiple node choices of type {choice.type_name}" - existing_type_names.add(choice.type_name) - - def is_token(self): - """ - Returns true if this child has a token kind. - """ - return self.token_kind is not None - - def has_base_type(self): - """ - Returns `True` if this child's type is one of the base syntax kinds and - it has no node choices. - """ - return not self.node_choices and self.syntax_kind in SYNTAX_BASE_KINDS - - def has_optional_base_type(self): - """ - Returns `True` if this child's type is one of the base syntax kinds and - it's optional. - """ - return self.has_base_type() and self.is_optional - - def main_token(self): - """ - Returns the first choice from the token_choices if there are any, - otherwise returns None. - """ - if self.token_choices: - return self.token_choices[0][0] - return None - - def is_unexpected_nodes(self): - return self.syntax_kind == 'UnexpectedNodes' - - def generate_default_initialization(self): - """ - If the type has a default value, return an expression of the form - ` = default_value` that can be used as the default value to for a - function parameter. Otherwise, return an empty string. - """ - - # Note that this should be Optional.none for defaulted generic, - # but that doesn't work in Swift 5.6. To keep source compatibility with - # previous SwiftSyntax, we instead create a second initializer that uses - # `Missing` and defaults that to `nil` instead (and `Missing` is - # used so that they can't be implicitly converted from a literal). - if self.is_optional or self.is_unexpected_nodes(): - return " = nil" - - if not self.is_token() or not self.token: - return "" - - if self.token.is_keyword: - return f" = .{self.token.swift_kind()}()" - if self.token.text: - return f" = .{self.token.swift_kind()}Token()" - text_choice = None - if self.token_choices and len(self.token_choices) == 1 and self.token_choices[0][1] is not None: - text_choice = self.token_choices[0][1] - if text_choice: - if self.token.associated_value_class: - if text_choice == "init": - text_choice = "`init`" - return f" = .{self.token.swift_kind()}(.{text_choice})" - else: - return f" = .{self.token.swift_kind()}(\"{text_choice}\")" - - return "" diff --git a/gyb_syntax_support/Classification.py b/gyb_syntax_support/Classification.py deleted file mode 100644 index 565ff946c55..00000000000 --- a/gyb_syntax_support/Classification.py +++ /dev/null @@ -1,83 +0,0 @@ -from .Utils import error -from .kinds import lowercase_first_word # noqa: I201 - - -class SyntaxClassification(object): - ''' - Represents a classification a token can receive for syntax highlighting. - ''' - - def __init__(self, name, description): - self.name = name - self.swift_name = lowercase_first_word(name) - self.description = description - - -SYNTAX_CLASSIFICATIONS = [ - SyntaxClassification('None', description=''' - The token should not receive syntax coloring. - '''), - SyntaxClassification('Keyword', description=''' - A Swift keyword, including contextual keywords. - '''), - SyntaxClassification('Identifier', description=''' - A generic identifier. - '''), - SyntaxClassification('TypeIdentifier', description=''' - An identifier referring to a type. - '''), - SyntaxClassification('OperatorIdentifier', description=''' - An identifier referring to an operator. - '''), - SyntaxClassification('DollarIdentifier', description=''' - An identifier starting with `$` like `$0`. - '''), - SyntaxClassification('IntegerLiteral', description=''' - An integer literal. - '''), - SyntaxClassification('FloatingLiteral', description=''' - A floating point literal. - '''), - SyntaxClassification('StringLiteral', description=''' - A string literal including multiline string literals. - '''), - SyntaxClassification('StringInterpolationAnchor', description=''' - The opening and closing parenthesis of string interpolation. - '''), - SyntaxClassification('PoundDirectiveKeyword', description=''' - A `#` keyword like `#warning`. - '''), - SyntaxClassification('BuildConfigId', description=''' - A build configuration directive like `#if`, `#elseif`, `#else`. - '''), - SyntaxClassification('Attribute', description=''' - An attribute starting with an `@`. - '''), - SyntaxClassification('ObjectLiteral', description=''' - An image, color, etc. literal. - '''), - SyntaxClassification('EditorPlaceholder', description=''' - An editor placeholder of the form `<#content#>` - '''), - SyntaxClassification('LineComment', description=''' - A line comment starting with `//`. - '''), - SyntaxClassification('DocLineComment', description=''' - A doc line comment starting with `///`. - '''), - SyntaxClassification('BlockComment', description=''' - A block comment starting with `/**` and ending with `*/. - '''), - SyntaxClassification('DocBlockComment', description=''' - A doc block comment starting with `/**` and ending with `*/. - '''), -] - - -def classification_by_name(classification_name): - if classification_name is None: - return None - for classification in SYNTAX_CLASSIFICATIONS: - if classification.name == classification_name: - return classification - error("Unknown syntax classification '%s'" % classification_name) diff --git a/gyb_syntax_support/CommonNodes.py b/gyb_syntax_support/CommonNodes.py deleted file mode 100644 index 0fab9d44e98..00000000000 --- a/gyb_syntax_support/CommonNodes.py +++ /dev/null @@ -1,94 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -COMMON_NODES = [ - Node('Decl', name_for_diagnostics='declaration', kind='Syntax', - parser_function='parseDeclaration'), - Node('Expr', name_for_diagnostics='expression', kind='Syntax', - parser_function='parseExpression'), - Node('Stmt', name_for_diagnostics='statement', kind='Syntax', - parser_function='parseStatement'), - Node('Type', name_for_diagnostics='type', kind='Syntax', - parser_function='parseType'), - Node('Pattern', name_for_diagnostics='pattern', kind='Syntax', - parser_function='parsePattern'), - Node('Missing', name_for_diagnostics=None, kind='Syntax'), - Node('MissingDecl', name_for_diagnostics='declaration', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', - collection_element_name='Modifier', is_optional=True), - ]), - Node('MissingExpr', name_for_diagnostics='expression', kind='Expr'), - Node('MissingStmt', name_for_diagnostics='statement', kind='Stmt'), - Node('MissingType', name_for_diagnostics='type', kind='Type'), - Node('MissingPattern', name_for_diagnostics='pattern', kind='Pattern'), - - # code-block-item = (decl | stmt | expr) ';'? - Node('CodeBlockItem', name_for_diagnostics=None, kind='Syntax', - omit_when_empty=True, - description=""" - A CodeBlockItem is any Syntax node that appears on its own line inside - a CodeBlock. - """, - children=[ - Child('Item', kind='Syntax', - description="The underlying node inside the code block.", - node_choices=[ - Child('Decl', kind='Decl'), - Child('Stmt', kind='Stmt'), - Child('Expr', kind='Expr'), - ]), - Child('Semicolon', kind='SemicolonToken', - description=""" - If present, the trailing semicolon at the end of the item. - """, - is_optional=True), - ]), - - # code-block-item-list -> code-block-item code-block-item-list? - Node('CodeBlockItemList', name_for_diagnostics=None, - kind='SyntaxCollection', element='CodeBlockItem', - elements_separated_by_newline=True), - - # code-block -> '{' stmt-list '}' - Node('CodeBlock', name_for_diagnostics='code block', kind='Syntax', - traits=['Braced', 'WithStatements'], - children=[ - Child('LeftBrace', kind='LeftBraceToken'), - Child('Statements', kind='CodeBlockItemList', name_for_diagnostics='statements', - collection_element_name='Statement', is_indented=True), - Child('RightBrace', kind='RightBraceToken', - requires_leading_newline=True), - ]), - - # decl-effect-specifiers -> (async | reasync)? (throws | rethrows)? - Node('DeclEffectSpecifiers', name_for_diagnostics='effect specifiers', kind='Syntax', - traits=['EffectSpecifiers'], - children=[ - Child('AsyncSpecifier', kind='KeywordToken', - token_choices=['KeywordToken|async', 'KeywordToken|reasync'], is_optional=True), - Child('ThrowsSpecifier', kind='KeywordToken', - is_optional=True, - token_choices=['KeywordToken|throws', 'KeywordToken|rethrows']), - ]), - - # type-effect-specifiers -> async? throws? - Node('TypeEffectSpecifiers', name_for_diagnostics='effect specifiers', kind='Syntax', - traits=['EffectSpecifiers'], - children=[ - Child('AsyncSpecifier', kind='KeywordToken', - token_choices=['KeywordToken|async'], is_optional=True), - Child('ThrowsSpecifier', kind='KeywordToken', token_choices=['KeywordToken|throws'], - is_optional=True), - ]), - - Node('UnexpectedNodes', name_for_diagnostics=None, kind='SyntaxCollection', - element='Syntax', - description=''' - A collection of syntax nodes that occurred in the source code but - could not be used to form a valid syntax tree. - '''), -] diff --git a/gyb_syntax_support/DeclNodes.py b/gyb_syntax_support/DeclNodes.py deleted file mode 100644 index a8179f39ff2..00000000000 --- a/gyb_syntax_support/DeclNodes.py +++ /dev/null @@ -1,931 +0,0 @@ -# flake8: noqa I201 -from .Child import Child -from .Node import Node - - -DECL_NODES = [ - # type-assignment -> '=' type - Node('TypeInitializerClause', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Equal', kind='EqualToken'), - Child('Value', kind='Type', name_for_diagnostics='type'), - ]), - - # typealias-declaration -> attributes? access-level-modifier? 'typealias' - # typealias-name generic-parameter-clause? - # type-assignment - # typealias-name -> identifier - Node('TypealiasDecl', name_for_diagnostics='typealias declaration', kind='Decl', - traits=['IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('TypealiasKeyword', kind='KeywordToken', token_choices=['KeywordToken|typealias']), - Child('Identifier', kind='IdentifierToken'), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('Initializer', kind='TypeInitializerClause'), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - ]), - - # associatedtype-declaration -> attributes? access-level-modifier? - # 'associatedtype' associatedtype-name - # inheritance-clause? type-assignment? - # generic-where-clause? - # associatedtype-name -> identifier - Node('AssociatedtypeDecl', name_for_diagnostics='associatedtype declaration', - kind='Decl', traits=['IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('AssociatedtypeKeyword', kind='KeywordToken', token_choices=['KeywordToken|associatedtype']), - Child('Identifier', kind='IdentifierToken'), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='inheritance clause', - is_optional=True), - Child('Initializer', kind='TypeInitializerClause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - ]), - - Node('FunctionParameterList', name_for_diagnostics='parameter list', - kind='SyntaxCollection', element='FunctionParameter'), - - Node('ParameterClause', name_for_diagnostics='parameter clause', kind='Syntax', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('ParameterList', kind='FunctionParameterList', name_for_diagnostics='parameters', - collection_element_name='Parameter', is_indented=True), - Child('RightParen', kind='RightParenToken'), - ]), - - # return-clause -> - # '->' type - Node('ReturnClause', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Arrow', kind='ArrowToken'), - Child('ReturnType', kind='Type', name_for_diagnostics='return type'), - ]), - - # function-signature -> - # '(' parameter-list? ')' decl-effect-specifiers? return-clause? - Node('FunctionSignature', name_for_diagnostics='function signature', kind='Syntax', - children=[ - Child('Input', kind='ParameterClause'), - Child('EffectSpecifiers', kind='DeclEffectSpecifiers', - is_optional=True), - Child('Output', kind='ReturnClause', is_optional=True), - ]), - - # if-config-clause -> - # ('#if' | '#elseif' | '#else') expr? (stmt-list | switch-case-list) - Node('IfConfigClause', name_for_diagnostics="conditional compilation clause", - kind='Syntax', - children=[ - Child('PoundKeyword', kind='Token', - classification='BuildConfigId', - token_choices=[ - 'PoundIfToken', - 'PoundElseifToken', - 'PoundElseToken', - ], requires_leading_newline=True), - Child('Condition', kind='Expr', name_for_diagnostics='condition', classification='BuildConfigId', - is_optional=True), - Child('Elements', is_optional=True, kind='Syntax', - node_choices=[ - Child('Statements', kind='CodeBlockItemList'), - Child('SwitchCases', kind='SwitchCaseList'), - Child('Decls', kind='MemberDeclList'), - Child('PostfixExpression', kind='Expr'), - Child('Attributes', kind='AttributeList'), - ]), - ]), - - Node('IfConfigClauseList', name_for_diagnostics=None, kind='SyntaxCollection', - element='IfConfigClause'), - - # if-config-decl -> '#if' expr stmt-list else-if-directive-clause-list - # else-clause? '#endif' - Node('IfConfigDecl', name_for_diagnostics='conditional compilation block', - kind='Decl', - children=[ - Child('Clauses', kind='IfConfigClauseList', - collection_element_name='Clause'), - Child('PoundEndif', kind='PoundEndifToken', - classification='BuildConfigId', requires_leading_newline=True), - ]), - - Node('PoundSourceLocation', name_for_diagnostics="'#sourceLocation' directive", - kind='Decl', traits=['Parenthesized'], - children=[ - Child('PoundSourceLocation', kind='PoundSourceLocationToken'), - Child('LeftParen', kind='LeftParenToken'), - Child('Args', kind='PoundSourceLocationArgs', name_for_diagnostics='arguments', is_optional=True), - Child('RightParen', kind='RightParenToken') - ]), - - Node('PoundSourceLocationArgs', name_for_diagnostics="'#sourceLocation' arguments", - kind='Syntax', - children=[ - Child('FileArgLabel', kind='KeywordToken', - token_choices=['KeywordToken|file']), - Child('FileArgColon', kind='ColonToken'), - Child('FileName', kind='StringLiteralExpr', name_for_diagnostics='file name'), - Child('Comma', kind='CommaToken'), - Child('LineArgLabel', kind='KeywordToken', - token_choices=['KeywordToken|line']), - Child('LineArgColon', kind='ColonToken'), - Child('LineNumber', name_for_diagnostics='line number', kind='IntegerLiteralToken'), - ]), - - Node('DeclModifierDetail', name_for_diagnostics=None, kind='Syntax', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Detail', kind='Token', token_choices=['IdentifierToken', 'KeywordToken|set']), - Child('RightParen', kind='RightParenToken'), - ]), - - Node('DeclModifier', name_for_diagnostics='modifier', kind='Syntax', - children=[ - Child('Name', kind='KeywordToken', classification='Attribute', - token_choices=[ - 'KeywordToken|class', 'KeywordToken|convenience', 'KeywordToken|dynamic', 'KeywordToken|final', 'KeywordToken|infix', - 'KeywordToken|lazy', 'KeywordToken|optional', 'KeywordToken|override', 'KeywordToken|postfix', 'KeywordToken|prefix', - 'KeywordToken|required', 'KeywordToken|static', 'KeywordToken|unowned', 'KeywordToken|weak', 'KeywordToken|private', - 'KeywordToken|fileprivate', 'KeywordToken|internal', 'KeywordToken|public', 'KeywordToken|open', - 'KeywordToken|mutating', 'KeywordToken|nonmutating', 'KeywordToken|indirect', 'KeywordToken|__consuming', - 'KeywordToken|borrowing', 'KeywordToken|consuming', - 'KeywordToken|actor', 'KeywordToken|async', 'KeywordToken|distributed', 'KeywordToken|isolated', - 'KeywordToken|nonisolated', 'KeywordToken|_const', 'KeywordToken|_local', 'KeywordToken|package' - ]), - Child('Detail', kind='DeclModifierDetail', is_optional=True), - ]), - - Node('InheritedType', name_for_diagnostics='inherited type', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('TypeName', kind='Type'), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - Node('InheritedTypeList', name_for_diagnostics=None, kind='SyntaxCollection', - element='InheritedType'), - - # type-inheritance-clause -> ':' type - Node('TypeInheritanceClause', name_for_diagnostics='inheritance clause', - kind='Syntax', - children=[ - Child('Colon', kind='ColonToken'), - Child('InheritedTypeCollection', kind='InheritedTypeList', - collection_element_name='InheritedType'), - ]), - - # class-declaration -> attributes? access-level-modifier? - # 'class' class-name - # generic-parameter-clause? - # type-inheritance-clause? - # generic-where-clause? - # '{' class-members '}' - # class-name -> identifier - Node('ClassDecl', name_for_diagnostics='class', kind='Decl', - traits=['DeclGroup', 'IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('ClassKeyword', kind='KeywordToken', token_choices=['KeywordToken|class']), - Child('Identifier', kind='IdentifierToken'), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='inheritance clause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - - # actor-declaration -> attributes? access-level-modifier? - # 'actor' actor-name - # generic-parameter-clause? - # type-inheritance-clause? - # generic-where-clause? - # '{' actor-members '}' - # actor-name -> identifier - Node('ActorDecl', name_for_diagnostics='actor', kind='Decl', - traits=['DeclGroup', 'IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('ActorKeyword', kind='KeywordToken', - token_choices=['KeywordToken|actor']), - Child('Identifier', kind='IdentifierToken'), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='type inheritance clause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - # struct-declaration -> attributes? access-level-modifier? - # 'struct' struct-name - # generic-parameter-clause? - # type-inheritance-clause? - # generic-where-clause? - # '{' struct-members '}' - # struct-name -> identifier - Node('StructDecl', name_for_diagnostics='struct', kind='Decl', - traits=['DeclGroup', 'IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('StructKeyword', kind='KeywordToken', token_choices=['KeywordToken|struct']), - Child('Identifier', kind='IdentifierToken'), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='type inheritance clause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - - Node('ProtocolDecl', name_for_diagnostics='protocol', kind='Decl', - traits=['DeclGroup', 'IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('ProtocolKeyword', kind='KeywordToken', token_choices=['KeywordToken|protocol']), - Child('Identifier', kind='IdentifierToken'), - Child('PrimaryAssociatedTypeClause', - kind='PrimaryAssociatedTypeClause', - name_for_diagnostics='primary associated type clause', - is_optional=True), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='inheritance clause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - - # extension-declaration -> attributes? access-level-modifier? - # 'extension' extended-type - # type-inheritance-clause? - # generic-where-clause? - # '{' extension-members '}' - # extension-name -> identifier - Node('ExtensionDecl', name_for_diagnostics='extension', kind='Decl', - traits=['DeclGroup', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('ExtensionKeyword', kind='KeywordToken', token_choices=['KeywordToken|extension']), - Child('ExtendedType', kind='Type'), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='inheritance clause', - is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - - Node('MemberDeclBlock', name_for_diagnostics='member block', kind='Syntax', - traits=['Braced'], - parser_function='parseMemberDeclList', - children=[ - Child('LeftBrace', kind='LeftBraceToken'), - Child('Members', kind='MemberDeclList', - collection_element_name='Member', is_indented=True), - Child('RightBrace', kind='RightBraceToken', - requires_leading_newline=True), - ]), - - # member-decl-list = member-decl member-decl-list? - Node('MemberDeclList', name_for_diagnostics=None, kind='SyntaxCollection', - element='MemberDeclListItem', elements_separated_by_newline=True), - - # member-decl = decl ';'? - Node('MemberDeclListItem', name_for_diagnostics=None, kind='Syntax', - omit_when_empty=True, - description=''' - A member declaration of a type consisting of a declaration and an - optional semicolon; - ''', - children=[ - Child('Decl', kind='Decl', - description='The declaration of the type member.'), - Child('Semicolon', kind='SemicolonToken', is_optional=True, - description='An optional trailing semicolon.'), - ]), - - # source-file = code-block-item-list eof - Node('SourceFile', name_for_diagnostics='source file', kind='Syntax', - traits=['WithStatements'], - parser_function='parseSourceFile', - children=[ - Child('Statements', kind='CodeBlockItemList', - collection_element_name='Statement'), - Child('EOFToken', kind='EOFToken') - ]), - - # initializer -> '=' expr - Node('InitializerClause', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Equal', kind='EqualToken'), - Child('Value', kind='Expr'), - ]), - - # parameter -> - # external-parameter-name? local-parameter-name ':' - # type '...'? '='? expression? ','? - Node('FunctionParameter', name_for_diagnostics='parameter', kind='Syntax', - traits=['WithTrailingComma', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('FirstName', kind='Token', - token_choices=[ - 'IdentifierToken', - 'WildcardToken', - ], - is_optional=True), - # One of these two names needs be optional, we choose the second - # name to avoid backtracking. - Child('SecondName', kind='Token', name_for_diagnostics='internal name', - token_choices=[ - 'IdentifierToken', - 'WildcardToken', - ], - is_optional=True), - Child('Colon', kind='ColonToken', - is_optional=True), - Child('Type', kind='Type', name_for_diagnostics='type', - is_optional=True), - Child('Ellipsis', kind='EllipsisToken', - is_optional=True), - Child('DefaultArgument', kind='InitializerClause', name_for_diagnostics='default argument', - is_optional=True), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # declaration-modifier -> access-level-modifier - # | mutation-modifier - # | 'class' - # | 'convenience' - # | 'distributed' - # | 'dynamic' - # | 'final' - # | 'infix' - # | 'isolated' - # | 'lazy' - # | 'nonisolated' - # | 'optional' - # | 'override' - # | 'postfix' - # | 'prefix' - # | 'required' - # | 'static' - # | 'unowned' - # | 'unowned(safe)' - # | 'unowned(unsafe)' - # | 'weak' - # mutation-modifier -> 'mutating' | 'nonmutating' - Node('ModifierList', name_for_diagnostics=None, kind='SyntaxCollection', - omit_when_empty=True, - element='DeclModifier', - element_name='Modifier'), - - Node('FunctionDecl', name_for_diagnostics='function', kind='Decl', - traits=['IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('FuncKeyword', kind='KeywordToken', token_choices=['KeywordToken|func']), - Child('Identifier', kind='Token', - token_choices=[ - 'IdentifierToken', - 'BinaryOperatorToken', - 'PrefixOperatorToken', - 'PostfixOperatorToken', - ]), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('Signature', kind='FunctionSignature', name_for_diagnostics='function signature'), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - # the body is not necessary inside a protocol definition - Child('Body', kind='CodeBlock', is_optional=True), - ]), - - Node('InitializerDecl', name_for_diagnostics='initializer', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('InitKeyword', kind='KeywordToken', token_choices=['KeywordToken|init']), - Child('OptionalMark', kind='Token', - token_choices=[ - 'PostfixQuestionMarkToken', - 'InfixQuestionMarkToken', - 'ExclamationMarkToken', - ], - is_optional=True), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('Signature', kind='FunctionSignature', name_for_diagnostics='function signature',), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - # the body is not necessary inside a protocol definition - Child('Body', kind='CodeBlock', is_optional=True), - ]), - - Node('DeinitializerDecl', name_for_diagnostics='deinitializer', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('DeinitKeyword', kind='KeywordToken', token_choices=['KeywordToken|deinit']), - Child('Body', kind='CodeBlock', is_optional=True), - ]), - - Node('SubscriptDecl', name_for_diagnostics='subscript', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('SubscriptKeyword', kind='KeywordToken', token_choices=['KeywordToken|subscript']), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('Indices', kind='ParameterClause'), - Child('Result', kind='ReturnClause'), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - # the body is not necessary inside a protocol definition - Child('Accessor', kind='Syntax', is_optional=True, - node_choices=[ - Child('Accessors', kind='AccessorBlock'), - Child('Getter', kind='CodeBlock')]), - ]), - - # FIXME: technically misnamed; should be "ImportPathComponent" - Node('AccessPathComponent', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Name', kind='IdentifierToken', name_for_diagnostics='name',), - Child('TrailingDot', kind='PeriodToken', is_optional=True), - ]), - - # FIXME: technically misnamed; should be "ImportPath" - Node('AccessPath', name_for_diagnostics=None, kind='SyntaxCollection', - element='AccessPathComponent'), - - Node('ImportDecl', name_for_diagnostics='import', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('ImportTok', kind='KeywordToken', token_choices=['KeywordToken|import']), - Child('ImportKind', kind='KeywordToken', is_optional=True, - token_choices=[ - 'KeywordToken|typealias', 'KeywordToken|struct', 'KeywordToken|class', 'KeywordToken|enum', 'KeywordToken|protocol', 'KeywordToken|var', - 'KeywordToken|let', 'KeywordToken|func', 'KeywordToken|inout' - ]), - Child('Path', kind='AccessPath', - collection_element_name='PathComponent'), - ]), - - # (value) - Node('AccessorParameter', name_for_diagnostics=None, kind='Syntax', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Name', kind='IdentifierToken', name_for_diagnostics='name'), - Child('RightParen', kind='RightParenToken'), - ]), - - Node('AccessorDecl', name_for_diagnostics='accessor', kind='Decl', - traits=['Attributed'], - parser_function='parseAccessorDecl', - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifier', kind='DeclModifier', name_for_diagnostics='modifiers', is_optional=True), - Child('AccessorKind', kind='KeywordToken', - token_choices=[ - 'KeywordToken|get', 'KeywordToken|set', 'KeywordToken|didSet', 'KeywordToken|willSet', 'KeywordToken|unsafeAddress', - 'KeywordToken|addressWithOwner', 'KeywordToken|addressWithNativeOwner', - 'KeywordToken|unsafeMutableAddress', - 'KeywordToken|mutableAddressWithOwner', - 'KeywordToken|mutableAddressWithNativeOwner', - 'KeywordToken|_read', 'KeywordToken|_modify' - ]), - Child('Parameter', name_for_diagnostics='parameter', kind='AccessorParameter', is_optional=True), - Child('EffectSpecifiers', kind='DeclEffectSpecifiers', is_optional=True), - Child('Body', kind='CodeBlock', is_optional=True), - ]), - - Node('AccessorList', name_for_diagnostics=None, kind="SyntaxCollection", - element='AccessorDecl', elements_separated_by_newline=True), - - Node('AccessorBlock', name_for_diagnostics=None, kind="Syntax", traits=['Braced'], - children=[ - Child('LeftBrace', kind='LeftBraceToken'), - Child('Accessors', kind='AccessorList', - collection_element_name='Accessor', is_indented=True), - Child('RightBrace', kind='RightBraceToken', requires_leading_newline=True), - ]), - - # Pattern: Type = Value { get {} }, - Node('PatternBinding', name_for_diagnostics=None, kind="Syntax", - traits=['WithTrailingComma'], - children=[ - Child('Pattern', kind='Pattern'), - Child('TypeAnnotation', kind='TypeAnnotation', name_for_diagnostics='type annotation', is_optional=True), - Child('Initializer', kind='InitializerClause', is_optional=True), - Child('Accessor', kind='Syntax', is_optional=True, - node_choices=[ - Child('Accessors', kind='AccessorBlock'), - Child('Getter', kind='CodeBlock')]), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - Node('PatternBindingList', name_for_diagnostics=None, kind="SyntaxCollection", - element='PatternBinding'), - - Node('VariableDecl', name_for_diagnostics='variable', kind='Decl', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('BindingKeyword', kind='KeywordToken', - token_choices=[ - 'KeywordToken|let', 'KeywordToken|var', - 'KeywordToken|inout' - ]), - Child('Bindings', kind='PatternBindingList', - collection_element_name='Binding'), - ]), - - Node('EnumCaseElement', name_for_diagnostics=None, kind='Syntax', - description=''' - An element of an enum case, containing the name of the case and, - optionally, either associated values or an assignment to a raw value. - ''', - traits=['WithTrailingComma'], - children=[ - Child('Identifier', kind='IdentifierToken', - description='The name of this case.'), - Child('AssociatedValue', kind='ParameterClause', name_for_diagnostics='associated values', is_optional=True, - description='The set of associated values of the case.'), - Child('RawValue', kind='InitializerClause', is_optional=True, - description=''' - The raw value of this enum element, if present. - '''), - Child('TrailingComma', kind='CommaToken', is_optional=True, - description=''' - The trailing comma of this element, if the case has - multiple elements. - '''), - ]), - - Node('EnumCaseElementList', name_for_diagnostics=None, kind='SyntaxCollection', - description='A collection of 0 or more `EnumCaseElement`s.', - element='EnumCaseElement'), - - Node('EnumCaseDecl', name_for_diagnostics='enum case', kind='Decl', - description=''' - A `case` declaration of a Swift `enum`. It can have 1 or more - `EnumCaseElement`s inside, each declaring a different case of the - enum. - ''', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True, - description=''' - The attributes applied to the case declaration. - '''), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True, - description=''' - The declaration modifiers applied to the case declaration. - '''), - Child('CaseKeyword', kind='KeywordToken', token_choices=['KeywordToken|case'], - description='The `case` keyword for this case.'), - Child('Elements', kind='EnumCaseElementList', - collection_element_name='Element', name_for_diagnostics='elements', - description='The elements this case declares.') - ]), - - Node('EnumDecl', name_for_diagnostics='enum', kind='Decl', - traits=['DeclGroup', 'IdentifiedDecl', 'Attributed'], - description='A Swift `enum` declaration.', - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True, - description=''' - The attributes applied to the enum declaration. - '''), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True, - description=''' - The declaration modifiers applied to the enum declaration. - '''), - Child('EnumKeyword', kind='KeywordToken', token_choices=['KeywordToken|enum'], - description=''' - The `enum` keyword for this declaration. - '''), - Child('Identifier', kind='IdentifierToken', - description=''' - The name of this enum. - '''), - Child('GenericParameters', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True, - description=''' - The generic parameters, if any, for this enum. - '''), - Child('InheritanceClause', kind='TypeInheritanceClause', name_for_diagnostics='inheritance clause', - is_optional=True, - description=''' - The inheritance clause describing conformances or raw - values for this enum. - '''), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True, - description=''' - The `where` clause that applies to the generic parameters of - this enum. - '''), - Child('Members', kind='MemberDeclBlock', - description=''' - The cases and other members of this enum. - ''') - ]), - - # operator-decl -> attribute? modifiers? 'operator' operator - Node('OperatorDecl', name_for_diagnostics='operator declaration', kind='Decl', - traits=['IdentifiedDecl', 'Attributed'], - description='A Swift `operator` declaration.', - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True, - description=''' - The attributes applied to the 'operator' declaration. - '''), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True, - classification='Attribute', - description=''' - The declaration modifiers applied to the 'operator' - declaration. - '''), - Child('OperatorKeyword', kind='KeywordToken', token_choices=['KeywordToken|operator']), - Child('Identifier', kind='Token', - classification='OperatorIdentifier', - token_choices=[ - 'BinaryOperatorToken', - 'PrefixOperatorToken', - 'PostfixOperatorToken', - ]), - Child('OperatorPrecedenceAndTypes', kind='OperatorPrecedenceAndTypes', - description=''' - Optionally specify a precedence group and designated types. - ''', - is_optional=True), - ]), - - # designated-type-list -> (',' identifier)* - Node('DesignatedTypeList', name_for_diagnostics=None, kind='SyntaxCollection', - element='DesignatedTypeElement'), - Node('DesignatedTypeElement', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('LeadingComma', kind='CommaToken'), - Child('Name', kind='Token'), - ]), - - # infix-operator-group -> ':' identifier designated-type-list? - Node('OperatorPrecedenceAndTypes', name_for_diagnostics=None, kind='Syntax', - description=''' - A clause to specify precedence group in infix operator declarations, and designated types in any operator declaration. - ''', - children=[ - Child('Colon', kind='ColonToken'), - Child('PrecedenceGroup', name_for_diagnostics='precedence group', kind='IdentifierToken', - description=''' - The precedence group for this operator - '''), - Child('DesignatedTypes', kind='DesignatedTypeList', - collection_element_name='DesignatedTypeElement', - description=''' - The designated types associated with this operator. - '''), - ]), - - # precedence-group-decl -> attributes? modifiers? 'precedencegroup' - # identifier '{' precedence-group-attribute-list - # '}' - Node('PrecedenceGroupDecl', name_for_diagnostics='precedencegroup', kind='Decl', - traits=['IdentifiedDecl', 'Attributed'], - description='A Swift `precedencegroup` declaration.', - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True, - description=''' - The attributes applied to the 'precedencegroup' declaration. - '''), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True, - description=''' - The declaration modifiers applied to the 'precedencegroup' - declaration. - '''), - Child('PrecedencegroupKeyword', kind='KeywordToken', token_choices=['KeywordToken|precedencegroup']), - Child('Identifier', kind='IdentifierToken', - description=''' - The name of this precedence group. - '''), - Child('LeftBrace', kind='LeftBraceToken'), - Child('GroupAttributes', kind='PrecedenceGroupAttributeList', - collection_element_name='GroupAttribute', - description=''' - The characteristics of this precedence group. - '''), - Child('RightBrace', kind='RightBraceToken'), - ]), - - # precedence-group-attribute-list -> - # (precedence-group-relation | precedence-group-assignment | - # precedence-group-associativity )* - Node('PrecedenceGroupAttributeList', name_for_diagnostics=None, - kind='SyntaxCollection', element='Syntax', - element_name='PrecedenceGroupAttribute', - element_choices=[ - 'PrecedenceGroupRelation', - 'PrecedenceGroupAssignment', - 'PrecedenceGroupAssociativity' - ]), - - # precedence-group-relation -> - # ('higherThan' | 'lowerThan') ':' precedence-group-name-list - Node('PrecedenceGroupRelation', - name_for_diagnostics="'relation' property of precedencegroup", kind='Syntax', - description=''' - Specify the new precedence group's relation to existing precedence - groups. - ''', - children=[ - Child('HigherThanOrLowerThan', kind='KeywordToken', - classification='Keyword', - token_choices=[ - 'KeywordToken|higherThan', 'KeywordToken|lowerThan', - ], - description=''' - The relation to specified other precedence groups. - '''), - Child('Colon', kind='ColonToken'), - Child('OtherNames', kind='PrecedenceGroupNameList', - collection_element_name='OtherName', - description=''' - The name of other precedence group to which this precedence - group relates. - '''), - ]), - - # precedence-group-name-list -> - # identifier (',' identifier)* - Node('PrecedenceGroupNameList', name_for_diagnostics=None, kind='SyntaxCollection', - element='PrecedenceGroupNameElement'), - Node('PrecedenceGroupNameElement', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Name', kind='IdentifierToken', name_for_diagnostics='name'), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # precedence-group-assignment -> - # 'assignment' ':' ('true' | 'false') - Node('PrecedenceGroupAssignment', - name_for_diagnostics="'assignment' property of precedencegroup", kind='Syntax', - description=''' - Specifies the precedence of an operator when used in an operation - that includes optional chaining. - ''', - children=[ - Child('AssignmentKeyword', kind='KeywordToken', - token_choices=['KeywordToken|assignment']), - Child('Colon', kind='ColonToken'), - Child('Flag', kind='KeywordToken', token_choices=['KeywordToken|true', 'KeywordToken|false'], - description=''' - When true, an operator in the corresponding precedence group - uses the same grouping rules during optional chaining as the - assignment operators from the standard library. Otherwise, - operators in the precedence group follows the same optional - chaining rules as operators that don't perform assignment. - '''), - ]), - - # precedence-group-associativity -> - # 'associativity' ':' ('left' | 'right' | 'none') - Node('PrecedenceGroupAssociativity', - name_for_diagnostics="'associativity' property of precedencegroup", - kind='Syntax', - description=''' - Specifies how a sequence of operators with the same precedence level - are grouped together in the absence of grouping parentheses. - ''', - children=[ - Child('AssociativityKeyword', kind='KeywordToken', - classification='Keyword', token_choices=['KeywordToken|associativity']), - Child('Colon', kind='ColonToken'), - Child('Value', kind='IdentifierToken', - token_choices=['KeywordToken|left', 'KeywordToken|right', 'KeywordToken|none'], - description=''' - Operators that are `left`-associative group left-to-right. - Operators that are `right`-associative group right-to-left. - Operators that are specified with an associativity of `none` - don't associate at all - '''), - ]), - - Node('MacroDecl', name_for_diagnostics='macro', kind='Decl', - traits=['IdentifiedDecl', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Modifiers', kind='ModifierList', name_for_diagnostics='modifiers', - collection_element_name='Modifier', is_optional=True), - Child('MacroKeyword', kind='KeywordToken', - token_choices=['KeywordToken|macro']), - Child('Identifier', kind='IdentifierToken'), - Child('GenericParameterClause', kind='GenericParameterClause', name_for_diagnostics='generic parameter clause', - is_optional=True), - Child('Signature', kind='Syntax', name_for_diagnostics='macro signature', - node_choices=[ - Child('FunctionLike', kind='FunctionSignature', name_for_diagnostics="macro signature"), - Child('ValueLike', kind='TypeAnnotation', name_for_diagnostics="macro signature"), - ]), - Child('Definition', kind='InitializerClause', name_for_diagnostics='macro definition', is_optional=True), - Child('GenericWhereClause', kind='GenericWhereClause', name_for_diagnostics='generic where clause', - is_optional=True), - ]), - - # e.g., "#embed("filename.txt")" - Node('MacroExpansionDecl', - name_for_diagnostics="macro expansion", kind='Decl', - traits=['FreestandingMacroExpansion'], - children=[ - Child('PoundToken', kind='PoundToken', - description='The `#` sign.'), - Child('Macro', kind='IdentifierToken'), - Child('GenericArguments', kind='GenericArgumentClause', - is_optional=True), - Child('LeftParen', kind='LeftParenToken', - is_optional=True), - Child('ArgumentList', kind='TupleExprElementList', - collection_element_name='Argument'), - Child('RightParen', kind='RightParenToken', - is_optional=True), - Child('TrailingClosure', kind='ClosureExpr', - is_optional=True), - Child('AdditionalTrailingClosures', - kind='MultipleTrailingClosureElementList', - collection_element_name='AdditionalTrailingClosure', - is_optional=True), - ]), - - # <#content#> - Node('EditorPlaceholderDecl', name_for_diagnostics='editor placeholder', - kind='Decl', - children=[ - Child('Identifier', kind='IdentifierToken'), - ]), -] diff --git a/gyb_syntax_support/ExprNodes.py b/gyb_syntax_support/ExprNodes.py deleted file mode 100644 index bcbbe6eed48..00000000000 --- a/gyb_syntax_support/ExprNodes.py +++ /dev/null @@ -1,791 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -EXPR_NODES = [ - # An inout expression. - # &x - Node('InOutExpr', name_for_diagnostics='inout expression', kind='Expr', - children=[ - Child('Ampersand', kind='PrefixAmpersandToken'), - Child('Expression', kind='Expr'), - ]), - - Node('TupleExprElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='TupleExprElement'), - - Node('ArrayElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='ArrayElement'), - - Node('DictionaryElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='DictionaryElement'), - - Node('StringLiteralSegments', name_for_diagnostics=None, kind='SyntaxCollection', - element='Syntax', element_name='Segment', - element_choices=['StringSegment', 'ExpressionSegment']), - - # The try operator. - # try foo() - # try? foo() - # try! foo() - Node('TryExpr', name_for_diagnostics="'try' expression", kind='Expr', - children=[ - Child('TryKeyword', kind='KeywordToken', token_choices=['KeywordToken|try']), - Child('QuestionOrExclamationMark', kind='Token', - is_optional=True, - token_choices=[ - 'PostfixQuestionMarkToken', - 'ExclamationMarkToken', - ], - requires_trailing_space=True), - Child('Expression', kind='Expr'), - ]), - - # The await operator. - # await foo() - Node('AwaitExpr', name_for_diagnostics="'await' expression", kind='Expr', - children=[ - Child('AwaitKeyword', kind='KeywordToken', - token_choices=['KeywordToken|await']), - Child('Expression', kind='Expr'), - ]), - - # The move expr - Node('MoveExpr', name_for_diagnostics="'_move' expression", kind='Expr', - children=[ - Child('MoveKeyword', kind='KeywordToken', - token_choices=[ - 'KeywordToken|_move', - 'KeywordToken|consume', - ]), - Child('Expression', kind='Expr'), - ]), - - # The borrow expr - Node('BorrowExpr', name_for_diagnostics="'_borrow' expression", kind='Expr', - children=[ - Child('BorrowKeyword', kind='KeywordToken', - token_choices=['KeywordToken|_borrow']), - Child('Expression', kind='Expr'), - ]), - - # declname-arguments -> '(' declname-argument-list ')' - # declname-argument-list -> declname-argument* - # declname-argument -> identifier ':' - Node('DeclNameArgument', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Name', kind='Token'), - Child('Colon', kind='ColonToken', requires_trailing_space=False), - ]), - Node('DeclNameArgumentList', name_for_diagnostics=None, kind='SyntaxCollection', - element='DeclNameArgument'), - Node('DeclNameArguments', name_for_diagnostics=None, kind='Syntax', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Arguments', kind='DeclNameArgumentList', - collection_element_name='Argument'), - Child('RightParen', kind='RightParenToken'), - ]), - - # An identifier expression. - Node('IdentifierExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Identifier', kind='Token', - token_choices=[ - 'IdentifierToken', - 'KeywordToken', - 'DollarIdentifierToken', - 'BinaryOperatorToken', - ]), - Child('DeclNameArguments', kind='DeclNameArguments', - is_optional=True), - ]), - - # An 'super' expression. - Node('SuperRefExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('SuperKeyword', kind='KeywordToken', token_choices=['KeywordToken|super']), - ]), - - # A nil expression. - Node('NilLiteralExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('NilKeyword', kind='KeywordToken', token_choices=['KeywordToken|nil']), - ]), - - # A _ expression. - Node('DiscardAssignmentExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Wildcard', kind='WildcardToken'), - ]), - - # An = expression. - Node('AssignmentExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('AssignToken', kind='EqualToken'), - ]), - - # A pack expansion expr spelled with 'repeat'. - Node('PackExpansionExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('RepeatKeyword', kind='KeywordToken', token_choices=['KeywordToken|repeat']), - Child('PatternExpr', kind='Expr'), - ]), - - # A pack element expr spelled with 'each'. - Node('PackElementExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('EachKeyword', kind='KeywordToken', - token_choices=['KeywordToken|each']), - Child('PackRefExpr', kind='Expr'), - ]), - - # A flat list of expressions before sequence folding, e.g. 1 + 2 + 3. - Node('SequenceExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Elements', kind='ExprList', - collection_element_name='Element'), - ]), - - Node('ExprList', name_for_diagnostics=None, kind='SyntaxCollection', - element='Expr', - element_name='Expression', - description=''' - A list of expressions connected by operators. This list is contained - by a `SequenceExprSyntax`. - '''), - - # A prefix operator expression. - # -x - # !true - Node('PrefixOperatorExpr', name_for_diagnostics='operator', - kind='Expr', - children=[ - Child('OperatorToken', kind='PrefixOperatorToken', - is_optional=True), - Child('PostfixExpression', kind='Expr'), - ]), - - # An operator like + or -. - # NOTE: This appears only in SequenceExpr. - Node('BinaryOperatorExpr', name_for_diagnostics='operator', - kind='Expr', - children=[ - Child('OperatorToken', kind='BinaryOperatorToken'), - ]), - - # arrow-expr -> 'async'? 'throws'? '->' - # NOTE: This appears only in SequenceExpr. - Node('ArrowExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('EffectSpecifiers', kind='TypeEffectSpecifiers', is_optional=True), - Child('ArrowToken', kind='ArrowToken'), - ]), - - # An infix binary expression like x + y. - # NOTE: This won't come directly out of the parser. Rather, it is the - # result of "folding" a SequenceExpr based on knowing the precedence - # relationships amongst the different infix operators. - Node('InfixOperatorExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('LeftOperand', kind='Expr'), - Child('OperatorOperand', kind='Expr'), - Child('RightOperand', kind='Expr'), - ]), - - # A floating-point literal - # 4.0 - # -3.9 - # +4e20 - Node('FloatLiteralExpr', name_for_diagnostics='floating literal', kind='Expr', - children=[ - Child('FloatingDigits', kind='FloatingLiteralToken'), - ]), - - Node('TupleExpr', name_for_diagnostics='tuple', kind='Expr', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('ElementList', kind='TupleExprElementList', - collection_element_name='Element', is_indented=True), - Child('RightParen', kind='RightParenToken'), - ]), - - # Array literal, e.g. [1, 2, 3] - Node('ArrayExpr', name_for_diagnostics='array', kind='Expr', - children=[ - Child('LeftSquare', kind='LeftSquareBracketToken'), - Child('Elements', kind='ArrayElementList', - collection_element_name='Element', is_indented=True), - Child('RightSquare', kind='RightSquareBracketToken'), - ]), - - # Dictionary literal, e.g. [1:1, 2:2, 3:3] - Node('DictionaryExpr', name_for_diagnostics='dictionary', kind='Expr', - children=[ - Child('LeftSquare', kind='LeftSquareBracketToken'), - Child('Content', kind='Syntax', - node_choices=[ - Child('Colon', kind='ColonToken', requires_trailing_space=False), - Child('Elements', kind='DictionaryElementList'), - ], is_indented=True), - Child('RightSquare', kind='RightSquareBracketToken'), - ]), - - # An element inside a tuple element list - Node('TupleExprElement', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Label', kind='Token', name_for_diagnostics='label', - is_optional=True, - token_choices=[ - 'IdentifierToken', - 'WildcardToken' - ]), - Child('Colon', kind='ColonToken', - is_optional=True), - Child('Expression', kind='Expr', name_for_diagnostics='value'), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # element inside an array expression: expression ','? - Node('ArrayElement', name_for_diagnostics='array element', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Expression', kind='Expr', name_for_diagnostics='value'), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - # element inside an array expression: expression ','? - Node('DictionaryElement', name_for_diagnostics='dictionary element', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('KeyExpression', kind='Expr', name_for_diagnostics='key'), - Child('Colon', kind='ColonToken'), - Child('ValueExpression', kind='Expr', name_for_diagnostics='value', is_indented=True), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - # An integer literal. - # 3 - # +3_400 - # +0x4f - Node('IntegerLiteralExpr', name_for_diagnostics='integer literal', kind='Expr', - children=[ - Child('Digits', kind='IntegerLiteralToken'), - ]), - - # true or false - Node('BooleanLiteralExpr', name_for_diagnostics='bool literal', kind='Expr', - children=[ - Child("BooleanLiteral", kind='KeywordToken', token_choices=['KeywordToken|true', 'KeywordToken|false']) - ]), - - # if-expr -> identifier? ':'? 'if' condition-list code-block - # else-clause ';'? - # - # This node represents both an 'if' expression, as well as an 'if' statement - # when wrapped in a ExpressionStmt node. - Node('IfExpr', name_for_diagnostics="'if' statement", kind='Expr', - traits=['WithCodeBlock'], - children=[ - Child('IfKeyword', kind='KeywordToken', token_choices=['KeywordToken|if']), - Child('Conditions', kind='ConditionElementList', - collection_element_name='Condition'), - Child('Body', kind='CodeBlock', name_for_diagnostics='body'), - Child('ElseKeyword', kind='ElseToken', - is_optional=True), - Child('ElseBody', kind='Syntax', name_for_diagnostics='else body', - node_choices=[ - Child('IfExpr', kind='IfExpr'), - Child('CodeBlock', kind='CodeBlock'), - ], - is_optional=True), - ]), - - # switch-expr -> identifier? ':'? 'switch' expr '{' - # switch-case-list '}' ';'? - # - # This node represents both a 'switch' expression, as well as a 'switch' - # statement when wrapped in a ExpressionStmt node. - Node('SwitchExpr', name_for_diagnostics="'switch' statement", kind='Expr', - traits=['Braced'], - children=[ - Child('SwitchKeyword', kind='KeywordToken', token_choices=['KeywordToken|switch']), - Child('Expression', kind='Expr'), - Child('LeftBrace', kind='LeftBraceToken'), - Child('Cases', kind='SwitchCaseList', - collection_element_name='Case'), - Child('RightBrace', kind='RightBraceToken', - requires_leading_newline=True), - ]), - - # switch-case-list -> switch-case switch-case-list? - Node('SwitchCaseList', name_for_diagnostics=None, kind='SyntaxCollection', - element='Syntax', element_name='SwitchCase', - element_choices=['SwitchCase', 'IfConfigDecl'], - elements_separated_by_newline=True), - - # switch-case -> unknown-attr? switch-case-label stmt-list - # | unknown-attr? switch-default-label stmt-list - Node('SwitchCase', name_for_diagnostics='switch case', kind='Syntax', - traits=['WithStatements'], - parser_function='parseSwitchCase', - children=[ - Child('UnknownAttr', kind='Attribute', is_optional=True), - Child('Label', kind='Syntax', name_for_diagnostics='label', - node_choices=[ - Child('Default', kind='SwitchDefaultLabel'), - Child('Case', kind='SwitchCaseLabel'), - ]), - Child('Statements', kind='CodeBlockItemList', - collection_element_name='Statement', - is_indented=True), - ]), - - # switch-case-label -> 'case' case-item-list ':' - Node('SwitchCaseLabel', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('CaseKeyword', kind='KeywordToken', token_choices=['KeywordToken|case']), - Child('CaseItems', kind='CaseItemList', - collection_element_name='CaseItem'), - Child('Colon', kind='ColonToken', requires_trailing_space=False), - ]), - - # switch-default-label -> 'default' ':' - Node('SwitchDefaultLabel', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('DefaultKeyword', kind='KeywordToken', token_choices=['KeywordToken|default']), - Child('Colon', kind='ColonToken', requires_trailing_space=False), - ]), - - # case-item -> pattern where-clause? ','? - Node('CaseItem', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Pattern', kind='Pattern'), - Child('WhereClause', kind='WhereClause', - is_optional=True), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # ? expr : - # Ternary expression without the condition and the second choice. - # NOTE: This appears only in SequenceExpr. - Node('UnresolvedTernaryExpr', name_for_diagnostics='ternary operator', kind='Expr', - children=[ - Child("QuestionMark", kind='InfixQuestionMarkToken'), - Child("FirstChoice", kind='Expr'), - Child("ColonMark", kind='ColonToken'), - ]), - - - # a ? 1 : 0 - # NOTE: This won't come directly out of the parser. Rather, it is the - # result of "folding" a SequenceExpr based on knowing the precedence - # relationships amongst the different infix operators. - Node('TernaryExpr', name_for_diagnostics='ternay expression', kind='Expr', - children=[ - Child("ConditionExpression", kind='Expr', name_for_diagnostics='condition'), - Child("QuestionMark", kind='InfixQuestionMarkToken'), - Child("FirstChoice", kind='Expr', name_for_diagnostics='first choice'), - Child("ColonMark", kind='ColonToken'), - Child("SecondChoice", kind='Expr', name_for_diagnostics='second choice') - ]), - - # expr?.name - Node('MemberAccessExpr', name_for_diagnostics='member access', kind='Expr', - children=[ - # The base needs to be optional to parse expressions in key paths - # like \.a - Child("Base", kind='Expr', name_for_diagnostics='base', is_optional=True), - Child("Dot", kind='PeriodToken'), - # Name could be 'self' - Child("Name", kind='Token', name_for_diagnostics='name'), - Child('DeclNameArguments', kind='DeclNameArguments', - is_optional=True), - ]), - - # 'is' - # "is" type casting ooperator without operands. - # NOTE: This appears only in SequenceExpr. - Node('UnresolvedIsExpr', name_for_diagnostics="'is'", kind='Expr', - children=[ - Child("IsTok", kind='KeywordToken', token_choices=['KeywordToken|is']), - ]), - - # expression is TypeName - # NOTE: This won't come directly out of the parser. Rather, it is the - # result of "folding" a SequenceExpr based on knowing the precedence - # relationships amongst the different infix operators. - Node('IsExpr', name_for_diagnostics="'is'", kind='Expr', - children=[ - Child("Expression", kind="Expr"), - Child("IsTok", kind='KeywordToken', token_choices=['KeywordToken|is']), - Child("TypeName", kind='Type') - ]), - - # 'as' ('?'|'!') - # "as" type casting ooperator without operands. - # NOTE: This appears only in SequenceExpr. - Node('UnresolvedAsExpr', name_for_diagnostics="'as'", kind='Expr', - children=[ - Child("AsTok", kind='KeywordToken', token_choices=['KeywordToken|as']), - Child("QuestionOrExclamationMark", kind='Token', - is_optional=True, - token_choices=[ - 'PostfixQuestionMarkToken', - 'ExclamationMarkToken', - ]), - ]), - - # expression as TypeName - # NOTE: This won't come directly out of the parser. Rather, it is the - # result of "folding" a SequenceExpr based on knowing the precedence - # relationships amongst the different infix operators. - Node('AsExpr', name_for_diagnostics="'as'", kind='Expr', - children=[ - Child("Expression", kind="Expr"), - Child("AsTok", kind='KeywordToken', token_choices=['KeywordToken|as']), - Child("QuestionOrExclamationMark", kind='Token', - is_optional=True, - token_choices=[ - 'PostfixQuestionMarkToken', - 'ExclamationMarkToken', - ]), - Child("TypeName", kind='Type') - ]), - - # Type - Node('TypeExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Type', kind='Type'), - ]), - - Node('ClosureCaptureItemSpecifier', name_for_diagnostics='closure capture specifier', kind='Syntax', - children=[ - Child('Specifier', kind='KeywordToken', token_choices=['KeywordToken|weak', 'KeywordToken|unowned']), - Child('LeftParen', kind='LeftParenToken', is_optional=True), - Child('Detail', kind='KeywordToken', is_optional=True, token_choices=['KeywordToken|safe', 'KeywordToken|unsafe']), - Child('RightParen', kind='RightParenToken', is_optional=True), - ]), - - Node('ClosureCaptureItem', name_for_diagnostics='closure capture item', - kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Specifier', kind='ClosureCaptureItemSpecifier', is_optional=True), - Child("Name", kind='IdentifierToken', is_optional=True), - Child('AssignToken', kind='EqualToken', is_optional=True), - Child("Expression", kind='Expr'), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - Node('ClosureCaptureItemList', name_for_diagnostics=None, kind='SyntaxCollection', - element='ClosureCaptureItem'), - - Node('ClosureCaptureSignature', name_for_diagnostics='closure capture signature', - kind='Syntax', - children=[ - Child('LeftSquare', kind='LeftSquareBracketToken'), - Child('Items', kind='ClosureCaptureItemList', - collection_element_name='Item', is_optional=True), - Child('RightSquare', kind='RightSquareBracketToken'), - ]), - - Node('ClosureParam', name_for_diagnostics='closure parameter', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Name', kind='Token', name_for_diagnostics='name', - token_choices=[ - 'IdentifierToken', - 'WildcardToken', - ]), - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - # a, b, c - Node('ClosureParamList', name_for_diagnostics=None, kind='SyntaxCollection', - element='ClosureParam'), - - Node('ClosureSignature', name_for_diagnostics='closure signature', kind='Syntax', - traits=['Attributed'], - children=[ - Child('Attributes', kind='AttributeList', name_for_diagnostics='attributes', - collection_element_name='Attribute', is_optional=True), - Child('Capture', kind='ClosureCaptureSignature', - is_optional=True), - Child('Input', kind='Syntax', is_optional=True, - node_choices=[ - Child('SimpleInput', kind='ClosureParamList'), - Child('Input', kind='ParameterClause'), - ]), - Child('EffectSpecifiers', kind='TypeEffectSpecifiers', - is_optional=True), - Child('Output', kind='ReturnClause', is_optional=True), - Child('InTok', kind='KeywordToken', token_choices=['KeywordToken|in']), - ]), - - Node('ClosureExpr', name_for_diagnostics='closure', kind='Expr', - traits=['Braced', 'WithStatements'], - children=[ - Child('LeftBrace', kind='LeftBraceToken'), - Child('Signature', kind='ClosureSignature', is_optional=True), - Child('Statements', kind='CodeBlockItemList', - collection_element_name='Statement', is_indented=True), - Child('RightBrace', kind='RightBraceToken', - requires_leading_newline=True), - ]), - - # unresolved-pattern-expr -> pattern - Node('UnresolvedPatternExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Pattern', kind='Pattern'), - ]), - - # trailing-closure-element -> identifier ':' closure-expression - Node('MultipleTrailingClosureElement', name_for_diagnostics='trailing closure', - kind='Syntax', - children=[ - Child('Label', kind='Token', name_for_diagnostics='label', - token_choices=[ - 'IdentifierToken', - 'WildcardToken' - ]), - Child('Colon', kind='ColonToken'), - Child('Closure', kind='ClosureExpr'), - ]), - - Node('MultipleTrailingClosureElementList', name_for_diagnostics=None, - kind='SyntaxCollection', element='MultipleTrailingClosureElement'), - - # call-expr -> expr '(' call-argument-list ')' closure-expr? - # | expr closure-expr - Node('FunctionCallExpr', name_for_diagnostics='function call', kind='Expr', - children=[ - Child('CalledExpression', kind='Expr', name_for_diagnostics='called expression'), - Child('LeftParen', kind='LeftParenToken', - is_optional=True), - Child('ArgumentList', kind='TupleExprElementList', name_for_diagnostics='arguments', - collection_element_name='Argument', is_indented=True), - Child('RightParen', kind='RightParenToken', - is_optional=True), - Child('TrailingClosure', kind='ClosureExpr', name_for_diagnostics='trailing closure', - is_optional=True), - Child('AdditionalTrailingClosures', name_for_diagnostics='trailing closures', - kind='MultipleTrailingClosureElementList', - collection_element_name='AdditionalTrailingClosure', - is_optional=True), - ]), - - # subscript-expr -> expr '[' call-argument-list ']' closure-expr? - Node('SubscriptExpr', name_for_diagnostics='subscript', kind='Expr', - children=[ - Child('CalledExpression', kind='Expr', name_for_diagnostics='called expression'), - Child('LeftBracket', kind='LeftSquareBracketToken'), - Child('ArgumentList', kind='TupleExprElementList', name_for_diagnostics='arguments', - collection_element_name='Argument'), - Child('RightBracket', kind='RightSquareBracketToken'), - Child('TrailingClosure', kind='ClosureExpr', name_for_diagnostics='trailing closure', - is_optional=True), - Child('AdditionalTrailingClosures', name_for_diagnostics='trailing closures', - kind='MultipleTrailingClosureElementList', - collection_element_name='AdditionalTrailingClosure', - is_optional=True), - ]), - - # optional-chaining-expr -> expr '?' - Node('OptionalChainingExpr', name_for_diagnostics='optional chaining', kind='Expr', - children=[ - Child('Expression', kind='Expr'), - Child('QuestionMark', kind='PostfixQuestionMarkToken'), - ]), - - # forced-value-expr -> expr '!' - Node('ForcedValueExpr', name_for_diagnostics='force unwrap', kind='Expr', - children=[ - Child('Expression', kind='Expr'), - Child('ExclamationMark', kind='ExclamationMarkToken'), - ]), - - # postfix-unary-expr -> expr postfix-operator - Node('PostfixUnaryExpr', name_for_diagnostics='postfix expression', kind='Expr', - children=[ - Child('Expression', kind='Expr'), - Child('OperatorToken', kind='PostfixOperatorToken'), - ]), - - # specialize-expr -> expr generic-argument-clause? - Node('SpecializeExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Expression', kind='Expr'), - Child('GenericArgumentClause', kind='GenericArgumentClause'), - ]), - - # string literal segment in a string interpolation expression. - Node('StringSegment', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Content', kind='StringSegmentToken'), - ]), - - # expression segment in a string interpolation expression. - Node('ExpressionSegment', name_for_diagnostics=None, kind='Syntax', - traits=['Parenthesized'], - children=[ - Child('Backslash', kind='BackslashToken'), - Child('Delimiter', kind='RawStringDelimiterToken', - is_optional=True), - Child('LeftParen', kind='LeftParenToken', - classification='StringInterpolationAnchor', - force_classification=True), - Child('Expressions', kind='TupleExprElementList', - collection_element_name='Expression'), - Child('RightParen', kind='RightParenToken', - classification='StringInterpolationAnchor', - force_classification=True), - ]), - - # e.g. "abc \(foo()) def" - Node('StringLiteralExpr', name_for_diagnostics='string literal', kind='Expr', - children=[ - Child('OpenDelimiter', kind='RawStringDelimiterToken', - is_optional=True), - Child('OpenQuote', kind='Token', - token_choices=[ - 'StringQuoteToken', - 'MultilineStringQuoteToken', - 'SingleQuoteToken', - ]), - Child('Segments', kind='StringLiteralSegments', - collection_element_name='Segment'), - Child('CloseQuote', kind='Token', - token_choices=[ - 'StringQuoteToken', - 'MultilineStringQuoteToken', - 'SingleQuoteToken', - ]), - Child('CloseDelimiter', kind='RawStringDelimiterToken', - is_optional=True), - ]), - - # e.g '(a|c)*', the contents of the literal is opaque to the C++ Swift - # parser though. - Node('RegexLiteralExpr', name_for_diagnostics='regex literal', kind='Expr', - children=[ - Child('Regex', kind='RegexLiteralToken'), - ]), - - # e.g. "\a.b[2].a" - Node('KeyPathExpr', name_for_diagnostics='key path', kind='Expr', - children=[ - Child('Backslash', kind='BackslashToken'), - Child('Root', kind='Type', name_for_diagnostics='root', is_optional=True), - Child('Components', kind='KeyPathComponentList', - collection_element_name='KeyPathComponent'), - ]), - - # The components of a key path - Node('KeyPathComponentList', name_for_diagnostics=None, - kind='SyntaxCollection', element='KeyPathComponent'), - - # A single key path component. - Node('KeyPathComponent', name_for_diagnostics='key path component', - kind='Syntax', - children=[ - Child('Period', kind='PeriodToken', - is_optional=True), - - Child('Component', kind='Syntax', node_choices=[ - Child('Property', kind='KeyPathPropertyComponent'), - Child('Subscript', kind='KeyPathSubscriptComponent'), - Child('Optional', kind='KeyPathOptionalComponent'), - ]) - ]), - - # A key path component like .property or .1. - Node('KeyPathPropertyComponent', name_for_diagnostics='key path property component', kind='Syntax', - children=[ - Child('Identifier', kind='Token', - token_choices=[ - 'IdentifierToken', - 'KeywordToken', - 'DollarIdentifierToken', - 'BinaryOperatorToken', - 'IntegerLiteralToken', - ]), - Child('DeclNameArguments', kind='DeclNameArguments', - is_optional=True), - Child('GenericArgumentClause', kind='GenericArgumentClause', - is_optional=True), - - ]), - - # A key path component like .[17] - Node('KeyPathSubscriptComponent', name_for_diagnostics='key path subscript component', kind='Syntax', - children=[ - Child('LeftBracket', kind='LeftSquareBracketToken'), - Child('ArgumentList', kind='TupleExprElementList', name_for_diagnostics='arguments', - collection_element_name='Argument'), - Child('RightBracket', kind='RightSquareBracketToken'), - ]), - - # A key path component like '?' or '!'. - Node('KeyPathOptionalComponent', name_for_diagnostics='key path optional component', kind='Syntax', - children=[ - Child("QuestionOrExclamationMark", kind='Token', - token_choices=[ - 'PostfixQuestionMarkToken', - 'ExclamationMarkToken', - ]), - ]), - - # e.g., "#embed("filename.txt")" - Node('MacroExpansionExpr', - name_for_diagnostics="macro expansion", kind='Expr', - traits=['FreestandingMacroExpansion'], - children=[ - Child('PoundToken', kind='PoundToken', - description='The `#` sign.'), - Child('Macro', kind='IdentifierToken'), - Child('GenericArguments', kind='GenericArgumentClause', - is_optional=True), - Child('LeftParen', kind='LeftParenToken', - is_optional=True), - Child('ArgumentList', kind='TupleExprElementList', - collection_element_name='Argument'), - Child('RightParen', kind='RightParenToken', - is_optional=True), - Child('TrailingClosure', kind='ClosureExpr', - is_optional=True), - Child('AdditionalTrailingClosures', - kind='MultipleTrailingClosureElementList', - collection_element_name='AdditionalTrailingClosure', - is_optional=True), - ]), - - # postfix '#if' expression - Node('PostfixIfConfigExpr', name_for_diagnostics=None, kind='Expr', - children=[ - Child('Base', kind='Expr', is_optional=True), - Child('Config', kind='IfConfigDecl'), - ]), - - # <#content#> - Node('EditorPlaceholderExpr', name_for_diagnostics='editor placeholder', - kind='Expr', - children=[ - Child('Identifier', kind='IdentifierToken'), - ]), - - Node('YieldExprList', name_for_diagnostics='yield list', - kind='SyntaxCollection', - element='YieldExprListElement', - element_name='Yields'), - Node('YieldExprListElement', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Expression', kind='Expr'), - Child('Comma', kind='CommaToken', is_optional=True), - ]), -] diff --git a/gyb_syntax_support/GenericNodes.py b/gyb_syntax_support/GenericNodes.py deleted file mode 100644 index 363d6f25a7b..00000000000 --- a/gyb_syntax_support/GenericNodes.py +++ /dev/null @@ -1,132 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -GENERIC_NODES = [ - # generic-where-clause -> 'where' requirement-list - Node('GenericWhereClause', name_for_diagnostics="'where' clause", kind='Syntax', - children=[ - Child('WhereKeyword', kind='KeywordToken', token_choices=['KeywordToken|where']), - Child('RequirementList', kind='GenericRequirementList', - collection_element_name='Requirement'), - ]), - - Node('GenericRequirementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='GenericRequirement', - element_name='GenericRequirement'), - - # generic-requirement -> - # (same-type-requirement|conformance-requirement|layout-requirement) ','? - Node('GenericRequirement', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Body', kind='Syntax', - node_choices=[ - Child('SameTypeRequirement', - kind='SameTypeRequirement'), - Child('ConformanceRequirement', - kind='ConformanceRequirement'), - Child('LayoutRequirement', - kind='LayoutRequirement'), - ]), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # same-type-requirement -> type-identifier == type - Node('SameTypeRequirement', name_for_diagnostics='same type requirement', - kind='Syntax', - children=[ - Child('LeftTypeIdentifier', kind='Type', name_for_diagnostics='left-hand type'), - Child('EqualityToken', kind='Token', - token_choices=[ - 'BinaryOperatorToken', - 'PrefixOperatorToken', - 'PostfixOperatorToken', - ]), - Child('RightTypeIdentifier', name_for_diagnostics='right-hand type', kind='Type'), - ]), - - # layout-requirement -> type-name : layout-constraint - # layout-constraint -> identifier '('? integer-literal? ','? integer-literal? ')'? - Node('LayoutRequirement', name_for_diagnostics='layout requirement', kind='Syntax', - children=[ - Child('TypeIdentifier', kind='Type', name_for_diagnostics='constrained type'), - Child('Colon', kind='ColonToken'), - Child('LayoutConstraint', kind='KeywordToken', token_choices=['KeywordToken|_Trivial', 'KeywordToken|_TrivialAtMost', 'KeywordToken|_UnknownLayout', 'KeywordToken|_RefCountedObject', 'KeywordToken|_NativeRefCountedObject', 'KeywordToken|_Class', 'KeywordToken|_NativeClass']), - Child('LeftParen', kind='LeftParenToken', - is_optional=True), - Child('Size', kind='IntegerLiteralToken', name_for_diagnostics='size', is_optional=True), - Child('Comma', kind='CommaToken', - is_optional=True), - Child('Alignment', kind='IntegerLiteralToken', name_for_diagnostics='alignment', is_optional=True), - Child('RightParen', kind='RightParenToken', - is_optional=True), - ]), - - Node('GenericParameterList', name_for_diagnostics=None, kind='SyntaxCollection', - element='GenericParameter'), - - # generic-parameter -> type-name - # | type-name : type-identifier - # | type-name : protocol-composition-type - Node('GenericParameter', name_for_diagnostics='generic parameter', kind='Syntax', - traits=['WithTrailingComma', 'Attributed'], - children=[ - Child('Attributes', kind='AttributeList', - collection_element_name='Attribute', is_optional=True), - Child('Each', - name_for_diagnostics='parameter pack specifier', - kind='KeywordToken', token_choices=['KeywordToken|each'], is_optional=True), - Child('Name', name_for_diagnostics='name', kind='IdentifierToken'), - Child('Colon', kind='ColonToken', - is_optional=True), - Child('InheritedType', name_for_diagnostics='inherited type', kind='Type', - is_optional=True), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - Node('PrimaryAssociatedTypeList', name_for_diagnostics=None, - kind='SyntaxCollection', element='PrimaryAssociatedType'), - - # primary-associated-type -> type-name ','? - Node('PrimaryAssociatedType', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Name', name_for_diagnostics='name', kind='IdentifierToken'), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # generic-parameter-clause -> '<' generic-parameter-list generic-where-clause? '>' - Node('GenericParameterClause', name_for_diagnostics='generic parameter clause', - kind='Syntax', - parser_function='parseGenericParameters', - children=[ - Child('LeftAngleBracket', kind='LeftAngleToken'), - Child('GenericParameterList', kind='GenericParameterList', - collection_element_name='GenericParameter'), - Child('GenericWhereClause', kind='GenericWhereClause', - is_optional=True), - Child('RightAngleBracket', kind='RightAngleToken'), - ]), - - # conformance-requirement -> type-identifier : type-identifier - Node('ConformanceRequirement', name_for_diagnostics='conformance requirement', - kind='Syntax', - children=[ - Child('LeftTypeIdentifier', kind='Type'), - Child('Colon', kind='ColonToken'), - Child('RightTypeIdentifier', kind='Type'), - ]), - - # primary-associated-type-clause -> '<' primary-associated-type-list '>' - Node('PrimaryAssociatedTypeClause', - name_for_diagnostics='primary associated type clause', kind='Syntax', - children=[ - Child('LeftAngleBracket', kind='LeftAngleToken'), - Child('PrimaryAssociatedTypeList', kind='PrimaryAssociatedTypeList', - collection_element_name='PrimaryAssociatedType'), - Child('RightAngleBracket', kind='RightAngleToken'), - ]), -] diff --git a/gyb_syntax_support/Node.py b/gyb_syntax_support/Node.py deleted file mode 100644 index 6838e1bcb55..00000000000 --- a/gyb_syntax_support/Node.py +++ /dev/null @@ -1,180 +0,0 @@ -from .Child import Child # noqa: I201 -from .Utils import error -from .kinds import SYNTAX_BASE_KINDS, kind_to_type, lowercase_first_word - - -class Node(object): - """ - A Syntax node, possibly with children. - If the kind is "SyntaxCollection", then this node is considered a Syntax - Collection that will expose itself as a typedef rather than a concrete - subclass. - """ - - def __init__(self, name, name_for_diagnostics, description=None, kind=None, - traits=None, parser_function=None, children=[], element=None, - element_name=None, element_choices=None, omit_when_empty=False, - elements_separated_by_newline=False): - self.syntax_kind = name - self.element_name = element_name - self.swift_syntax_kind = lowercase_first_word(name) - self.name = kind_to_type(self.syntax_kind) - self.kind = kind - self.name_for_diagnostics = name_for_diagnostics - self.description = description - self.parser_function = parser_function - - self.traits = traits or [] - self.children = [] - # Add implicitly generated UnexpectedNodes children in between any two - # defined children - if kind != 'SyntaxCollection' and len(children) > 0: - for i in range(2 * len(children) + 1): - if i % 2 == 0: - if i == 0: - name = 'UnexpectedBefore' + children[0].name - elif i == 2 * len(children): - name = 'UnexpectedAfter' + children[-1].name - else: - name = 'UnexpectedBetween%sAnd%s' % \ - (children[int(i / 2) - 1].name, children[int(i / 2)].name) - self.children.append(Child( - name, - kind='UnexpectedNodes', - collection_element_name=name, - is_optional=True - )) - else: - self.children.append(children[int((i - 1) / 2)]) - elif kind != 'SyntaxCollection' and len(children) == 0: - self.children.append(Child( - 'Unexpected', - kind='UnexpectedNodes', - collection_element_name='Unexpected', - is_optional=True - )) - - self.non_unexpected_children = \ - [child for child in children if not child.is_unexpected_nodes()] - - self.base_kind = kind - if self.base_kind == 'SyntaxCollection': - self.base_type = 'Syntax' - else: - self.base_type = kind_to_type(self.base_kind) - - if self.base_kind not in SYNTAX_BASE_KINDS: - error("unknown base kind '%s' for node '%s'" % - (self.base_kind, self.syntax_kind)) - - self.omit_when_empty = omit_when_empty - self.collection_element = element or "" - # For SyntaxCollections make sure that the element_name is set. - assert not self.is_syntax_collection() or element_name or element - # If there's a preferred name for the collection element that differs - # from its supertype, use that. - self.collection_element_name = element_name or self.collection_element - self.collection_element_type = kind_to_type(self.collection_element) - self.collection_element_choices = element_choices or [] - self.elements_separated_by_newline = elements_separated_by_newline - - def is_base(self): - """ - Returns `True` if this node declares one of the base syntax kinds. - """ - return self.syntax_kind in SYNTAX_BASE_KINDS - - def is_syntax_collection(self): - """ - Returns `True` if this node is a subclass of SyntaxCollection. - """ - return self.base_kind == "SyntaxCollection" - - def requires_validation(self): - """ - Returns `True` if this node should have a `validate` method associated. - """ - return self.is_buildable() - - def is_unknown(self): - """ - Returns `True` if this node is an `Unknown` syntax subclass. - """ - return "Unknown" in self.syntax_kind - - def is_missing(self): - """ - Returns `True` if this node is a `Missing` syntax subclass. - """ - return "Missing" in self.syntax_kind - - def is_buildable(self): - """ - Returns `True` if this node should have a builder associated. - """ - return not self.is_base() and \ - not self.is_unknown() and \ - not self.is_missing() and \ - not self.is_syntax_collection() - - def shall_be_omitted_when_empty(self): - """ - Returns 'True' if this node shall not be created while parsing if it - has no children. - """ - return self.omit_when_empty - - def is_token(self): - """ - Returns true if this child has a token kind. - """ - return 'Token' in self.syntax_kind or \ - 'Token' in self.collection_element - - def has_optional_base_type_child(self): - return any(child.has_optional_base_type() for child in self.children) - - def generate_initializer_decl(self, optional_base_as_missing, current_indentation=""): - if not self.children: - return "public init()" - - generic_param_names = {} - generic_params = [] - params = [] - - if self.children: - params.append("leadingTrivia: Trivia? = nil") - for child in self.children: - if child.node_choices: - param_type = child.name - elif child.has_base_type(): - if optional_base_as_missing: - param_type = f"Missing{child.type_name}" - else: - # If we have a base type, make the initializer generic over its - # protocol instead. - param_type = child.swift_name[0].upper() - - param_count = generic_param_names.get(param_type, 0) + 1 - generic_param_names[param_type] = param_count - if param_count > 1: - param_type += str(param_count) - - generic_params.append(f"{param_type}: {child.type_name}Protocol") - else: - param_type = child.type_name - - if child.is_optional: - param_type += "?" - label = "_ " if child.is_unexpected_nodes() else "" - - params.append(f"{label}{child.swift_name}: {param_type}{child.generate_default_initialization()}") - if self.children: - params.append("trailingTrivia: Trivia? = nil") - - param_indentation = current_indentation + " " - separator = ",\n" + param_indentation - generics = "" - if generic_params: - generics = f"<{', '.join(generic_params)}>" - return f"public init{generics}(\n{param_indentation}{separator.join(params)}\n{current_indentation})" diff --git a/gyb_syntax_support/PatternNodes.py b/gyb_syntax_support/PatternNodes.py deleted file mode 100644 index 0b26d654e6b..00000000000 --- a/gyb_syntax_support/PatternNodes.py +++ /dev/null @@ -1,83 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -PATTERN_NODES = [ - - # type-annotation -> ':' type - Node('TypeAnnotation', name_for_diagnostics='type annotation', kind='Syntax', - children=[ - Child('Colon', kind='ColonToken'), - Child('Type', kind='Type'), - ]), - - # is-type-pattern -> 'is' type - Node('IsTypePattern', name_for_diagnostics="'is' pattern", kind='Pattern', - children=[ - Child('IsKeyword', kind='KeywordToken', token_choices=['KeywordToken|is']), - Child('Type', kind='Type'), - ]), - - # identifier-pattern -> identifier - Node('IdentifierPattern', name_for_diagnostics='pattern', kind='Pattern', - children=[ - Child('Identifier', kind='Token', - token_choices=[ - 'IdentifierToken', - 'KeywordToken', - ]), - ]), - - # tuple-pattern -> '(' tuple-pattern-element-list ')' - Node('TuplePattern', name_for_diagnostics='tuple pattern', kind='Pattern', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Elements', kind='TuplePatternElementList', - collection_element_name='Element'), - Child('RightParen', kind='RightParenToken'), - ]), - - # wildcard-pattern -> '_' type-annotation? - Node('WildcardPattern', name_for_diagnostics='wildcard pattern', kind='Pattern', - children=[ - Child('Wildcard', kind='WildcardToken'), - Child('TypeAnnotation', kind='TypeAnnotation', - is_optional=True), - ]), - - # tuple-pattern-element -> identifier? ':' pattern ','? - Node('TuplePatternElement', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('LabelName', kind='IdentifierToken', name_for_diagnostics='label', - is_optional=True), - Child('LabelColon', kind='ColonToken', - is_optional=True), - Child('Pattern', kind='Pattern'), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # expr-pattern -> expr - Node('ExpressionPattern', name_for_diagnostics='pattern', kind='Pattern', - children=[ - Child('Expression', kind='Expr'), - ]), - - # tuple-pattern-element-list -> tuple-pattern-element - # tuple-pattern-element-list? - Node('TuplePatternElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='TuplePatternElement'), - - # value-binding-pattern -> 'let' pattern - # | 'var' pattern - # | 'inout' pattern - Node('ValueBindingPattern', name_for_diagnostics='value binding pattern', - kind='Pattern', - children=[ - Child('BindingKeyword', kind='KeywordToken', - token_choices=['KeywordToken|let', 'KeywordToken|var', - 'KeywordToken|inout']), - Child('ValuePattern', kind='Pattern'), - ]), -] diff --git a/gyb_syntax_support/StmtNodes.py b/gyb_syntax_support/StmtNodes.py deleted file mode 100644 index 15babb4fbf4..00000000000 --- a/gyb_syntax_support/StmtNodes.py +++ /dev/null @@ -1,251 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -STMT_NODES = [ - # labeled-stmt -> label ':' stmt - Node('LabeledStmt', name_for_diagnostics='labeled statement', kind='Stmt', - children=[ - Child('LabelName', kind='IdentifierToken', name_for_diagnostics='label name'), - Child('LabelColon', kind='ColonToken'), - Child('Statement', kind='Stmt'), - ]), - - # expr-stmt -> expression ';'? - Node('ExpressionStmt', name_for_diagnostics='expression', kind='Stmt', - children=[ - Child('Expression', kind='Expr'), - ]), - - # continue-stmt -> 'continue' label? ';'? - Node('ContinueStmt', name_for_diagnostics="'continue' statement", kind='Stmt', - children=[ - Child('ContinueKeyword', kind='KeywordToken', token_choices=['KeywordToken|continue']), - Child('Label', kind='IdentifierToken', name_for_diagnostics='label', - is_optional=True), - ]), - - # while-stmt -> label? ':'? 'while' condition-list code-block ';'? - Node('WhileStmt', name_for_diagnostics="'while' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('WhileKeyword', kind='KeywordToken', token_choices=['KeywordToken|while']), - Child('Conditions', kind='ConditionElementList', - collection_element_name='Condition'), - Child('Body', kind='CodeBlock'), - ]), - - # defer-stmt -> 'defer' code-block ';'? - Node('DeferStmt', name_for_diagnostics="'defer' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('DeferKeyword', kind='KeywordToken', token_choices=['KeywordToken|defer']), - Child('Body', kind='CodeBlock'), - ]), - - # repeat-while-stmt -> label? ':'? 'repeat' code-block 'while' expr ';'? - Node('RepeatWhileStmt', name_for_diagnostics="'repeat' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('RepeatKeyword', kind='KeywordToken', token_choices=['KeywordToken|repeat']), - Child('Body', kind='CodeBlock', name_for_diagnostics='body'), - Child('WhileKeyword', kind='KeywordToken', token_choices=['KeywordToken|while']), - Child('Condition', kind='Expr', name_for_diagnostics='condition'), - ]), - - # guard-stmt -> 'guard' condition-list 'else' code-block ';'? - Node('GuardStmt', name_for_diagnostics="'guard' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('GuardKeyword', kind='KeywordToken', token_choices=['KeywordToken|guard']), - Child('Conditions', kind='ConditionElementList', name_for_diagnostics='condition', - collection_element_name='Condition'), - Child('ElseKeyword', kind='KeywordToken', token_choices=['KeywordToken|else']), - Child('Body', kind='CodeBlock', name_for_diagnostics='body'), - ]), - - Node('WhereClause', name_for_diagnostics="'where' clause", kind='Syntax', - children=[ - Child('WhereKeyword', kind='KeywordToken', token_choices=['KeywordToken|where']), - Child('GuardResult', kind='Expr'), - ]), - - # for-in-stmt -> label? ':'? - # 'for' 'try'? 'await'? 'case'? pattern 'in' expr 'where'? - # expr code-block ';'? - Node('ForInStmt', name_for_diagnostics="'for' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('ForKeyword', kind='KeywordToken', token_choices=['KeywordToken|for']), - Child('TryKeyword', kind='TryToken', - is_optional=True), - Child('AwaitKeyword', kind='IdentifierToken', - classification='Keyword', - token_choices=['KeywordToken|await'], is_optional=True), - Child('CaseKeyword', kind='CaseToken', - is_optional=True), - Child('Pattern', kind='Pattern'), - Child('TypeAnnotation', kind='TypeAnnotation', - is_optional=True), - Child('InKeyword', kind='KeywordToken', token_choices=['KeywordToken|in']), - Child('SequenceExpr', kind='Expr'), - Child('WhereClause', kind='WhereClause', - is_optional=True), - Child('Body', kind='CodeBlock', name_for_diagnostics='body'), - ]), - - # catch-clause-list -> catch-clause catch-clause-list? - Node('CatchClauseList', name_for_diagnostics="'catch' clause", - kind='SyntaxCollection', element='CatchClause'), - - # do-stmt -> identifier? ':'? 'do' code-block catch-clause-list ';'? - Node('DoStmt', name_for_diagnostics="'do' statement", kind='Stmt', - traits=['WithCodeBlock'], - children=[ - Child('DoKeyword', kind='KeywordToken', token_choices=['KeywordToken|do']), - Child('Body', kind='CodeBlock', name_for_diagnostics='body',), - Child('CatchClauses', kind='CatchClauseList', - collection_element_name='CatchClause', is_optional=True), - ]), - - # return-stmt -> 'return' expr? ';'? - Node('ReturnStmt', name_for_diagnostics="'return' statement", kind='Stmt', - children=[ - Child('ReturnKeyword', kind='KeywordToken', token_choices=['KeywordToken|return']), - Child('Expression', kind='Expr', - is_optional=True), - ]), - - # yield-stmt -> 'yield' '('? expr-list? ')'? - Node('YieldStmt', name_for_diagnostics="'yield' statement", kind='Stmt', - children=[ - Child('YieldKeyword', kind='KeywordToken', token_choices=['KeywordToken|yield']), - Child('Yields', kind='Syntax', - node_choices=[ - Child('YieldList', kind='YieldList'), - Child('SimpleYield', kind='Expr'), - ]), - ]), - - Node('YieldList', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('ElementList', kind='YieldExprList', - collection_element_name='Element'), - Child('RightParen', kind='RightParenToken'), - ]), - - # fallthrough-stmt -> 'fallthrough' ';'? - Node('FallthroughStmt', name_for_diagnostics="'fallthrough' statement", kind='Stmt', - children=[ - Child('FallthroughKeyword', kind='KeywordToken', token_choices=['KeywordToken|fallthrough']), - ]), - - # break-stmt -> 'break' identifier? ';'? - Node('BreakStmt', name_for_diagnostics="'break' statement", kind='Stmt', - children=[ - Child('BreakKeyword', kind='KeywordToken', token_choices=['KeywordToken|break'], requires_trailing_space=False), - Child('Label', kind='IdentifierToken', name_for_diagnostics='label', - is_optional=True), - ]), - - # case-item-list -> case-item case-item-list? - Node('CaseItemList', name_for_diagnostics=None, kind='SyntaxCollection', - element='CaseItem'), - - # catch-item-list -> catch-item catch-item-list? - Node('CatchItemList', name_for_diagnostics=None, kind='SyntaxCollection', - element='CatchItem'), - - # condition -> expression - # | availability-condition - # | case-condition - # | optional-binding-condition - Node('ConditionElement', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Condition', kind='Syntax', - node_choices=[ - Child('Expression', kind='Expr'), - Child('Availability', kind='AvailabilityCondition'), - Child('MatchingPattern', - kind='MatchingPatternCondition'), - Child('OptionalBinding', - kind='OptionalBindingCondition'), - ]), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # availability-condition -> '#available' '(' availability-spec ')' - Node('AvailabilityCondition', name_for_diagnostics="availability condition", - kind='Syntax', - children=[ - Child('AvailabilityKeyword', kind='Token', token_choices=['PoundAvailableToken', 'PoundUnavailableToken']), - Child('LeftParen', kind='LeftParenToken'), - Child('AvailabilitySpec', kind='AvailabilitySpecList', - collection_element_name='AvailabilityArgument'), - Child('RightParen', kind='RightParenToken'), - ]), - Node('MatchingPatternCondition', kind='Syntax', - name_for_diagnostics='pattern matching', - children=[ - Child('CaseKeyword', kind='KeywordToken', token_choices=['KeywordToken|case']), - Child('Pattern', kind='Pattern'), - Child('TypeAnnotation', kind='TypeAnnotation', - is_optional=True), - Child('Initializer', kind='InitializerClause'), - ]), - Node('OptionalBindingCondition', name_for_diagnostics="optional binding", - kind='Syntax', - children=[ - Child('BindingKeyword', kind='KeywordToken', - token_choices=['KeywordToken|let', 'KeywordToken|var', - 'KeywordToken|inout']), - Child('Pattern', kind='Pattern'), - Child('TypeAnnotation', kind='TypeAnnotation', - is_optional=True), - Child('Initializer', kind='InitializerClause', - is_optional=True), - ]), - - # condition-list -> condition - # | condition ','? condition-list - Node('ConditionElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='ConditionElement'), - - # throw-stmt -> 'throw' expr ';'? - Node('ThrowStmt', name_for_diagnostics="'throw' statement", kind='Stmt', - children=[ - Child('ThrowKeyword', kind='KeywordToken', token_choices=['KeywordToken|throw']), - Child('Expression', kind='Expr'), - ]), - - # forget-stmt -> 'forget' expr ';'? - Node('ForgetStmt', name_for_diagnostics="'forget' statement", kind='Stmt', - children=[ - Child('ForgetKeyword', kind='KeywordToken', token_choices=['KeywordToken|_forget']), - Child('Expression', kind='Expr'), - ]), - - # catch-item -> pattern? where-clause? ','? - Node('CatchItem', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('Pattern', kind='Pattern', is_optional=True), - Child('WhereClause', kind='WhereClause', - is_optional=True), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # catch-clause 'catch' case-item-list? code-block - Node('CatchClause', name_for_diagnostics="'catch' clause", kind='Syntax', - traits=['WithCodeBlock'], - parser_function='parseCatchClause', - children=[ - Child('CatchKeyword', kind='KeywordToken', token_choices=['KeywordToken|catch']), - Child('CatchItems', kind='CatchItemList', - collection_element_name='CatchItem', is_optional=True), - Child('Body', kind='CodeBlock'), - ]), -] diff --git a/gyb_syntax_support/Token.py b/gyb_syntax_support/Token.py deleted file mode 100644 index 99aa7616c0a..00000000000 --- a/gyb_syntax_support/Token.py +++ /dev/null @@ -1,273 +0,0 @@ -from .Classification import classification_by_name -from .Utils import error # noqa: I201 -from .kinds import lowercase_first_word # noqa: I201 - - -class Token(object): - """ - Represents the specification for a Token in the TokenSyntax file. - """ - - def __init__(self, name, kind, name_for_diagnostics, - unprefixed_kind=None, text=None, classification='None', - is_keyword=False, requires_leading_space=False, - requires_trailing_space=False, associated_value_class=None): - self.name = name - self.kind = kind - if unprefixed_kind is None: - self.unprefixed_kind = kind - else: - self.unprefixed_kind = unprefixed_kind - self.name_for_diagnostics = name_for_diagnostics - self.text = text - self.classification = classification_by_name(classification) - self.is_keyword = is_keyword - self.requires_leading_space = requires_leading_space - self.requires_trailing_space = requires_trailing_space - self.associated_value_class = associated_value_class - - def swift_kind(self): - name = lowercase_first_word(self.name) - if self.is_keyword: - return name + 'Keyword' - return name - - -class Keyword(Token): - """ - Represents a keyword token. - """ - - def __init__(self, name, text, classification='Keyword', - requires_leading_space=False, requires_trailing_space=True): - Token.__init__(self, - name=name, - kind='kw_' + text, - name_for_diagnostics=text, - unprefixed_kind=text, text=text, - classification=classification, is_keyword=True, - requires_leading_space=requires_leading_space, - requires_trailing_space=requires_trailing_space) - - def macro_name(self): - return "KEYWORD" - - -class SwiftKeyword(Keyword): - def macro_name(self): - return "SWIFT_KEYWORD" - - -class DeclKeyword(SwiftKeyword): - def macro_name(self): - return "DECL_KEYWORD" - - -class StmtKeyword(SwiftKeyword): - def macro_name(self): - return "STMT_KEYWORD" - - -class ExprKeyword(SwiftKeyword): - def macro_name(self): - return "EXPR_KEYWORD" - - -class PatternKeyword(SwiftKeyword): - def macro_name(self): - return "PAT_KEYWORD" - - -class SilKeyword(Keyword): - def macro_name(self): - return "SIL_KEYWORD" - - -class PoundKeyword(Token): - def __init__(self, name, kind, text, name_for_diagnostics=None, - classification='Keyword'): - if name_for_diagnostics is None: - name_for_diagnostics = text - Token.__init__(self, - name=name, - kind='pound_' + kind, - name_for_diagnostics=name_for_diagnostics, - unprefixed_kind=kind, text=text, - classification=classification, is_keyword=True, - requires_trailing_space=True) - - def macro_name(self): - return "POUND_KEYWORD" - - -class PoundObjectLiteral(PoundKeyword): - def __init__(self, name, kind, text, name_for_diagnostics, - protocol, classification='ObjectLiteral'): - PoundKeyword.__init__( - self, - name=name, - kind=kind, - text=text, - name_for_diagnostics=name_for_diagnostics, - classification=classification - ) - self.description = name_for_diagnostics - self.protocol = protocol - - def macro_name(self): - return "POUND_OBJECT_LITERAL" - - -class PoundConfig(PoundKeyword): - def macro_name(self): - return "POUND_CONFIG" - - -class PoundDirectiveKeyword(PoundKeyword): - def __init__(self, name, kind, text, - classification='PoundDirectiveKeyword'): - PoundKeyword.__init__( - self, - name=name, - kind=kind, - text=text, - classification=classification - ) - - def macro_name(self): - return "POUND_DIRECTIVE_KEYWORD" - - -class PoundConditionalDirectiveKeyword(PoundDirectiveKeyword): - def __init__(self, name, kind, text, - classification='PoundDirectiveKeyword'): - PoundKeyword.__init__( - self, - name=name, - kind=kind, - text=text, - classification=classification - ) - - def macro_name(self): - return "POUND_COND_DIRECTIVE_KEYWORD" - - -class Punctuator(Token): - def __init__(self, name, kind, text, classification='None', - requires_leading_space=False, requires_trailing_space=False): - Token.__init__( - self, - name=name, - kind=kind, - name_for_diagnostics=text, - unprefixed_kind=None, - text=text, - classification=classification, - is_keyword=False, - requires_leading_space=requires_leading_space, - requires_trailing_space=requires_trailing_space - ) - - def macro_name(self): - return "PUNCTUATOR" - - -class Literal(Token): - def macro_name(self): - return "LITERAL" - - -class Misc(Token): - def macro_name(self): - return "MISC" - - -SYNTAX_TOKENS = [ - # Pattern keywords - Misc('Wildcard', '_', text='_', name_for_diagnostics='wildcard'), - - # Punctuators - Punctuator('LeftParen', 'l_paren', text='('), - Punctuator('RightParen', 'r_paren', text=')'), - Punctuator('LeftBrace', 'l_brace', text='{', requires_leading_space=True), - Punctuator('RightBrace', 'r_brace', text='}'), - Punctuator('LeftSquareBracket', 'l_square', text='['), - Punctuator('RightSquareBracket', 'r_square', text=']'), - Punctuator('LeftAngle', 'l_angle', text='<'), - Punctuator('RightAngle', 'r_angle', text='>'), - - Punctuator('Period', 'period', text='.'), - Punctuator('Comma', 'comma', text=',', requires_trailing_space=True), - Punctuator('Ellipsis', 'ellipsis', text='...'), - Punctuator('Colon', 'colon', text=':', requires_trailing_space=True), - Punctuator('Semicolon', 'semi', text=';'), - Punctuator('Equal', 'equal', text='=', requires_leading_space=True, - requires_trailing_space=True), - Punctuator('AtSign', 'at_sign', text='@', classification='Attribute'), - Punctuator('Pound', 'pound', text='#'), - - Punctuator('PrefixAmpersand', 'amp_prefix', text='&'), - Punctuator('Arrow', 'arrow', text='->', requires_leading_space=True, - requires_trailing_space=True), - - Punctuator('Backtick', 'backtick', text='`'), - - Punctuator('Backslash', 'backslash', text='\\\\'), - - Punctuator('ExclamationMark', 'exclaim_postfix', text='!'), - - Punctuator('PostfixQuestionMark', 'question_postfix', text='?'), - Punctuator('InfixQuestionMark', 'question_infix', text='?'), - - Punctuator('StringQuote', 'string_quote', text='\\\"', - classification='StringLiteral'), - Punctuator('SingleQuote', 'single_quote', text='\\\'', - classification='StringLiteral'), - Punctuator('MultilineStringQuote', 'multiline_string_quote', - text='\\\"\\\"\\\"', classification='StringLiteral'), - - # Keywords prefixed with a '#'. - PoundDirectiveKeyword('PoundSourceLocation', 'sourceLocation', - text='#sourceLocation'), - - PoundConditionalDirectiveKeyword('PoundIf', 'if', text='#if'), - PoundConditionalDirectiveKeyword('PoundElse', 'else', text='#else'), - PoundConditionalDirectiveKeyword('PoundElseif', 'elseif', - text='#elseif'), - PoundConditionalDirectiveKeyword('PoundEndif', 'endif', - text='#endif'), - - PoundConfig('PoundAvailable', 'available', text='#available'), - PoundConfig('PoundUnavailable', 'unavailable', text='#unavailable'), - - Literal('IntegerLiteral', 'integer_literal', name_for_diagnostics='integer literal', - classification='IntegerLiteral'), - Literal('FloatingLiteral', 'floating_literal', - name_for_diagnostics='floating literal', classification='FloatingLiteral'), - Literal('RegexLiteral', 'regex_literal', name_for_diagnostics='regex literal'), - - Misc('Unknown', 'unknown', name_for_diagnostics='token'), - Misc('Identifier', 'identifier', name_for_diagnostics='identifier', - classification='Identifier'), - Misc('BinaryOperator', 'oper_binary', - name_for_diagnostics='binary operator', - classification='OperatorIdentifier', - requires_leading_space=True, requires_trailing_space=True), - Misc('PostfixOperator', 'oper_postfix', name_for_diagnostics='postfix operator', - classification='OperatorIdentifier'), - Misc('PrefixOperator', 'oper_prefix', name_for_diagnostics='prefix operator', - classification='OperatorIdentifier'), - Misc('DollarIdentifier', 'dollarident', name_for_diagnostics='dollar identifier', - classification='DollarIdentifier'), - - Misc('Keyword', 'keyword', name_for_diagnostics='keyword', - classification='Keyword', associated_value_class='Keyword'), - Misc('RawStringDelimiter', 'raw_string_delimiter', - name_for_diagnostics='raw string delimiter'), - Misc('StringSegment', 'string_segment', name_for_diagnostics='string segment', - classification='StringLiteral'), -] - -SYNTAX_TOKEN_MAP = {token.name + 'Token': token for token in SYNTAX_TOKENS} - diff --git a/gyb_syntax_support/Traits.py b/gyb_syntax_support/Traits.py deleted file mode 100644 index 536f85ca600..00000000000 --- a/gyb_syntax_support/Traits.py +++ /dev/null @@ -1,83 +0,0 @@ -from .Child import Child - - -class Trait(object): - def __init__(self, trait_name, description=None, children=None): - self.trait_name = trait_name - self.children = children - self.description = description - - -TRAITS = [ - Trait('Attributed', - children=[ - Child('Attributes', kind='AttributeList', is_optional=True), - ]), - - Trait('DeclGroup', - children=[ - Child('Attributes', kind='AttributeList', is_optional=True), - Child('Modifiers', kind='ModifierList', is_optional=True), - Child('Members', kind='MemberDeclBlock'), - ]), - - Trait('Braced', - children=[ - Child('LeftBrace', kind='LeftBraceToken'), - Child('RightBrace', kind='RightBraceToken'), - ]), - - Trait('IdentifiedDecl', - children=[ - Child('Identifier', kind='IdentifierToken'), - ]), - - Trait('WithCodeBlock', - children=[ - Child('Body', kind='CodeBlock'), - ]), - - Trait('Parenthesized', - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('RightParen', kind='RightParenToken'), - ]), - - Trait('FreestandingMacroExpansion', - children=[ - Child('PoundToken', kind='PoundToken'), - Child('Macro', kind='IdentifierToken'), - Child('GenericArguments', kind='GenericArgumentClause', - is_optional=True), - Child('LeftParen', kind='LeftParenToken', - is_optional=True), - Child('ArgumentList', kind='TupleExprElementList', - collection_element_name='Argument'), - Child('RightParen', kind='RightParenToken', - is_optional=True), - Child('TrailingClosure', kind='ClosureExpr', - is_optional=True), - Child('AdditionalTrailingClosures', - kind='MultipleTrailingClosureElementList', - collection_element_name='AdditionalTrailingClosure', - is_optional=True), - ]), - - Trait('WithTrailingComma', - children=[ - Child('TrailingComma', kind='CommaToken', is_optional=True), - ]), - - Trait('WithStatements', - children=[ - Child('Statements', kind='CodeBlockItemList'), - ]), - Trait('EffectSpecifiers', - children=[ - Child('UnexpectedBeforeAsyncSpecifier', kind='UnexpectedNodes', is_optional=True), - Child('AsyncSpecifier', kind='KeywordToken', is_optional=True), - Child('UnexpectedBetweenAsyncSpecifierAndThrowsSpecifier', kind='UnexpectedNodes', is_optional=True), - Child('ThrowsSpecifier', kind='KeywordToken', is_optional=True), - Child('UnexpectedAfterThrowsSpecifier', kind='UnexpectedNodes', is_optional=True), - ]), -] diff --git a/gyb_syntax_support/Trivia.py b/gyb_syntax_support/Trivia.py deleted file mode 100644 index 77e655c74c6..00000000000 --- a/gyb_syntax_support/Trivia.py +++ /dev/null @@ -1,67 +0,0 @@ -from .Utils import error -from .kinds import lowercase_first_word # noqa: I201 - - -class Trivia(object): - def __init__(self, name, comment, characters=[], - swift_characters=[], is_new_line=False, is_comment=False): - self.name = name - self.comment = comment - self.characters = tuple(characters) - self.lower_name = lowercase_first_word(name) - if name == "Backslash": - self.plural_name = "backslashes" - else: - self.plural_name = f"{lowercase_first_word(name)}s" - self.is_new_line = is_new_line - self.is_comment = is_comment - - # Swift sometimes doesn't support escaped characters like \f or \v; - # we should allow specifying alternatives explicitly. - if swift_characters: - self.swift_characters = tuple(swift_characters) - else: - self.swift_characters = characters - assert len(self.swift_characters) == len(self.characters) - - def characters_len(self): - return len(self.characters) - - def is_collection(self): - return self.characters_len() > 0 - - -TRIVIAS = [ - Trivia('Space', 'A space \' \' character.', characters=[' ']), - Trivia('Tab', 'A tab \'\\t\' character.', characters=['\\t']), - # Swift don't support vertical tab '\v' so we use the raw unicode - Trivia('VerticalTab', 'A vertical tab \'\\v\' character.', - characters=['\\u{b}'], swift_characters=['\\u{2B7F}']), - # Swift don't support form feed '\f' so we use the raw unicode - Trivia('Formfeed', 'A form-feed \'f\' character.', characters=['\\u{c}'], - swift_characters=['\\u{240C}']), - Trivia('Newline', 'A newline \'\\n\' character.', characters=['\\n'], - is_new_line=True), - Trivia('CarriageReturn', 'A newline \'\\r\' character.', - characters=['\\r'], is_new_line=True), - Trivia('CarriageReturnLineFeed', - 'A newline consists of contiguous \'\\r\' and \'\\n\' characters.', - characters=['\\r', '\\n'], is_new_line=True), - Trivia('LineComment', 'A developer line comment, starting with \'//\'', - is_comment=True), - Trivia('BlockComment', - 'A developer block comment, starting with \'/*\' and ending with' - ' \'*/\'.', - is_comment=True), - Trivia('DocLineComment', - 'A documentation line comment, starting with \'///\'.', - is_comment=True), - Trivia('DocBlockComment', - 'A documentation block comment, starting with \'/**\' and ending ' - 'with \'*/\'.', - is_comment=True), - Trivia('Backslash', 'A backslash that is at the end of a line in a multi-line string literal to escape the newline.', characters=['\\\\']), - Trivia('Pound', 'A \'#\' that is at the end of a line in a multi-line string literal to escape the newline.', characters=['#']), - Trivia('UnexpectedText', 'Any skipped unexpected text.'), - Trivia('Shebang', 'A script command, starting with \'#!\'.'), -] diff --git a/gyb_syntax_support/TypeNodes.py b/gyb_syntax_support/TypeNodes.py deleted file mode 100644 index 5b27b33b05c..00000000000 --- a/gyb_syntax_support/TypeNodes.py +++ /dev/null @@ -1,229 +0,0 @@ -from .Child import Child -from .Node import Node # noqa: I201 - -TYPE_NODES = [ - # simple-type-identifier -> identifier generic-argument-clause? - Node('SimpleTypeIdentifier', name_for_diagnostics='type', kind='Type', - children=[ - Child('Name', kind='Token', classification='TypeIdentifier', - token_choices=[ - 'IdentifierToken', - 'KeywordToken', - 'WildcardToken', - ]), - Child('GenericArgumentClause', kind='GenericArgumentClause', - is_optional=True), - ]), - - # member-type-identifier -> type '.' identifier generic-argument-clause? - Node('MemberTypeIdentifier', name_for_diagnostics='member type', kind='Type', - children=[ - Child('BaseType', kind='Type', name_for_diagnostics='base type'), - Child('Period', kind='PeriodToken'), - Child('Name', kind='Token', name_for_diagnostics='name', classification='TypeIdentifier', - token_choices=[ - 'IdentifierToken', - 'KeywordToken', - ]), - Child('GenericArgumentClause', kind='GenericArgumentClause', - is_optional=True), - ]), - - # class-restriction-type -> 'class' - Node('ClassRestrictionType', name_for_diagnostics=None, kind='Type', - children=[ - Child('ClassKeyword', kind='KeywordToken', token_choices=['KeywordToken|class']), - ]), - # array-type -> '[' type ']' - Node('ArrayType', name_for_diagnostics='array type', kind='Type', - children=[ - Child('LeftSquareBracket', kind='LeftSquareBracketToken'), - Child('ElementType', kind='Type'), - Child('RightSquareBracket', kind='RightSquareBracketToken'), - ]), - - # dictionary-type -> '[' type ':' type ']' - Node('DictionaryType', name_for_diagnostics='dictionary type', kind='Type', - children=[ - Child('LeftSquareBracket', kind='LeftSquareBracketToken'), - Child('KeyType', kind='Type', name_for_diagnostics='key type',), - Child('Colon', kind='ColonToken'), - Child('ValueType', kind='Type', name_for_diagnostics='value type'), - Child('RightSquareBracket', kind='RightSquareBracketToken'), - ]), - - # metatype-type -> type '.' 'Type' - # | type '.' 'Protocol - Node('MetatypeType', name_for_diagnostics='metatype', kind='Type', - children=[ - Child('BaseType', kind='Type', name_for_diagnostics='base type'), - Child('Period', kind='PeriodToken'), - Child('TypeOrProtocol', kind='KeywordToken', - token_choices=[ - 'KeywordToken|Type', - 'KeywordToken|Protocol', - ]), - ]), - - # optional-type -> type '?' - Node('OptionalType', name_for_diagnostics='optional type', kind='Type', - children=[ - Child('WrappedType', kind='Type'), - Child('QuestionMark', kind='PostfixQuestionMarkToken'), - ]), - - # constrained-sugar-type -> ('some'|'any') type - Node('ConstrainedSugarType', name_for_diagnostics='type', kind='Type', - children=[ - Child('SomeOrAnySpecifier', kind='KeywordToken', - token_choices=['KeywordToken|some', 'KeywordToken|any']), - Child('BaseType', kind='Type'), - ]), - - # implicitly-unwrapped-optional-type -> type '!' - Node('ImplicitlyUnwrappedOptionalType', - name_for_diagnostics='implicitly unwrapped optional type', kind='Type', - children=[ - Child('WrappedType', kind='Type'), - Child('ExclamationMark', kind='ExclamationMarkToken'), - ]), - - # composition-type-element -> type '&' - Node('CompositionTypeElement', name_for_diagnostics=None, kind='Syntax', - children=[ - Child('Type', kind='Type'), - Child('Ampersand', kind='Token', - is_optional=True), - ]), - - # composition-typeelement-list -> composition-type-element - # composition-type-element-list? - Node('CompositionTypeElementList', name_for_diagnostics=None, - kind='SyntaxCollection', - element='CompositionTypeElement'), - - # composition-type -> composition-type-element-list - Node('CompositionType', name_for_diagnostics='type composition', kind='Type', - children=[ - Child('Elements', kind='CompositionTypeElementList', - collection_element_name='Element'), - ]), - - # pack-expansion-type -> type '...' - Node('PackExpansionType', name_for_diagnostics='variadic expansion', kind='Type', - children=[ - Child('RepeatKeyword', kind='KeywordToken', token_choices=['KeywordToken|repeat']), - Child('PatternType', kind='Type') - ]), - - # pack-reference-type -> 'each' type - Node('PackReferenceType', name_for_diagnostics='pack reference', kind='Type', - children=[ - Child('EachKeyword', kind='KeyworkToken', - token_choices=['KeywordToken|each'], is_optional=False), - Child('PackType', kind='Type') - ]), - - # tuple-type-element -> identifier? ':'? type-annotation ','? - Node('TupleTypeElement', name_for_diagnostics=None, kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('InOut', kind='InoutToken', - is_optional=True), - Child('Name', kind='Token', name_for_diagnostics='name', - is_optional=True, - token_choices=[ - 'IdentifierToken', - 'WildcardToken' - ]), - Child('SecondName', kind='Token', name_for_diagnostics='internal name', - is_optional=True, - token_choices=[ - 'IdentifierToken', - 'WildcardToken' - ]), - Child('Colon', kind='ColonToken', - is_optional=True), - Child('Type', kind='Type'), - Child('Ellipsis', kind='EllipsisToken', - is_optional=True), - Child('Initializer', kind='InitializerClause', - is_optional=True), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # tuple-type-element-list -> tuple-type-element tuple-type-element-list? - Node('TupleTypeElementList', name_for_diagnostics=None, kind='SyntaxCollection', - element='TupleTypeElement'), - - # tuple-type -> '(' tuple-type-element-list ')' - Node('TupleType', name_for_diagnostics='tuple type', kind='Type', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Elements', kind='TupleTypeElementList', - collection_element_name='Element', is_indented=True), - Child('RightParen', kind='RightParenToken'), - ]), - - # throwing-specifier -> 'throws' | 'rethrows' - # function-type -> attribute-list '(' function-type-argument-list ')' - # type-effect-specifiers? return-clause - Node('FunctionType', name_for_diagnostics='function type', kind='Type', - traits=['Parenthesized'], - children=[ - Child('LeftParen', kind='LeftParenToken'), - Child('Arguments', kind='TupleTypeElementList', - collection_element_name='Argument', is_indented=True), - Child('RightParen', kind='RightParenToken'), - Child('EffectSpecifiers', kind='TypeEffectSpecifiers', - is_optional=True), - Child('Output', kind='ReturnClause'), - ]), - - # attributed-type -> type-specifier? attribute-list? type - # type-specifier -> 'inout' | 'borrowing' | 'consuming' | '__owned' | '__shared' - Node('AttributedType', name_for_diagnostics='type', kind='Type', - traits=['Attributed'], - children=[ - Child('Specifier', kind='Token', - token_choices=['KeywordToken|inout', 'KeywordToken|__shared', 'KeywordToken|__owned', 'KeywordToken|isolated', 'KeywordToken|_const', 'KeywordToken|borrowing', 'KeywordToken|consuming'], - is_optional=True), - Child('Attributes', kind='AttributeList', - collection_element_name='Attribute', is_optional=True), - Child('BaseType', kind='Type'), - ]), - - # generic-argument-list -> generic-argument generic-argument-list? - Node('GenericArgumentList', name_for_diagnostics=None, kind='SyntaxCollection', - element='GenericArgument'), - - # A generic argument. - # Dictionary - # ^~~~ ^~~~~~ - Node('GenericArgument', name_for_diagnostics='generic argument', kind='Syntax', - traits=['WithTrailingComma'], - children=[ - Child('ArgumentType', kind='Type'), - Child('TrailingComma', kind='CommaToken', - is_optional=True), - ]), - - # generic-argument-clause -> '<' generic-argument-list '>' - Node('GenericArgumentClause', name_for_diagnostics='generic argument clause', - kind='Syntax', - children=[ - Child('LeftAngleBracket', kind='LeftAngleToken'), - Child('Arguments', kind='GenericArgumentList', - collection_element_name='Argument'), - Child('RightAngleBracket', kind='RightAngleToken'), - ]), - - # named-opaque-return-type -> generic-argument-clause type - Node('NamedOpaqueReturnType', name_for_diagnostics='named opaque return type', kind='Type', - children=[ - Child('GenericParameters', kind='GenericParameterClause'), - Child('BaseType', kind='Type'), - ]), -] diff --git a/gyb_syntax_support/Utils.py b/gyb_syntax_support/Utils.py deleted file mode 100644 index 28efc571e00..00000000000 --- a/gyb_syntax_support/Utils.py +++ /dev/null @@ -1,6 +0,0 @@ -import sys - - -def error(msg): - print('error: ' + msg, file=sys.stderr) - sys.exit(-1) diff --git a/gyb_syntax_support/__init__.py b/gyb_syntax_support/__init__.py deleted file mode 100644 index 1d1c248054f..00000000000 --- a/gyb_syntax_support/__init__.py +++ /dev/null @@ -1,127 +0,0 @@ -import hashlib -import textwrap -from . import Classification # noqa: I201 -from . import Token -from .AttributeNodes import ATTRIBUTE_NODES # noqa: I201 -from .AvailabilityNodes import AVAILABILITY_NODES # noqa: I201 -from .CommonNodes import COMMON_NODES # noqa: I201 -from .DeclNodes import DECL_NODES # noqa: I201 -from .ExprNodes import EXPR_NODES # noqa: I201 -from .GenericNodes import GENERIC_NODES # noqa: I201 -from .PatternNodes import PATTERN_NODES # noqa: I201 -from .StmtNodes import STMT_NODES # noqa: I201 -from .Trivia import TRIVIAS # noqa: I201 -from .TypeNodes import TYPE_NODES # noqa: I201 -from .kinds import SYNTAX_BASE_KINDS # noqa: I201 - - -# Re-export global constants -SYNTAX_NODES = COMMON_NODES + EXPR_NODES + DECL_NODES + ATTRIBUTE_NODES + \ - STMT_NODES + GENERIC_NODES + TYPE_NODES + PATTERN_NODES + \ - AVAILABILITY_NODES -NON_BASE_SYNTAX_NODES = [node for node in SYNTAX_NODES if not node.is_base()] -SYNTAX_TOKENS = Token.SYNTAX_TOKENS -SYNTAX_TOKEN_MAP = Token.SYNTAX_TOKEN_MAP -SYNTAX_CLASSIFICATIONS = Classification.SYNTAX_CLASSIFICATIONS - - -def make_missing_child(child): - """ - Generates a C++ call to make the raw syntax for a given Child object. - """ - if child.is_token(): - token = child.main_token() - tok_kind = token.kind if token else "unknown" - tok_text = token.text if token else "" - return \ - 'RawSyntax::missing(tok::%s, "%s", Arena)' % \ - (tok_kind, tok_text) - else: - missing_kind = "Unknown" if child.syntax_kind == "Syntax" \ - else child.syntax_kind - if child.node_choices: - return make_missing_child(child.node_choices[0]) - return 'RawSyntax::missing(SyntaxKind::%s, Arena)' % missing_kind - - -def make_missing_swift_child(child): - """ - Generates a Swift call to make the raw syntax for a given Child object. - """ - if child.is_token(): - token = child.main_token() - tok_kind = token.swift_kind() if token else "unknown" - if token and token.associated_value_class: - if len(child.token_choices) >= 1 and child.token_choices[0][1] is not None: - text_choice = child.token_choices[0][1] - else: - assert False, f"Can only create missing child if text is known (while creating {child.name} of type {child.syntax_kind})" - - if text_choice == "init": - text_choice = "`init`" - tok_kind += f'(.{text_choice})' - elif not token or not token.text: - tok_kind += '("")' - return f'RawSyntax.makeMissingToken(kind: TokenKind.{tok_kind}, ' + \ - 'arena: arena)' - else: - if child.syntax_kind == "Syntax": - missing_kind = "missing" - elif child.syntax_kind in SYNTAX_BASE_KINDS: - missing_kind = f"missing{child.syntax_kind}" - else: - missing_kind = child.swift_syntax_kind - return f'RawSyntax.makeEmptyLayout(kind: SyntaxKind.{missing_kind}, ' + \ - 'arena: arena)' - - -def create_node_map(): - """ - Creates a lookup table to find nodes by their kind. - """ - return {node.syntax_kind: node for node in SYNTAX_NODES} - - -def is_visitable(node): - return not node.is_base() - - -def dedented_lines(description): - """ - Each line of the provided string with leading whitespace stripped. - """ - if not description: - return [] - return textwrap.dedent(description).split('\n') - - -def calculate_node_hash(): - digest = hashlib.sha1() - - def _digest_syntax_node(node): - # Hash into the syntax name - digest.update(node.name.encode("utf-8")) - for child in node.children: - # Hash into the expected child syntax - digest.update(child.syntax_kind.encode("utf-8")) - # Hash into the child name - digest.update(child.name.encode("utf-8")) - # Hash into whether the child is optional - digest.update(str(child.is_optional).encode("utf-8")) - - def _digest_syntax_token(token): - # Hash into the token name - digest.update(token.name.encode("utf-8")) - - def _digest_trivia(trivia): - digest.update(trivia.name.encode("utf-8")) - digest.update(str(trivia.characters).encode("utf-8")) - - for node in SYNTAX_NODES: - _digest_syntax_node(node) - for token in SYNTAX_TOKENS: - _digest_syntax_token(token) - for trivia in TRIVIAS: - _digest_trivia(trivia) - - return digest.hexdigest() diff --git a/gyb_syntax_support/kinds.py b/gyb_syntax_support/kinds.py deleted file mode 100644 index edbf34da0a2..00000000000 --- a/gyb_syntax_support/kinds.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -All the known base syntax kinds. These will all be considered non-final classes -and other types will be allowed to inherit from them. -""" -SYNTAX_BASE_KINDS = ['Decl', 'Expr', 'Pattern', 'Stmt', - 'Syntax', 'SyntaxCollection', 'Type'] - - -def kind_to_type(kind): - """ - Converts a SyntaxKind to a type name, checking to see if the kind is - Syntax or SyntaxCollection first. - A type name is the same as the SyntaxKind name with the suffix "Syntax" - added. - """ - if kind in ["Syntax", "SyntaxCollection"]: - return kind - if kind.endswith("Token"): - return "TokenSyntax" - return kind + "Syntax" - - -def lowercase_first_word(name): - """ - Lowercases the first word in the provided camelCase or PascalCase string. - EOF -> eof - IfKeyword -> ifKeyword - EOFToken -> eofToken - """ - word_index = 0 - threshold_index = 1 - for c in name: - if c.islower(): - if word_index > threshold_index: - word_index -= 1 - break - word_index += 1 - if word_index == 0: - return name - return name[:word_index].lower() + name[word_index:]