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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,4 @@ Contributors:
- Marat Nagayev <[email protected]>
- Patrick Scheibe <[email protected]>
- Kyle Brown <kylebrown9@github>
- Marcus Ortiz <[email protected]>
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Language Improvements:
- Matching of named-characters aka special symbols like `\[Gamma]`
- Updated list of version 12.1 built-in symbols
- Matching of patterns, slots, message-names and braces
- fix(swift) Handle keywords that start with `#` [Marcus Ortiz][]
- enh(swift) Match `some` keyword [Marcus Ortiz][]
- enh(swift) Match `@main` attribute [Marcus Ortiz][]

Dev Improvements:

Expand All @@ -54,6 +57,7 @@ New themes:
[Michael Rush]: https://github.com/rushimusmaximus
[Patrick Scheibe]: https://github.com/halirutan
[Kyle Brown]: https://github.com/kylebrown9
[Marcus Ortiz]: https://github.com/mportiz08


## Version 10.3.1
Expand Down
7 changes: 5 additions & 2 deletions src/languages/swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Category: common, system

export default function(hljs) {
var SWIFT_KEYWORDS = {
// override the pattern since the default of of /\w+/ is not sufficient to
// capture the keywords that start with the character "#"
$pattern: /[\w#]+/,
keyword: '#available #colorLiteral #column #else #elseif #endif #file ' +
'#fileLiteral #function #if #imageLiteral #line #selector #sourceLocation ' +
'_ __COLUMN__ __FILE__ __FUNCTION__ __LINE__ Any as as! as? associatedtype ' +
Expand All @@ -18,7 +21,7 @@ export default function(hljs) {
'get guard if import in indirect infix init inout internal is lazy left let ' +
'mutating nil none nonmutating open operator optional override postfix precedence ' +
'prefix private protocol Protocol public repeat required rethrows return ' +
'right self Self set static struct subscript super switch throw throws true ' +
'right self Self set some static struct subscript super switch throw throws true ' +
'try try! try? Type typealias unowned var weak where while willSet',
literal: 'true false nil',
built_in: 'abs advance alignof alignofValue anyGenerator assert assertionFailure ' +
Expand Down Expand Up @@ -148,7 +151,7 @@ export default function(hljs) {
'@noreturn|@IBAction|@IBDesignable|@IBInspectable|@IBOutlet|' +
'@infix|@prefix|@postfix|@autoclosure|@testable|@available|' +
'@nonobjc|@NSApplicationMain|@UIApplicationMain|@dynamicMemberLookup|' +
'@propertyWrapper)\\b'
'@propertyWrapper|@main)\\b'

},
{
Expand Down
12 changes: 12 additions & 0 deletions test/markup/swift/swiftui.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<span class="hljs-meta">@main</span>
<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">MyApp</span>: <span class="hljs-title">App</span> </span>{
<span class="hljs-keyword">var</span> body: <span class="hljs-keyword">some</span> <span class="hljs-type">Scene</span> {
<span class="hljs-type">WindowGroup</span> {
<span class="hljs-keyword">#if</span> os(iOS)
<span class="hljs-type">Text</span>(<span class="hljs-string">&quot;Hello, world from iOS!&quot;</span>)
<span class="hljs-keyword">#else</span>
<span class="hljs-type">Text</span>(<span class="hljs-string">&quot;Hello, world!&quot;</span>)
<span class="hljs-keyword">#endif</span>
}
}
}
12 changes: 12 additions & 0 deletions test/markup/swift/swiftui.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
#if os(iOS)
Text("Hello, world from iOS!")
#else
Text("Hello, world!")
#endif
}
}
}