-
Notifications
You must be signed in to change notification settings - Fork 414
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
Don't declare attribute names as keywords #2486
base: main
Are you sure you want to change the base?
Conversation
They were declared as `Keyword` only for `TokenSpecs` (DeclarationAttributeWithSpecialSyntax and TypeAttribute), the attribute names are always parsed as `TypeSyntax` so those keywords weren't even appear in the parsed syntax tree. Instead, make those `TokenSpecSet` to accept `.identifier` lexemes.
@swift-ci Please test |
@swift-ci Please test |
Sources/SwiftParser/Attributes.swift
Outdated
} | ||
case .identifier: | ||
switch lexeme.tokenText { | ||
case "_alignment": self = ._alignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning toward making TokenSpec
for fixed text. I.e. TokenSpec("_alignment")
.
73afa81
to
655cd79
Compare
Matches a specific tokenText. Use it in decl/type attribute TokenSpecSet.
655cd79
to
dbcc021
Compare
The last commit implements |
@swift-ci Please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Could you / did you check that this doesn’t have a performance impact?
/// `fileprivate` because only functions in this file should access it since | ||
/// they know how to handle the identifier -> keyword remapping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn’t really make sense on an enum case.
return TokenSpec(keyword) | ||
} | ||
|
||
static func fixedText(_ text: SyntaxText) -> TokenSpec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to add a short comment that explains when somebody should use fixedText
vs adding a keyword. The chance of misuse seems quite high to me.
They were declared as
Keyword
only forTokenSpecs
(DeclarationAttributeWithSpecialSyntax and TypeAttribute), the attribute names are always parsed asTypeSyntax
so those keywords weren't even appear in the parsed syntax tree.Instead, make those
TokenSpecSet
to accept.identifier
lexemes with specific token text.