diff --git a/CHANGES.md b/CHANGES.md
index 112ed8561b..09b2092c87 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 Scala 3 `extension` soft keyword (#3326) [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..090c37b36f 100644
--- a/src/languages/scala.js
+++ b/src/languages/scala.js
@@ -112,6 +112,17 @@ export default function(hljs) {
contains: [ NAME ]
};
+ const EXTENSION = {
+ begin: [
+ /^\s*/, // Is first token on the line
+ 'extension',
+ /\s+(?=[[(])/, // followed by at least one space and `[` or `(`
+ ],
+ beginScope: {
+ 2: "keyword",
+ }
+ };
+
return {
name: 'Scala',
keywords: {
@@ -126,6 +137,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
+ EXTENSION,
ANNOTATION
]
};
diff --git a/test/markup/scala/extension.expect.txt b/test/markup/scala/extension.expect.txt
new file mode 100644
index 0000000000..9daa346a91
--- /dev/null
+++ b/test/markup/scala/extension.expect.txt
@@ -0,0 +1,19 @@
+extension (x: Int) def plus(y: Int) = x + y
+
+extension [T](x: T) def f = ()
+
+extension (x: Int)
+ def f = 1
+ def f = 2
+
+object Foo {
+ extension (x: Int)
+ def f = 1
+ def f = 2
+}
+
+def extension(file: File) =
+ file.extension
+
+ file
+ .extension
diff --git a/test/markup/scala/extension.txt b/test/markup/scala/extension.txt
new file mode 100644
index 0000000000..75a6327980
--- /dev/null
+++ b/test/markup/scala/extension.txt
@@ -0,0 +1,19 @@
+extension (x: Int) def plus(y: Int) = x + y
+
+extension [T](x: T) def f = ()
+
+extension (x: Int)
+ def f = 1
+ def f = 2
+
+object Foo {
+ extension (x: Int)
+ def f = 1
+ def f = 2
+}
+
+def extension(file: File) =
+ file.extension
+
+ file
+ .extension