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

(swift) improvements: support some, @main; Fix # keywords . #2845

Merged
merged 5 commits into from
Nov 11, 2020

Conversation

mportiz08
Copy link
Contributor

General enhancements and a bug fix for highlighting Swift code.

Changes

Adds highlighting support for new Swift 5.1 and 5.3 features that are heavily utilized in SwiftUI code:

  1. some keyword (Introduced in Swift 5.1)
  2. @main attribute (Introduced in Swift 5.3)

Fixes a bug where keywords that start with the # character (like #endif as an example) are not matched.

Checklist

  • Added markup tests
  • Updated the changelog at CHANGES.md
  • Added myself to AUTHORS.txt, under Contributors

1. [`some` keyword][1] (Introduced in Swift 5.1)
2. [`@main` attribute][2] (Introduced in Swift 5.3)

These language syntax features are utilized heavily in code that depends
on the `SwiftUI` framework for user interfaces.

[1]: https://github.com/apple/swift-evolution/blob/main/proposals/0244-opaque-result-types.md
[2]: https://github.com/apple/swift-evolution/blob/main/proposals/0281-main-attribute.md
The default of lexeme pattern of `/\w+/` is not sufficient to capture
keywords that start with a number sign character (like `#if` as one
example). This updates the pattern to also recognize the number sign
character as well as other alphanumeric characters that were previously
recognized. [1]

[1]: https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID413
@joshgoebel joshgoebel changed the title Swift improvements (swift) improvements: support some, @main. fix # keywords Nov 11, 2020
@joshgoebel
Copy link
Member

@svanimpe Could you take a quick look here. Does this look good to you? I think the changes look good, I just don't know the language itself.

@mportiz08 #2847

Do you know anything about c? If not and you agree would you mind yanking that out as part of this PR also?

@joshgoebel joshgoebel changed the title (swift) improvements: support some, @main. fix # keywords (swift) improvements: support some, @main; Fix # keywords . Nov 11, 2020
@svanimpe
Copy link
Contributor

I wonder if @mattt would be willing to help out here. Perhaps https://github.com/SwiftDocOrg/swift-doc can be used to generate a list of global functions in the Standard Library?

@joshgoebel
Copy link
Member

There are a number of Swift issues open right now (many of them of the more trivial variety) if a Swift champion were to show up on the scene. :) #2825

@joshgoebel
Copy link
Member

Perhaps https://github.com/SwiftDocOrg/swift-doc can be used to generate a list of global functions in the Standard Library?

I do worry that what we have now is perhaps someones list of "frequently used" rather than ever having been "all globals" (I really have no idea though), but now I'm curious. Swift is shipped as part of the common group so that makes me think about it's ultimate size perhaps a bit more than other grammars... like if we were suddenly going to add 1000 keywords that might be something we need to look at. Right now though Swift is a pretty small grammar, so we certainly have room to grow.

@joshgoebel
Copy link
Member

If we're going to totally rewrite the keywords section overall I'd save that for another PR though and also switch to the new one keyword per line array style to make future maintenance easier.

@mportiz08
Copy link
Contributor Author

Do you know anything about c? If not and you agree would you mind yanking that out as part of this PR also?

I don't, but that is really interesting/surprising—I'm honestly not aware of c being a keyword on its own. It looks like it was introduced with e5c1b0c.

@joshgoebel
Copy link
Member

@natecook1000 You added c to the list of Swift keywords in e5c1b0c. Can you shed any light? :)

@joshgoebel
Copy link
Member

Since we don't have any immediate answer on c I don't see a need for that issue to hold up this work. I glanced at the links provided and this looks entirely reasonable.

Thanks for the contribution!

@joshgoebel joshgoebel merged commit 6bc573c into highlightjs:master Nov 11, 2020
@joshgoebel
Copy link
Member

joshgoebel commented Nov 11, 2020

If you'd perhaps like to continue helping out with Swift: #2758 #2819

Now quite as low-hanging fruit, but close.

@svanimpe
Copy link
Contributor

W.r.t. the built-ins: I've noticed that methods like Array.count also highlight because count is listed as a built-in, even though it's not a global function anymore.

@joshgoebel
Copy link
Member

Well if the language has changed then count be perhaps removed but ultimately this will be solved when the Swift grammar adds property access and method dispatch since that rule matching would win prevent the keyword from matching, etc.

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.

3 participants