diff --git a/CHANGES.md b/CHANGES.md index 978c6dbc81..bbe08e3279 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/languages/scala.js b/src/languages/scala.js index 0dee48c0d7..bd79fce38c 100644 --- a/src/languages/scala.js +++ b/src/languages/scala.js @@ -6,6 +6,8 @@ Contributors: Erik Osheim Website: https://www.scala-lang.org */ +import * as regex from '../lib/regex.js'; + export default function(hljs) { const ANNOTATION = { className: 'meta', @@ -107,8 +109,7 @@ export default function(hljs) { const METHOD = { className: 'function', beginKeywords: 'def', - end: /[:={\[(\n;]/, - excludeEnd: true, + end: regex.lookahead(/[:={\[(\n;]/), contains: [ NAME ] }; @@ -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: { @@ -163,6 +175,7 @@ export default function(hljs) { EXTENSION, END, ...INLINE_MODES, + 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) + + // not `using` keyword + (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 )