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 6, 2021
1 parent 3cc0800 commit bfa8406
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Grammars:
- enh(css/less/stylus/scss) add support for CSS Grid properties [monochromer][]
- enh(java) add support for Java Text Block (#3322) [Teletha][]
- enh(scala) add missing `do` and `then` keyword (#3323) [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
6 changes: 6 additions & 0 deletions src/languages/scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export default function(hljs) {
contains: [ NAME ]
};

const USING_PARAM_CLAUSE = {
className: 'keyword',
begin: /(?<=\(\s*)using(?=\s(?!\s*\)))/,
};

return {
name: 'Scala',
keywords: {
Expand All @@ -132,6 +137,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
USING_PARAM_CLAUSE,
ANNOTATION
]
};
Expand Down
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>
given (<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 bfa8406

Please sign in to comment.