Skip to content

Commit 78969cf

Browse files
committed
Make keyword precedence exhaustive
1 parent 56b057b commit 78969cf

File tree

1 file changed

+128
-8
lines changed

1 file changed

+128
-8
lines changed

Sources/SwiftParser/TokenPrecedence.swift

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,29 +192,33 @@ enum TokenPrecedence: Comparable {
192192
case // Literals
193193
.Self, .false, .nil, .`self`, .super, .true:
194194
self = .identifierLike
195+
195196
// MARK: Expr keyword
196197
case // Keywords
197-
.as, .is, .try,
198+
.as, .is, .some, .try,
199+
.await, .each, .copy,
198200
// We don't know much about which contextual keyword it is, be conservative an allow considering it as unexpected.
199201
// Keywords in function types (we should be allowed to skip them inside parenthesis)
200-
.rethrows, .throws,
202+
.rethrows, .throws, .reasync, .async,
201203
// Consider 'any' a prefix operator to a type and a type is expression-like.
202204
.Any,
203205
// 'where' can only occur in the signature of declarations. Consider the signature expression-like.
204206
.where,
205207
// 'in' occurs in closure input/output definitions and for loops. Consider both constructs expression-like.
206208
.in:
207209
self = .exprKeyword
210+
208211
case // Control-flow constructs
209212
.defer, .do, .for, .guard, .if, .repeat, .switch, .while,
210213
// Secondary parts of control-flow constructs
211214
.case, .catch, .default, .else,
212215
// Return-like statements
213216
.break, .continue, .fallthrough, .return, .throw, .then, .yield:
214217
self = .stmtKeyword
218+
215219
// MARK: Decl keywords
216220
case // Types
217-
.associatedtype, .class, .enum, .extension, .protocol, .struct, .typealias,
221+
.associatedtype, .class, .enum, .extension, .protocol, .struct, .typealias, .actor, .macro,
218222
// Access modifiers
219223
.fileprivate, .internal, .private, .public, .static,
220224
// Functions
@@ -225,14 +229,130 @@ enum TokenPrecedence: Comparable {
225229
.operator, .precedencegroup,
226230
// Declaration Modifiers
227231
.__consuming, .final, .required, .optional, .lazy, .dynamic, .infix, .postfix, .prefix, .mutating, .nonmutating, .convenience, .override, .package, .open,
228-
.__setter_access, .indirect, .nonisolated, .distributed, ._local,
229-
.inout, ._mutating, ._borrowing, ._consuming,
232+
.__setter_access, .indirect, .isolated, .nonisolated, .distributed, ._local,
233+
.inout, ._mutating, ._borrow, ._borrowing, .borrowing, ._consuming, .consuming, .consume,
230234
// Misc
231235
.import:
232236
self = .declKeyword
233-
default:
234-
// Treat all keywords that weren't handled above as expression keywords as a fallback option.
235-
// FIXME: We should assign a token precedence to all keywords
237+
238+
case // Treat all other keywords as expression keywords in the absence of any better information.
239+
.__owned,
240+
.__shared,
241+
._alignment,
242+
._backDeploy,
243+
._cdecl,
244+
._Class,
245+
._compilerInitialized,
246+
._const,
247+
._documentation,
248+
._dynamicReplacement,
249+
._effects,
250+
._expose,
251+
._forward,
252+
._implements,
253+
._linear,
254+
._modify,
255+
._move,
256+
._NativeClass,
257+
._NativeRefCountedObject,
258+
._noMetadata,
259+
._nonSendable,
260+
._objcImplementation,
261+
._objcRuntimeName,
262+
._opaqueReturnTypeOf,
263+
._optimize,
264+
._originallyDefinedIn,
265+
._PackageDescription,
266+
._private,
267+
._projectedValueProperty,
268+
._read,
269+
._RefCountedObject,
270+
._semantics,
271+
._specialize,
272+
._spi,
273+
._spi_available,
274+
._swift_native_objc_runtime_base,
275+
._Trivial,
276+
._TrivialAtMost,
277+
._typeEraser,
278+
._unavailableFromAsync,
279+
._underlyingVersion,
280+
._UnknownLayout,
281+
._version,
282+
.accesses,
283+
.addressWithNativeOwner,
284+
.addressWithOwner,
285+
.any,
286+
.assignment,
287+
.associativity,
288+
.attached,
289+
.autoclosure,
290+
.availability,
291+
.available,
292+
.backDeployed,
293+
.before,
294+
.block,
295+
.canImport,
296+
.compiler,
297+
.convention,
298+
.cType,
299+
.deprecated,
300+
.derivative,
301+
.didSet,
302+
.differentiable,
303+
.escaping,
304+
.exclusivity,
305+
.exported,
306+
.file,
307+
.discard,
308+
.forward,
309+
.get,
310+
.higherThan,
311+
.initializes,
312+
.inline,
313+
.introduced,
314+
.kind,
315+
.left,
316+
.line,
317+
.linear,
318+
.lowerThan,
319+
.message,
320+
.metadata,
321+
.module,
322+
.mutableAddressWithNativeOwner,
323+
.mutableAddressWithOwner,
324+
.noasync,
325+
.noDerivative,
326+
.noescape,
327+
.none,
328+
.objc,
329+
.obsoleted,
330+
.of,
331+
.Protocol,
332+
.renamed,
333+
.reverse,
334+
.right,
335+
.safe,
336+
.Sendable,
337+
.set,
338+
.sourceFile,
339+
.spi,
340+
.spiModule,
341+
.swift,
342+
.target,
343+
.transpose,
344+
.Type,
345+
.unavailable,
346+
.unchecked,
347+
.unowned,
348+
.unsafeAddress,
349+
.unsafeMutableAddress,
350+
.visibility,
351+
.weak,
352+
.willSet,
353+
.witness_method,
354+
.wrt,
355+
.unsafe:
236356
self = .exprKeyword
237357
}
238358
}

0 commit comments

Comments
 (0)