From fa0c5412c84c08ac4c02efb6fd8de375ccb5a1ce Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 6 Sep 2021 11:08:23 +0200 Subject: [PATCH] enh(scala) add Scala 3 end soft keyword Add Scala 3 end of definition or expression. Simplified verion of /~https://github.com/scala/vscode-scala-syntax/blob/main/src/typescript/Scala.tmLanguage.ts#L599-L634. Here we only need one kind of keyword. --- CHANGES.md | 1 + src/languages/scala.js | 14 +++++++++++ test/markup/scala/end.expect.txt | 41 ++++++++++++++++++++++++++++++++ test/markup/scala/end.txt | 41 ++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 test/markup/scala/end.expect.txt create mode 100644 test/markup/scala/end.txt diff --git a/CHANGES.md b/CHANGES.md index 09b2092c87..4a9b08bdcc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,7 @@ Grammars: - 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][] +- enh(scala) add Scala 3 `end` soft keyword (#3327) [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 090c37b36f..8e58fe4ace 100644 --- a/src/languages/scala.js +++ b/src/languages/scala.js @@ -123,6 +123,19 @@ export default function(hljs) { } }; + const END = [{ + begin: [ + /^\s*/, // Is first token on the line + /end/, + /\s+/, + /(extension\b)?/, // `extension` is the only marker that follows an `end` that cannot be captured by another rule. + ], + beginScope: { + 2: "keyword", + 4: "keyword", + } + }]; + return { name: 'Scala', keywords: { @@ -138,6 +151,7 @@ export default function(hljs) { CLASS, hljs.C_NUMBER_MODE, EXTENSION, + END, ANNOTATION ] }; diff --git a/test/markup/scala/end.expect.txt b/test/markup/scala/end.expect.txt new file mode 100644 index 0000000000..a94ef8cfd8 --- /dev/null +++ b/test/markup/scala/end.expect.txt @@ -0,0 +1,41 @@ +def foo = + if (true) + () + else + () + end if + + while true do + () + end while + + for x <- xs do + () + end for + + x match + case _ => + end match +end foo + +def bar = + new Foo: + def f = () + end new +end + +val baz = + () +end val + +var baz2 = + () +end var + +extension (x: Int) + def f = 1 + def f = 2 +end extension + +class Foo: +end Foo diff --git a/test/markup/scala/end.txt b/test/markup/scala/end.txt new file mode 100644 index 0000000000..fbf16d363b --- /dev/null +++ b/test/markup/scala/end.txt @@ -0,0 +1,41 @@ +def foo = + if (true) + () + else + () + end if + + while true do + () + end while + + for x <- xs do + () + end for + + x match + case _ => + end match +end foo + +def bar = + new Foo: + def f = () + end new +end + +val baz = + () +end val + +var baz2 = + () +end var + +extension (x: Int) + def f = 1 + def f = 2 +end extension + +class Foo: +end Foo