Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(scala) add using soft keyword #3330

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Grammars:
- enh(scala) add Scala 3 `extension` soft keyword (#3326) [Nicolas Stucki][]
- enh(scala) add Scala 3 `end` soft keyword (#3327) [Nicolas Stucki][]
- enh(scala) add `inline` soft keyword (#3329) [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
17 changes: 15 additions & 2 deletions src/languages/scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Contributors: Erik Osheim <d_m@plastic-idolatry.com>
Website: https://www.scala-lang.org
*/

import * as regex from '../lib/regex.js';

export default function(hljs) {
const ANNOTATION = {
className: 'meta',
Expand Down Expand Up @@ -107,8 +109,7 @@ export default function(hljs) {
const METHOD = {
className: 'function',
beginKeywords: 'def',
end: /[:={\[(\n;]/,
excludeEnd: true,
end: regex.lookahead(/[:={\[(\n;]/),
contains: [ NAME ]
};

Expand Down Expand Up @@ -146,6 +147,17 @@ export default function(hljs) {
keywords: 'inline'
}];

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 @@ -163,6 +175,7 @@ export default function(hljs) {
EXTENSION,
END,
...INLINE_MODES,
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 )