Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Support parsing @_package attribute #1233

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CodeGeneration/Sources/SyntaxSupport/KeywordSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("_opaqueReturnTypeOf"),
KeywordSpec("_optimize"),
KeywordSpec("_originallyDefinedIn"),
KeywordSpec("_package"),
KeywordSpec("_PackageDescription"),
KeywordSpec("_private"),
KeywordSpec("_projectedValueProperty"),
Expand Down Expand Up @@ -100,6 +101,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("backDeployed"),
KeywordSpec("before"),
KeywordSpec("block"),
KeywordSpec("branch"),
KeywordSpec("break", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("case", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("catch", isLexerClassified: true, requiresLeadingSpace: true),
Expand All @@ -122,6 +124,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("else", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("enum", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("escaping"),
KeywordSpec("exact"),
KeywordSpec("exclusivity"),
KeywordSpec("exported"),
KeywordSpec("extension", isLexerClassified: true, requiresTrailingSpace: true),
Expand All @@ -132,10 +135,12 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("final"),
KeywordSpec("for", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("forward"),
KeywordSpec("from"),
KeywordSpec("func", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("get"),
KeywordSpec("guard", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("higherThan"),
KeywordSpec("id"),
KeywordSpec("if", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("import", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("in", isLexerClassified: true, requiresLeadingSpace: true, requiresTrailingSpace: true),
Expand Down Expand Up @@ -177,10 +182,12 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("optional"),
KeywordSpec("override"),
KeywordSpec("package"),
KeywordSpec("path"),
KeywordSpec("postfix"),
KeywordSpec("precedencegroup", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("prefix"),
KeywordSpec("private", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("product"),
KeywordSpec("Protocol"),
KeywordSpec("protocol", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("public", isLexerClassified: true, requiresTrailingSpace: true),
Expand All @@ -191,6 +198,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("rethrows", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("return", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("reverse"),
KeywordSpec("revision"),
KeywordSpec("right"),
KeywordSpec("safe"),
KeywordSpec("self", isLexerClassified: true),
Expand Down Expand Up @@ -221,6 +229,7 @@ public let KEYWORDS: [KeywordSpec] = [
KeywordSpec("unsafe"),
KeywordSpec("unsafeAddress"),
KeywordSpec("unsafeMutableAddress"),
KeywordSpec("url"),
KeywordSpec("var", isLexerClassified: true, requiresTrailingSpace: true),
KeywordSpec("visibility"),
KeywordSpec("weak"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(name: "EffectsArguments",
kind: .node(kind: "EffectsArguments")),
Child(name: "DocumentationArguments",
kind: .node(kind: "DocumentationAttributeArguments"))
kind: .node(kind: "DocumentationAttributeArguments")),
Child(name: "PackageAttributeArguments",
kind: .node(kind: "PackageAttributeArguments"))
]),
description: "The arguments of the attribute. In case the attribute takes multiple arguments, they are gather in the appropriate takes first.",
isOptional: true),
Expand Down Expand Up @@ -193,6 +195,159 @@ public let ATTRIBUTE_NODES: [Node] = [
isOptional: true)
]),

Node(name: "PackageAttributeArguments",
nameForDiagnostics: "@_package arguments",
description: "The arguments for the `@_package` attribute imitating `PackageDescription`",
kind: "Syntax",
children: [
Child(name: "Description",
kind: .nodeChoices(choices: [
Child(name: "FileSystem",
kind: .node(kind: "FileSystemPackageDescription")),
Child(name: "SourceControl",
kind: .node(kind: "SourceControlPackageDescription")),
Child(name: "Registry",
kind: .node(kind: "RegistryPackageDescription"))
])),
Child(name: "Comma",
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
description: "The comma between the package description and product, if it exists",
isOptional: true),
Child(name: "Product",
kind: .node(kind: "PackageProduct"),
description: "Explicit product declaration of package.",
isOptional: true)
]),

Node(name: "PackageProduct",
nameForDiagnostics: "package product",
description: "Explicit package product declaration",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "product")]),
description: "The product label"),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
Child(name: "Name",
kind: .node(kind: "StringLiteralExpr"),
description: "The exact product name from package")
]),

Node(name: "FileSystemPackageDescription",
nameForDiagnostics: "local package description",
description: "The description of a local package",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "path")]),
description: "The path label"),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
Child(name: "Path",
kind: .node(kind: "StringLiteralExpr"),
description: "The package path")
]),

Node(name: "SourceControlPackageDescription",
nameForDiagnostics: "remote package description (source control)",
description: "The description of a remote package using source control",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "url")]),
description: "The label of the package URL"),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
Child(name: "URL",
kind: .node(kind: "StringLiteralExpr"),
description: "The URL of package"),
Child(name: "Comma",
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
description: "The comma between the package URL and requirement"),
Child(name: "Requirement",
kind: .nodeChoices(choices: [
Child(name: "Labeled",
kind: .node(kind: "SourceControlRequirement")),
Child(name: "Range",
kind: .node(kind: "PackageVersionRange"))
]),
description: "Version requirement of the remote package")
]),

Node(name: "RegistryPackageDescription",
nameForDiagnostics: "remote package description",
description: "The description of a remote package",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "id")]),
description: "The label of the package ID"),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")])),
Child(name: "Identifier",
kind: .node(kind: "StringLiteralExpr"),
description: "The identifier of package"),
Child(name: "Comma",
kind: .token(choices: [.token(tokenKind: "CommaToken")]),
description: "The comma between the package identifier and requirement"),
Child(name: "Requirement",
kind: .nodeChoices(choices: [
Child(name: "Labeled",
kind: .node(kind: "RegistryRequirement")),
Child(name: "Range",
kind: .node(kind: "PackageVersionRange"))
]),
description: "Version requirement of the remote package")
]),

Node(name: "SourceControlRequirement",
nameForDiagnostics: "labeled package requirement (source control)",
description: "Labeled requirement of a source-control package",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "branch"), .keyword(text: "exact"), .keyword(text: "from"), .keyword(text: "revision")]),
description: "The requirement label",
isOptional: true),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
isOptional: true),
Child(name: "Requirement",
kind: .node(kind: "StringLiteralExpr"),
description: "Requirement description of remote package")
]),

Node(name: "RegistryRequirement",
nameForDiagnostics: "labeled package requirement (registry)",
description: "Labeled requirement of a registry package",
kind: "Syntax",
children: [
Child(name: "Label",
kind: .token(choices: [.keyword(text: "exact"), .keyword(text: "from")]),
description: "The requirement label",
isOptional: true),
Child(name: "Colon",
kind: .token(choices: [.token(tokenKind: "ColonToken")]),
isOptional: true),
Child(name: "Requirement",
kind: .node(kind: "StringLiteralExpr"),
description: "Requirement description of remote package")
]),

Node(name: "PackageVersionRange",
nameForDiagnostics: "range of package version",
description: "Open or closed range of dependent package versions",
kind: "Syntax",
children: [
Child(name: "FromVersion",
kind: .node(kind: "StringLiteralExpr")),
Child(name: "OperatorToken",
kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken")])),
Child(name: "ToVersion",
kind: .node(kind: "StringLiteralExpr"))
]),

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",
Expand Down
Loading