Skip to content

[5.9] Reduce SwiftParser’s public surface area #1673

New issue

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

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

Already on GitHub? Sign in to your account

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let isLexerClassifiedFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
/// Keywords are reserved unconditionally for use by Swift and may not
/// appear as identifiers in any position without being escaped. For example,
/// `class`, `func`, or `import`.
@_spi(Diagnostics) @_spi(Testing)
public var isLexerClassifiedKeyword: Bool
"""
) {
Expand Down
75 changes: 26 additions & 49 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ extension TokenConsumer {
}

extension Parser {
@_spi(RawSyntax)
public struct DeclAttributes {
public var attributes: RawAttributeListSyntax?
public var modifiers: RawModifierListSyntax?
struct DeclAttributes {
var attributes: RawAttributeListSyntax?
var modifiers: RawModifierListSyntax?

public init(attributes: RawAttributeListSyntax?, modifiers: RawModifierListSyntax?) {
init(attributes: RawAttributeListSyntax?, modifiers: RawModifierListSyntax?) {
self.attributes = attributes
self.modifiers = modifiers
}
Expand Down Expand Up @@ -169,8 +168,7 @@ extension Parser {
///
/// If `inMemberDeclList` is `true`, we know that the next item must be a
/// declaration and thus start with a keyword. This allows futher recovery.
@_spi(RawSyntax)
public mutating func parseDeclaration(inMemberDeclList: Bool = false) -> RawDeclSyntax {
mutating func parseDeclaration(inMemberDeclList: Bool = false) -> RawDeclSyntax {
switch self.at(anyIn: PoundDeclarationStart.self) {
case (.poundIfKeyword, _)?:
if self.withLookahead({ $0.consumeIfConfigOfAttributes() }) {
Expand Down Expand Up @@ -303,8 +301,7 @@ extension Parser {
/// import-declaration → attributes? 'import' import-kind? import-path
/// import-kind → 'typealias' | 'struct' | 'class' | 'enum' | 'protocol' | 'let' | 'var' | 'func'
/// import-path → identifier | identifier '.' import-path
@_spi(RawSyntax)
public mutating func parseImportDeclaration(
mutating func parseImportDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawImportDeclSyntax {
Expand All @@ -322,8 +319,7 @@ extension Parser {
)
}

@_spi(RawSyntax)
public mutating func parseImportKind() -> RawTokenSyntax? {
mutating func parseImportKind() -> RawTokenSyntax? {
enum ImportKind: TokenSpecSet {
case `typealias`
case `struct`
Expand Down Expand Up @@ -368,8 +364,7 @@ extension Parser {
return self.consume(ifAnyIn: ImportKind.self)
}

@_spi(RawSyntax)
public mutating func parseImportAccessPath() -> RawAccessPathSyntax {
mutating func parseImportAccessPath() -> RawAccessPathSyntax {
var elements = [RawAccessPathComponentSyntax]()
var keepGoing: RawTokenSyntax? = nil
var loopProgress = LoopProgressCondition()
Expand Down Expand Up @@ -398,8 +393,7 @@ extension Parser {
/// extension-body → '{' extension-members? '}'
/// extension-members → extension-member extension-members?
/// extension-member → declaration | compiler-control-statement
@_spi(RawSyntax)
public mutating func parseExtensionDeclaration(
mutating func parseExtensionDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawExtensionDeclSyntax {
Expand Down Expand Up @@ -451,8 +445,7 @@ extension Parser {
)
}

@_spi(RawSyntax)
public mutating func parseGenericParameters() -> RawGenericParameterClauseSyntax {
mutating func parseGenericParameters() -> RawGenericParameterClauseSyntax {
if let remainingTokens = remainingTokensIfMaximumNestingLevelReached() {
return RawGenericParameterClauseSyntax(
remainingTokens,
Expand Down Expand Up @@ -614,8 +607,7 @@ extension Parser {
}
}

@_spi(RawSyntax)
public mutating func parseGenericWhereClause() -> RawGenericWhereClauseSyntax {
mutating func parseGenericWhereClause() -> RawGenericWhereClauseSyntax {
let (unexpectedBeforeWhereKeyword, whereKeyword) = self.expect(.keyword(.where))

var elements = [RawGenericRequirementSyntax]()
Expand Down Expand Up @@ -779,8 +771,7 @@ extension Parser {
}

extension Parser {
@_spi(RawSyntax)
public mutating func parseMemberDeclListItem() -> RawMemberDeclListItemSyntax? {
mutating func parseMemberDeclListItem() -> RawMemberDeclListItemSyntax? {
if let remainingTokens = remainingTokensIfMaximumNestingLevelReached() {
let item = RawMemberDeclListItemSyntax(
remainingTokens,
Expand Down Expand Up @@ -819,8 +810,7 @@ extension Parser {
/// `introducer` is the `struct`, `class`, ... keyword that is the cause that the member decl block is being parsed.
/// If the left brace is missing, its indentation will be used to judge whether a following `}` was
/// indented to close this code block or a surrounding context. See `expectRightBrace`.
@_spi(RawSyntax)
public mutating func parseMemberDeclList(introducer: RawTokenSyntax? = nil) -> RawMemberDeclBlockSyntax {
mutating func parseMemberDeclList(introducer: RawTokenSyntax? = nil) -> RawMemberDeclBlockSyntax {
var elements = [RawMemberDeclListItemSyntax]()
let (unexpectedBeforeLBrace, lbrace) = self.expect(.leftBrace)
do {
Expand Down Expand Up @@ -878,8 +868,7 @@ extension Parser {
/// raw-value-style-enum-case → enum-case-name raw-value-assignment?
/// raw-value-assignment → = raw-value-literal
/// raw-value-literal → numeric-literal | static-string-literal | boolean-literal
@_spi(RawSyntax)
public mutating func parseEnumCaseDeclaration(
mutating func parseEnumCaseDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawEnumCaseDeclSyntax {
Expand Down Expand Up @@ -945,8 +934,7 @@ extension Parser {
/// =======
///
/// protocol-associated-type-declaration → attributes? access-level-modifier? 'associatedtype' typealias-name type-inheritance-clause? typealias-assignment? generic-where-clause?
@_spi(RawSyntax)
public mutating func parseAssociatedTypeDeclaration(
mutating func parseAssociatedTypeDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawAssociatedtypeDeclSyntax {
Expand Down Expand Up @@ -1036,8 +1024,7 @@ extension Parser {
/// initializer-head → attributes? declaration-modifiers? 'init' '?'
/// initializer-head → attributes? declaration-modifiers? 'init' '!'
/// initializer-body → code-block
@_spi(RawSyntax)
public mutating func parseInitializerDeclaration(
mutating func parseInitializerDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawInitializerDeclSyntax {
Expand Down Expand Up @@ -1092,8 +1079,7 @@ extension Parser {
/// =======
///
/// deinitializer-declaration → attributes? 'deinit' code-block
@_spi(RawSyntax)
public mutating func parseDeinitializerDeclaration(
mutating func parseDeinitializerDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawDeinitializerDeclSyntax {
Expand Down Expand Up @@ -1141,8 +1127,7 @@ extension Parser {
}

extension Parser {
@_spi(RawSyntax)
public mutating func parseFuncDeclaration(
mutating func parseFuncDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawFunctionDeclSyntax {
Expand Down Expand Up @@ -1192,8 +1177,7 @@ extension Parser {
)
}

@_spi(RawSyntax)
public mutating func parseFunctionSignature(allowOutput: Bool = true) -> RawFunctionSignatureSyntax {
mutating func parseFunctionSignature(allowOutput: Bool = true) -> RawFunctionSignatureSyntax {
let input = self.parseParameterClause(RawParameterClauseSyntax.self) { parser in
parser.parseFunctionParameter()
}
Expand Down Expand Up @@ -1239,8 +1223,7 @@ extension Parser {
/// subscript-declaration → subscript-head subscript-result generic-where-clause? getter-setter-keyword-block
/// subscript-head → attributes? declaration-modifiers? 'subscript' generic-parameter-clause? parameter-clause
/// subscript-result → '->' attributes? type
@_spi(RawSyntax)
public mutating func parseSubscriptDeclaration(
mutating func parseSubscriptDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawSubscriptDeclSyntax {
Expand Down Expand Up @@ -1320,8 +1303,7 @@ extension Parser {
/// }
/// }
/// ```
@_spi(RawSyntax)
public mutating func parseBindingDeclaration(
mutating func parseBindingDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle,
inMemberDeclList: Bool = false
Expand Down Expand Up @@ -1543,8 +1525,7 @@ extension Parser {
/// getter-setter-block → code-block
/// getter-setter-block → { getter-clause setter-clause opt }
/// getter-setter-block → { setter-clause getter-clause }
@_spi(RawSyntax)
public mutating func parseGetSet() -> RawSubscriptDeclSyntax.Accessor {
mutating func parseGetSet() -> RawSubscriptDeclSyntax.Accessor {
// Parse getter and setter.
let unexpectedBeforeLBrace: RawUnexpectedNodesSyntax?
let lbrace: RawTokenSyntax
Expand Down Expand Up @@ -1618,8 +1599,7 @@ extension Parser {
/// typealias-declaration → attributes? access-level-modifier? 'typealias' typealias-name generic-parameter-clause? typealias-assignment
/// typealias-name → identifier
/// typealias-assignment → '=' type
@_spi(RawSyntax)
public mutating func parseTypealiasDeclaration(
mutating func parseTypealiasDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawTypealiasDeclSyntax {
Expand Down Expand Up @@ -1685,8 +1665,7 @@ extension Parser {
/// postfix-operator-declaration → 'postfix' 'operator' operator
/// infix-operator-declaration → 'infix' 'operator' operator infix-operator-group?
/// infix-operator-group → ':' precedence-group-name
@_spi(RawSyntax)
public mutating func parseOperatorDeclaration(
mutating func parseOperatorDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawOperatorDeclSyntax {
Expand Down Expand Up @@ -1803,8 +1782,7 @@ extension Parser {
///
/// precedence-group-names → precedence-group-name | precedence-group-name ',' precedence-group-names
/// precedence-group-name → identifier
@_spi(RawSyntax)
public mutating func parsePrecedenceGroupDeclaration(
mutating func parsePrecedenceGroupDeclaration(
_ attrs: DeclAttributes,
_ handle: RecoveryConsumptionHandle
) -> RawPrecedenceGroupDeclSyntax {
Expand All @@ -1831,8 +1809,7 @@ extension Parser {
)
}

@_spi(RawSyntax)
public mutating func parsePrecedenceGroupAttributeListSyntax() -> RawPrecedenceGroupAttributeListSyntax {
mutating func parsePrecedenceGroupAttributeListSyntax() -> RawPrecedenceGroupAttributeListSyntax {
enum LabelText: TokenSpecSet {
case associativity
case assignment
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftParser/Directives.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ extension Parser {
/// previous element.
/// - syntax: A function that aggregates the parsed conditional elements
/// into a syntax collection.
@_spi(RawSyntax)
public mutating func parsePoundIfDirective<Element: RawSyntaxNodeProtocol>(
mutating func parsePoundIfDirective<Element: RawSyntaxNodeProtocol>(
_ parseElement: (_ parser: inout Parser, _ isFirstElement: Bool) -> Element?,
addSemicolonIfNeeded: (_ lastElement: Element, _ newItemAtStartOfLine: Bool, _ parser: inout Parser) -> Element? = { _, _, _ in nil },
syntax: (inout Parser, [Element]) -> RawIfConfigClauseSyntax.Elements?
Expand Down Expand Up @@ -172,8 +171,7 @@ extension Parser {
/// line-control-statement → '#sourceLocation' '(' ')'
/// line-number → `A decimal integer greater than zero`
/// file-path → static-string-literal
@_spi(RawSyntax)
public mutating func parsePoundSourceLocationDirective() -> RawPoundSourceLocationSyntax {
mutating func parsePoundSourceLocationDirective() -> RawPoundSourceLocationSyntax {
let line = self.consumeAnyToken()
let (unexpectedBeforeLParen, lparen) = self.expect(.leftParen)
let args: RawPoundSourceLocationArgsSyntax?
Expand Down
Loading