Skip to content

Commit 02c551d

Browse files
committed
Number sign keywords can appear as function names when without #
1 parent ffd5f86 commit 02c551d

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

src/languages/swift.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,20 +494,24 @@ export default function(hljs) {
494494
return concat("(?!", list.join("|"), ")");
495495
}
496496

497-
const METHODS_ONLY = [...Swift.keywords, ...Swift.numberSignKeywordsRaw, ...Swift.builtIns];
497+
const METHODS_ONLY = [...Swift.keywords, ...Swift.builtIns];
498498
const FUNCTION_CALL = {
499499
relevance: 0,
500500
variants: [
501501
{
502+
// Functions and macro calls
502503
scope: "title.function",
504+
keywords: KEYWORDS,
503505
match: concat(
504-
either(/#/, /\b/),
505-
noneOf(METHODS_ONLY.map(x => concat(x, TRAILING_PAREN_REGEX))),
506+
either(/\b/, /#/),
507+
noneOf([...METHODS_ONLY].map(x => concat(x, TRAILING_PAREN_REGEX))),
506508
FUNCTION_IDENT,
507509
lookahead(TRAILING_PAREN_REGEX),
508510
),
509511
},
510512
{
513+
// Keywords/built-ins that only can appear as a method call
514+
// e.g. foo.if()
511515
match: [
512516
/\./,
513517
either(...METHODS_ONLY),
@@ -518,6 +522,7 @@ export default function(hljs) {
518522
}
519523
},
520524
{
525+
// Quoted methods calls, e.g. `foo`()
521526
scope: "title.function",
522527
match: concat(
523528
QUOTED_IDENTIFIER.match,

test/markup/swift/functions.expect.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ obj.<span class="hljs-title function_">`if`</span> ()
7979
<span class="hljs-title function_">`notKeyword`</span>()
8080
obj.<span class="hljs-title function_">`notKeyword`</span>()
8181
obj.<span class="hljs-title function_">`notKeyword`</span> ()
82+
83+
<span class="hljs-comment">// number sign keywords are fine</span>
84+
<span class="hljs-title function_">column</span>()
85+
<span class="hljs-title function_">keyPath</span>()
86+
<span class="hljs-title function_">sourceLocation</span>()
87+
obj.<span class="hljs-title function_">column</span>()
88+
obj.<span class="hljs-title function_">keyPath</span>()
89+
obj.<span class="hljs-title function_">sourceLocation</span>()
90+
91+
<span class="hljs-comment">// attribute keywords are fine</span>
92+
<span class="hljs-title function_">frozen</span>()
93+
<span class="hljs-title function_">discardableResult</span>()
94+
obj.<span class="hljs-title function_">frozen</span>()
95+
obj.<span class="hljs-title function_">discardableResult</span>()
96+

test/markup/swift/functions.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ obj.`if` ()
7979
`notKeyword`()
8080
obj.`notKeyword`()
8181
obj.`notKeyword` ()
82+
83+
// number sign keywords are fine
84+
column()
85+
keyPath()
86+
sourceLocation()
87+
obj.column()
88+
obj.keyPath()
89+
obj.sourceLocation()
90+
91+
// attribute keywords are fine
92+
frozen()
93+
discardableResult()
94+
obj.frozen()
95+
obj.discardableResult()
96+

test/markup/swift/keywords.expect.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ x <span class="hljs-keyword">is</span> <span class="hljs-type">String</span>
2020
<span class="hljs-keyword">public</span> <span class="hljs-keyword">private</span> <span class="hljs-keyword">fileprivate</span> <span class="hljs-keyword">package</span> <span class="hljs-keyword">internal</span> <span class="hljs-keyword">open</span>
2121

2222
<span class="hljs-keyword">#if</span> <span class="hljs-type">DEBUG</span>
23-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
23+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
2424
<span class="hljs-keyword">#elseif</span> <span class="hljs-title function_">os</span>(macOS)
25-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
25+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
2626
<span class="hljs-keyword">#elseif</span> <span class="hljs-title function_">arch</span>(arm64)
27-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
27+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
2828
<span class="hljs-keyword">#elseif</span> <span class="hljs-title function_">compiler</span>(<span class="hljs-operator">&gt;=</span><span class="hljs-number">5.0</span>)
29-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
29+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
3030
<span class="hljs-keyword">#elseif</span> <span class="hljs-title function_">canImport</span>(<span class="hljs-type">UIKit</span>)
31-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
31+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
3232
<span class="hljs-keyword">#elseif</span> <span class="hljs-title function_">targetEnvironment</span>(simulator)
33-
<span class="hljs-keyword">#error</span>(<span class="hljs-string">&quot;Error&quot;</span>)
33+
<span class="hljs-title function_"><span class="hljs-keyword">#error</span></span>(<span class="hljs-string">&quot;Error&quot;</span>)
3434
<span class="hljs-keyword">#endif</span>
3535

36-
<span class="hljs-keyword">#imageLiteral</span>(resourceName: expression)
37-
<span class="hljs-keyword">#fileLiteral</span>(resourceName: expression)
36+
<span class="hljs-title function_"><span class="hljs-keyword">#imageLiteral</span></span>(resourceName: expression)
37+
<span class="hljs-title function_"><span class="hljs-keyword">#fileLiteral</span></span>(resourceName: expression)
3838

3939
x.<span class="hljs-title function_">as</span>(y)
4040
x.<span class="hljs-title function_">for</span>(y)

0 commit comments

Comments
 (0)