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

[SR-10024] Add new TokenKinds for contextual keyword in libSyntax/SwiftSyntax #434

Open
swift-ci opened this issue Mar 1, 2019 · 8 comments
Open

Comments

@swift-ci
Copy link
Contributor

@swift-ci swift-ci commented Mar 1, 2019

Previous ID SR-10024
Radar None
Original Reporter kitasuke (JIRA User)
Type Improvement

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler, SwiftSyntax
Labels Improvement
Assignee None
Priority Medium

md5: f6a7999be8142907c0d76093517b06c8

Issue Description:

All contextual keyword's token kind is `identifier` for now, but I would like to have them as keyword kind instead.

For example, I was expecting to have `weakKeyword` for below variable declaration, but I got `identifier("weak")` in SwiftSyntax. In this context, it can tell keyword, not identifier.

Same thing happens to other contextual keywords as well.

@IBOutlet private weak var button: UIButton!

Sample code:

// sample.swift
class View {
 @IBOutlet private weak var button: UIButton!
}
 $swiftc -frontend -emit-syntax sample.swift  

Expected:

"tokenKind":{"kind":"kw_weak"} 

Actual:

"tokenKind":{"kind":"identifier","text":"weak"}

Environment:

Xcode 10.2 beta 3 (10P99q)

Apple Swift version 5.0 (swiftlang-1001.0.63.8 clang-1001.0.43)
Target: x86_64-apple-darwin18.2.0

@rintaro
Copy link
Mannequin

@rintaro rintaro mannequin commented Mar 1, 2019

@akyrtzi
Copy link
Member

@akyrtzi akyrtzi commented Mar 1, 2019

I think this is the kind of contextual "classification" we have the SyntaxClassifier for.

For example for "let x: Int" "Int" is an identifier token, but the classifier will mark it as 'type-identifier'. In the case of "weak" in your example it will mark it as 'builtin-attribute' classification kind.

@rintaro
Copy link
Mannequin

@rintaro rintaro mannequin commented Mar 4, 2019

We already have ContextualKeyword token kind. We probably should use them for modifiers at least. WDYT @akyrtzi?

@akyrtzi
Copy link
Member

@akyrtzi akyrtzi commented Mar 4, 2019

Could you clarify how we use it currently ?

@rintaro
Copy link
Mannequin

@rintaro rintaro mannequin commented Mar 4, 2019

In parser, we set the token kind to tok::contextual_keyword for several places such as accessor introducer (get, set, willSet, etc.), #selector, or attribute names for precedencegroup (higherThan etc.). But not for decl modifiers.

@rintaro
Copy link
Mannequin

@rintaro rintaro mannequin commented Mar 4, 2019

@harlanhaskins Do you remember why ContextualKeyword was introduced? It's not entirely clear from apple/swift#13321

@harlanhaskins
Copy link
Contributor

@harlanhaskins harlanhaskins commented Mar 4, 2019

That patch was really introducing TokenKinds to cover the new ones in apple/swift#11809

I think SyntaxClassifier serves the need that contextual_keyword served. @nkcsgexi should we get rid of contextual_keyword?

@akyrtzi
Copy link
Member

@akyrtzi akyrtzi commented Mar 10, 2019

I've added a convenience API TokenSyntax.tokenClassification to get the classification for a specific token (#109 I think we should get rid of contextual_keyword.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants