diff --git a/CHANGES.md b/CHANGES.md
index 112ed8561b..54bdc98fbf 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -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
diff --git a/src/languages/scala.js b/src/languages/scala.js
index ae84bff1f5..30c5c1d7e2 100644
--- a/src/languages/scala.js
+++ b/src/languages/scala.js
@@ -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: {
@@ -126,6 +137,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
+ USING_PARAM_CLAUSE,
ANNOTATION
]
};
diff --git a/test/markup/scala/quoted-code.expect.txt b/test/markup/scala/quoted-code.expect.txt
index 74b90ece70..b0d393b4ab 100644
--- a/test/markup/scala/quoted-code.expect.txt
+++ b/test/markup/scala/quoted-code.expect.txt
@@ -1 +1 @@
-def f(using Quotes) = '{ val x = 1; ${g('x)} }
+def f(using Quotes) = '{ val x = 1; ${g('x)} }
diff --git a/test/markup/scala/using.expect.txt b/test/markup/scala/using.expect.txt
new file mode 100644
index 0000000000..4e56803f0d
--- /dev/null
+++ b/test/markup/scala/using.expect.txt
@@ -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)
+
+
+ (using)
+ (using )
+ ( using )
diff --git a/test/markup/scala/using.txt b/test/markup/scala/using.txt
new file mode 100644
index 0000000000..51df71d1a1
--- /dev/null
+++ b/test/markup/scala/using.txt
@@ -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 )