Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Feb 7, 2024

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 with specific token text.

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.
@rintaro
Copy link
Member Author

rintaro commented Feb 7, 2024

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Feb 8, 2024

@swift-ci Please test

}
case .identifier:
switch lexeme.tokenText {
case "_alignment": self = ._alignment
Copy link
Member Author

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").

Matches a specific tokenText. Use it in decl/type attribute
TokenSpecSet.
@rintaro
Copy link
Member Author

rintaro commented Feb 8, 2024

The last commit implements TokenSpec for a fixed text.

@rintaro
Copy link
Member Author

rintaro commented Feb 8, 2024

@swift-ci Please test

Copy link
Member

@ahoppen ahoppen left a 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?

Comment on lines +64 to +65
/// `fileprivate` because only functions in this file should access it since
/// they know how to handle the identifier -> keyword remapping.
Copy link
Member

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 {
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants