Skip to content

Commit

Permalink
enh(scala) add using soft keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Sep 7, 2021
1 parent e91ffbd commit c6f7de9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Grammars:
- enh(scala) add missing `do` and `then` keyword (#3323) [Nicolas Stucki][]
- enh(scala) add missing `enum`, `export` and `given` keywords (#3328) [Nicolas Stucki][]
- enh(scala) remove symbol syntax and fix quoted code syntax (#3324) [Nicolas Stucki][]
- enh(scala) add `using` soft keyword (#3330) [Nicolas Stucki][]

[Austin Schick]: https://github.com/austin-schick
[Josh Goebel]: https://github.com/joshgoebel
Expand Down
14 changes: 13 additions & 1 deletion src/languages/scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,22 @@ export default function(hljs) {
const METHOD = {
className: 'function',
beginKeywords: 'def',
end: /[:={\[(\n;]/,
end: /(?=[:={\[(\n;])/,
excludeEnd: true,
contains: [ NAME ]
};

const USING_PARAM_CLAUSE = {
begin: [
/[(]\s*/, // Opening `(` of a parameter or argument list
/using/,
/\s+(?!\))/ // Spaces not followed by `)`
],
beginScope: {
2: "keyword",
}
};

return {
name: 'Scala',
keywords: {
Expand All @@ -126,6 +137,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
USING_PARAM_CLAUSE,
ANNOTATION
]
};
Expand Down
2 changes: 1 addition & 1 deletion test/markup/scala/quoted-code.expect.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span></span>(using <span class="hljs-type">Quotes</span>) = &#x27;{ <span class="hljs-keyword">val</span> x = <span class="hljs-number">1</span>; ${g(&#x27;x)} }
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span></span>(<span class="hljs-keyword">using</span> <span class="hljs-type">Quotes</span>) = &#x27;{ <span class="hljs-keyword">val</span> x = <span class="hljs-number">1</span>; ${g(&#x27;x)} }
11 changes: 11 additions & 0 deletions test/markup/scala/using.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span></span>(<span class="hljs-keyword">using</span> x: <span class="hljs-type">Int</span>) = <span class="hljs-number">1</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">g</span></span>(<span class="hljs-keyword">using</span> <span class="hljs-type">Int</span>) = <span class="hljs-number">1</span>
<span class="hljs-keyword">given</span> (<span class="hljs-keyword">using</span> ev: <span class="hljs-type">Ev</span>): <span class="hljs-type">Foo</span> = ???

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">expressions</span> </span>=
f(<span class="hljs-keyword">using</span> <span class="hljs-number">2</span>)

<span class="hljs-comment">// not `using` keyword</span>
(using)
(using )
( using )
11 changes: 11 additions & 0 deletions test/markup/scala/using.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def f(using x: Int) = 1
def g(using Int) = 1
given (using ev: Ev): Foo = ???

def expressions =
f(using 2)

// not `using` keyword
(using)
(using )
( using )

0 comments on commit c6f7de9

Please sign in to comment.