Skip to content

Commit

Permalink
enh(swift) add SE-0290 unavailability condition (#3382)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleymackey committed Nov 2, 2021
1 parent cd1c9dc commit 8c00856
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -3,8 +3,10 @@
Grammars:

- fix(python) Fix recognition of numeric literals followed by keywords without whitespace (#2985) [Richard Gibson][]
- enh(swift) add SE-0290 unavailability condition (#3382) [Bradley Mackey][]

[Richard Gibson]: https://github.com/gibson042
[Bradley Mackey]: https://github.com/bradleymackey

## Version 11.3.1

Expand Down
4 changes: 2 additions & 2 deletions src/languages/lib/kws_swift.js
Expand Up @@ -141,7 +141,7 @@ export const precedencegroupKeywords = [
];

// Keywords that start with a number sign (#).
// #available is handled separately.
// #(un)available is handled separately.
export const numberSignKeywords = [
'#colorLiteral',
'#column',
Expand Down Expand Up @@ -307,7 +307,7 @@ export const keywordAttributes = [
'usableFromInline'
];

// Contextual keywords used in @available and #available.
// Contextual keywords used in @available and #(un)available.
export const availabilityKeywords = [
'iOS',
'iOSApplicationExtension',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/swift.js
Expand Up @@ -221,7 +221,7 @@ export default function(hljs) {

// https://docs.swift.org/swift-book/ReferenceManual/Attributes.html
const AVAILABLE_ATTRIBUTE = {
match: /(@|#)available/,
match: /(@|#(un)?)available/,
className: "keyword",
starts: {
contains: [
Expand Down
1 change: 0 additions & 1 deletion test/markup/swift/attributes.expect.txt
@@ -1,4 +1,3 @@
<span class="hljs-keyword">@available</span>(<span class="hljs-keyword">iOS</span> <span class="hljs-number">14</span>, deprecated: <span class="hljs-string">&quot;reason&quot;</span>, <span class="hljs-operator">*</span>)
<span class="hljs-keyword">@convention(swift)</span>
<span class="hljs-keyword">@objc</span>
<span class="hljs-keyword">@objc(name)</span>
Expand Down
1 change: 0 additions & 1 deletion test/markup/swift/attributes.txt
@@ -1,4 +1,3 @@
@available(iOS 14, deprecated: "reason", *)
@convention(swift)
@objc
@objc(name)
Expand Down
11 changes: 11 additions & 0 deletions test/markup/swift/availability.expect.txt
@@ -0,0 +1,11 @@
<span class="hljs-keyword">#available</span>()
<span class="hljs-keyword">#available</span>(<span class="hljs-keyword">iOS</span> <span class="hljs-number">15.0</span>, <span class="hljs-operator">*</span>)
<span class="hljs-keyword">@available</span>()
<span class="hljs-keyword">@available</span>(<span class="hljs-keyword">iOS</span> <span class="hljs-number">15.0</span>, <span class="hljs-operator">*</span>)
<span class="hljs-keyword">@available</span>(<span class="hljs-keyword">iOS</span> <span class="hljs-number">14</span>, deprecated: <span class="hljs-string">&quot;reason&quot;</span>, <span class="hljs-operator">*</span>)

<span class="hljs-keyword">#unavailable</span>()
<span class="hljs-keyword">#unavailable</span>(<span class="hljs-keyword">iOS</span> <span class="hljs-number">15.0</span>, <span class="hljs-operator">*</span>)
<span class="hljs-comment">// not a keyword</span>
<span class="hljs-meta">@unavailable</span>()
<span class="hljs-meta">@unavailable</span>(iOS <span class="hljs-number">15.0</span>, <span class="hljs-operator">*</span>)
11 changes: 11 additions & 0 deletions test/markup/swift/availability.txt
@@ -0,0 +1,11 @@
#available()
#available(iOS 15.0, *)
@available()
@available(iOS 15.0, *)
@available(iOS 14, deprecated: "reason", *)

#unavailable()
#unavailable(iOS 15.0, *)
// not a keyword
@unavailable()
@unavailable(iOS 15.0, *)

0 comments on commit 8c00856

Please sign in to comment.