@@ -431,24 +431,32 @@ extension Parser {
431431 )
432432 }
433433
434- /// If `keywordRecovery` is set to `true` and the parser is currently
435- /// positioned at a keyword instead of an identifier, this method recovers by
436- /// eating the keyword in place of an identifier, recovering if the developer
437- /// incorrectly used a keyword as an identifier.
438- /// This should be set if keywords aren't strong recovery marker at this
439- /// position, e.g. because the parser expects a punctuator next.
440- ///
441- /// If `allowSelfOrCapitalSelfAsIdentifier` is `true`, then `self` and `Self`
442- /// are also accepted and remapped to identifiers. This is exclusively used
443- /// to maintain compatibility with the C++ parser. No new uses of this should
444- /// be introduced.
434+ /// - Parameters:
435+ /// - keywordRecovery: If set to `true` and the parser is currently
436+ /// positioned at a keyword instead of an identifier, this method recovers
437+ /// by eating the keyword in place of an identifier, recovering if the
438+ /// developer incorrectly used a keyword as an identifier. This should be
439+ /// set if keywords aren't strong recovery marker at this position, e.g.
440+ /// because the parser expects a punctuator next
441+ /// - allowSelfOrCapitalSelfAsIdentifier: If set to `true`, then `self` and
442+ /// `Self` are also accepted and remapped to identifiers. This is
443+ /// exclusively used to maintain compatibility with the C++ parser. No new
444+ /// uses of this should be introduced.
445+ /// - allowKeywordsAsIdentifier: If set to `true` and the parser is
446+ /// currently positioned at a keyword, consume that keyword and remap it
447+ /// to and identifier.
448+ /// - Returns: The consumed token and any unexpected tokens that were skipped.
445449 mutating func expectIdentifier(
446450 keywordRecovery: Bool = false ,
447- allowSelfOrCapitalSelfAsIdentifier: Bool = false
451+ allowSelfOrCapitalSelfAsIdentifier: Bool = false ,
452+ allowKeywordsAsIdentifier: Bool = false
448453 ) -> ( RawUnexpectedNodesSyntax ? , RawTokenSyntax ) {
449454 if let identifier = self . consume ( if: . identifier) {
450455 return ( nil , identifier)
451456 }
457+ if allowKeywordsAsIdentifier, self . currentToken. isLexerClassifiedKeyword {
458+ return ( nil , self . consumeAnyToken ( remapping: . identifier) )
459+ }
452460 if allowSelfOrCapitalSelfAsIdentifier,
453461 let selfOrCapitalSelf = self . consume ( if: TokenSpec ( . self , remapping: . identifier) , TokenSpec ( . Self, remapping: . identifier) )
454462 {
0 commit comments