Skip to content

Commit

Permalink
removing unnecessary captures and improving class func/var declaratio…
Browse files Browse the repository at this point in the history
…n syntax
  • Loading branch information
guuido committed Oct 30, 2024
1 parent 7c536df commit 8a954c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
24 changes: 13 additions & 11 deletions src/languages/swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,27 +461,29 @@ export default function(hljs) {
};

const CLASS_FUNC_DECLARATION = {
begin: [
/(class)\s+/,
/(func)\b/,
match: [
/class\b/,
/\s+/,
/func\b/,
/\s+/,
/\b[A-Za-z_][A-Za-z0-9_]*\b/
],
beginScope: {
scope: {
1: "keyword",
2: "keyword",
4: "title.function"
3: "keyword",
5: "title.function"
}
};

const CLASS_VAR_DECLARATION = {
begin: [
/(class)\s+/,
/(var)\b/,
match: [
/class\b/,
/\s+/,
/var\b/,
],
beginScope: {
scope: {
1: "keyword",
2: "keyword"
3: "keyword"
}
};

Expand Down
10 changes: 5 additions & 5 deletions test/markup/swift/class-func-var.expect.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<span class="hljs-keyword">class </span><span class="hljs-keyword">func</span> <span class="hljs-title function_">f1</span>() -&gt; <span class="hljs-type">Void</span> { }
<span class="hljs-keyword">class</span> <span class="hljs-keyword">func</span> <span class="hljs-title function_">f1</span>() -&gt; <span class="hljs-type">Void</span> { }

<span class="hljs-keyword">class </span><span class="hljs-keyword">func</span> <span class="hljs-title function_">f2</span><span class="hljs-operator">&lt;</span><span class="hljs-type">T</span>: <span class="hljs-type">Comparable</span><span class="hljs-operator">&gt;</span>() -&gt; <span class="hljs-type">T</span> { }
<span class="hljs-keyword">class</span> <span class="hljs-keyword">func</span> <span class="hljs-title function_">f2</span><span class="hljs-operator">&lt;</span><span class="hljs-type">T</span>: <span class="hljs-type">Comparable</span><span class="hljs-operator">&gt;</span>() -&gt; <span class="hljs-type">T</span> { }

<span class="hljs-keyword">class </span><span class="hljs-keyword">func</span> <span class="hljs-title function_">f3</span><span class="hljs-operator">&lt;</span><span class="hljs-type">T</span><span class="hljs-operator">&gt;</span>(
<span class="hljs-keyword">class</span> <span class="hljs-keyword">func</span> <span class="hljs-title function_">f3</span><span class="hljs-operator">&lt;</span><span class="hljs-type">T</span><span class="hljs-operator">&gt;</span>(
<span class="hljs-keyword">_</span> p1: <span class="hljs-type">Int</span>,
p2: <span class="hljs-type">String</span>
) <span class="hljs-keyword">async</span> <span class="hljs-keyword">throws</span> -&gt; [<span class="hljs-type">T</span>] { }

<span class="hljs-keyword">class </span><span class="hljs-keyword">var</span> v1: <span class="hljs-type">Int</span> { <span class="hljs-keyword">get</span> <span class="hljs-keyword">set</span> }
<span class="hljs-keyword">class</span> <span class="hljs-keyword">var</span> v1: <span class="hljs-type">Int</span> { <span class="hljs-keyword">get</span> <span class="hljs-keyword">set</span> }

<span class="hljs-keyword">class </span><span class="hljs-keyword">var</span> v2: <span class="hljs-type">String</span> {
<span class="hljs-keyword">class</span> <span class="hljs-keyword">var</span> v2: <span class="hljs-type">String</span> {
<span class="hljs-keyword">get</span> { <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;test&quot;</span> }
<span class="hljs-keyword">set</span> { }
}

0 comments on commit 8a954c0

Please sign in to comment.