Skip to content

Drop Keyword suffix from TokenSpecSet #1668

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 1 commit into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Sources/SwiftParser/Attributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,23 @@ extension Parser {

enum DifferentiabilityKind: TokenSpecSet {
case reverse
case linear
case forward
case _linear
case _forward

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.reverse): self = .reverse
case TokenSpec(._linear): self = .linear
case TokenSpec(._forward): self = .forward
case TokenSpec(._linear): self = ._linear
case TokenSpec(._forward): self = ._forward
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .reverse: return .keyword(.reverse)
case .linear: return .keyword(._linear)
case .forward: return .keyword(._forward)
case ._linear: return .keyword(._linear)
case ._forward: return .keyword(._forward)
}
}
}
Expand Down Expand Up @@ -474,13 +474,13 @@ extension Parser {
enum ExpectedTokenKind: TokenSpecSet {
case identifier
case integerLiteral
case selfKeyword
case `self`

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(.identifier): self = .identifier
case TokenSpec(.integerLiteral): self = .integerLiteral
case TokenSpec(.self): self = .selfKeyword
case TokenSpec(.self): self = .self
default: return nil
}
}
Expand All @@ -489,7 +489,7 @@ extension Parser {
switch self {
case .identifier: return .identifier
case .integerLiteral: return .integerLiteral
case .selfKeyword: return .keyword(.self)
case .self: return .keyword(.self)
}
}
}
Expand All @@ -511,7 +511,7 @@ extension Parser {
trailingComma: comma,
arena: self.arena
)
case (.selfKeyword, let handle)?:
case (.self, let handle)?:
let token = self.eat(handle)
let comma = self.consume(if: .comma)
return RawDifferentiabilityParamSyntax(
Expand Down
104 changes: 52 additions & 52 deletions Sources/SwiftParser/Declarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extension TokenConsumer {
declStartKeyword = subparser.at(anyIn: DeclarationStart.self)?.0
}
switch declStartKeyword {
case .actorKeyword:
case .actor:
// actor Foo {}
if subparser.peek().rawTokenKind == .identifier {
return true
Expand All @@ -113,13 +113,13 @@ extension TokenConsumer {
lookahead.consumeAnyToken()
} while lookahead.atStartOfDeclaration(isAtTopLevel: isAtTopLevel, allowInitDecl: allowInitDecl)
return lookahead.at(.identifier)
case .caseKeyword:
case .case:
// When 'case' appears inside a function, it's probably a switch
// case, not an enum case declaration.
return false
case .initKeyword:
case .`init`:
return allowInitDecl
case .macroKeyword:
case .macro:
// macro Foo ...
return subparser.peek().rawTokenKind == .identifier
case .pound:
Expand Down Expand Up @@ -234,42 +234,42 @@ extension Parser {
let recoveryPrecedence = inMemberDeclList ? TokenPrecedence.closingBrace : nil

switch self.canRecoverTo(anyIn: DeclarationStart.self, overrideRecoveryPrecedence: recoveryPrecedence) {
case (.importKeyword, let handle)?:
case (.import, let handle)?:
return RawDeclSyntax(self.parseImportDeclaration(attrs, handle))
case (.classKeyword, let handle)?:
case (.class, let handle)?:
return RawDeclSyntax(self.parseNominalTypeDeclaration(for: RawClassDeclSyntax.self, attrs: attrs, introucerHandle: handle))
case (.enumKeyword, let handle)?:
case (.enum, let handle)?:
return RawDeclSyntax(self.parseNominalTypeDeclaration(for: RawEnumDeclSyntax.self, attrs: attrs, introucerHandle: handle))
case (.caseKeyword, let handle)?:
case (.case, let handle)?:
return RawDeclSyntax(self.parseEnumCaseDeclaration(attrs, handle))
case (.structKeyword, let handle)?:
case (.struct, let handle)?:
return RawDeclSyntax(self.parseNominalTypeDeclaration(for: RawStructDeclSyntax.self, attrs: attrs, introucerHandle: handle))
case (.protocolKeyword, let handle)?:
case (.protocol, let handle)?:
return RawDeclSyntax(self.parseNominalTypeDeclaration(for: RawProtocolDeclSyntax.self, attrs: attrs, introucerHandle: handle))
case (.associatedtypeKeyword, let handle)?:
case (.associatedtype, let handle)?:
return RawDeclSyntax(self.parseAssociatedTypeDeclaration(attrs, handle))
case (.typealiasKeyword, let handle)?:
case (.typealias, let handle)?:
return RawDeclSyntax(self.parseTypealiasDeclaration(attrs, handle))
case (.extensionKeyword, let handle)?:
case (.extension, let handle)?:
return RawDeclSyntax(self.parseExtensionDeclaration(attrs, handle))
case (.funcKeyword, let handle)?:
case (.func, let handle)?:
return RawDeclSyntax(self.parseFuncDeclaration(attrs, handle))
case (.subscriptKeyword, let handle)?:
case (.subscript, let handle)?:
return RawDeclSyntax(self.parseSubscriptDeclaration(attrs, handle))
case (.letKeyword, let handle)?, (.varKeyword, let handle)?,
(.inoutKeyword, let handle)?:
case (.let, let handle)?, (.var, let handle)?,
(.inout, let handle)?:
return RawDeclSyntax(self.parseBindingDeclaration(attrs, handle, inMemberDeclList: inMemberDeclList))
case (.initKeyword, let handle)?:
case (.`init`, let handle)?:
return RawDeclSyntax(self.parseInitializerDeclaration(attrs, handle))
case (.deinitKeyword, let handle)?:
case (.deinit, let handle)?:
return RawDeclSyntax(self.parseDeinitializerDeclaration(attrs, handle))
case (.operatorKeyword, let handle)?:
case (.operator, let handle)?:
return RawDeclSyntax(self.parseOperatorDeclaration(attrs, handle))
case (.precedencegroupKeyword, let handle)?:
case (.precedencegroup, let handle)?:
return RawDeclSyntax(self.parsePrecedenceGroupDeclaration(attrs, handle))
case (.actorKeyword, let handle)?:
case (.actor, let handle)?:
return RawDeclSyntax(self.parseNominalTypeDeclaration(for: RawActorDeclSyntax.self, attrs: attrs, introucerHandle: handle))
case (.macroKeyword, let handle)?:
case (.macro, let handle)?:
return RawDeclSyntax(self.parseMacroDeclaration(attrs: attrs, introducerHandle: handle))
case (.pound, let handle)?:
return RawDeclSyntax(self.parseMacroExpansionDeclaration(attrs, handle))
Expand Down Expand Up @@ -575,50 +575,50 @@ extension Parser {
}

enum LayoutConstraint: TokenSpecSet {
case trivialLayout
case trivialAtMostLayout
case unknownLayout
case refCountedObjectLayout
case nativeRefCountedObjectLayout
case classLayout
case nativeClassLayout
case _Trivial
case _TrivialAtMost
case _UnknownLayout
case _RefCountedObjectLayout
case _NativeRefCountedObjectLayout
case _Class
case _NativeClass

init?(lexeme: Lexer.Lexeme) {
switch PrepareForKeywordMatch(lexeme) {
case TokenSpec(._Trivial): self = .trivialLayout
case TokenSpec(._TrivialAtMost): self = .trivialAtMostLayout
case TokenSpec(._UnknownLayout): self = .unknownLayout
case TokenSpec(._RefCountedObject): self = .refCountedObjectLayout
case TokenSpec(._NativeRefCountedObject): self = .nativeRefCountedObjectLayout
case TokenSpec(._Class): self = .classLayout
case TokenSpec(._NativeClass): self = .nativeClassLayout
case TokenSpec(._Trivial): self = ._Trivial
case TokenSpec(._TrivialAtMost): self = ._TrivialAtMost
case TokenSpec(._UnknownLayout): self = ._UnknownLayout
case TokenSpec(._RefCountedObject): self = ._RefCountedObjectLayout
case TokenSpec(._NativeRefCountedObject): self = ._NativeRefCountedObjectLayout
case TokenSpec(._Class): self = ._Class
case TokenSpec(._NativeClass): self = ._NativeClass
default: return nil
}
}

var spec: TokenSpec {
switch self {
case .trivialLayout: return .keyword(._Trivial)
case .trivialAtMostLayout: return .keyword(._TrivialAtMost)
case .unknownLayout: return .keyword(._UnknownLayout)
case .refCountedObjectLayout: return .keyword(._RefCountedObject)
case .nativeRefCountedObjectLayout: return .keyword(._NativeRefCountedObject)
case .classLayout: return .keyword(._Class)
case .nativeClassLayout: return .keyword(._NativeClass)
case ._Trivial: return .keyword(._Trivial)
case ._TrivialAtMost: return .keyword(._TrivialAtMost)
case ._UnknownLayout: return .keyword(._UnknownLayout)
case ._RefCountedObjectLayout: return .keyword(._RefCountedObject)
case ._NativeRefCountedObjectLayout: return .keyword(._NativeRefCountedObject)
case ._Class: return .keyword(._Class)
case ._NativeClass: return .keyword(._NativeClass)
}
}

var hasArguments: Bool {
switch self {
case .trivialLayout,
.trivialAtMostLayout:
case ._Trivial,
._TrivialAtMost:
return true

case .unknownLayout,
.refCountedObjectLayout,
.nativeRefCountedObjectLayout,
.classLayout,
.nativeClassLayout:
case ._UnknownLayout,
._RefCountedObjectLayout,
._NativeRefCountedObjectLayout,
._Class,
._NativeClass:
return false
}
}
Expand Down Expand Up @@ -696,7 +696,7 @@ extension Parser {
let rightParen: RawTokenSyntax?
// Unlike the other layout constraints, _Trivial's argument list
// is optional.
if layoutConstraint.hasArguments && (layoutConstraint != .trivialLayout || self.at(.leftParen)) {
if layoutConstraint.hasArguments && (layoutConstraint != ._Trivial || self.at(.leftParen)) {
(unexpectedBeforeLeftParen, leftParen) = self.expect(.leftParen)
size = self.expectWithoutRecovery(.integerLiteral)
comma = self.consume(if: .comma)
Expand Down
Loading