From 7f3af1001c4e448f28183ae15915ebe5ea2984e6 Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Sun, 3 Sep 2023 18:52:50 +0200 Subject: [PATCH] Fix syntax for string literal in square brackets Since https://docs.scala-lang.org/sips/42.type.html which is implemented in scala 2.13 and in scala 3 it possible to use string literals as singleton types. So code like ``` someFunc["abc"] ``` is valid. Currently this code is not hightlighted correctly and worse if there is an unclosed `(` in the string it breaks the formating in the rest of the file. --- syntax/scala.vim | 2 +- syntax/testfile.scala | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/syntax/scala.vim b/syntax/scala.vim index bb0fe0a..f99e24b 100644 --- a/syntax/scala.vim +++ b/syntax/scala.vim @@ -180,7 +180,7 @@ hi link scalaNumber Number syn region scalaRoundBrackets start="(" end=")" skipwhite contained contains=scalaTypeDeclaration,scalaSquareBrackets,scalaRoundBrackets -syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter +syn region scalaSquareBrackets matchgroup=scalaSquareBracketsBrackets start="\[" end="\]" skipwhite nextgroup=scalaTypeExtension contains=scalaTypeDeclaration,scalaSquareBrackets,scalaTypeOperator,scalaTypeAnnotationParameter,scalaString syn match scalaTypeOperator /[-+=:<>]\+/ contained syn match scalaTypeAnnotationParameter /@\<[`_A-Za-z0-9$]\+\>/ contained hi link scalaSquareBracketsBrackets Type diff --git a/syntax/testfile.scala b/syntax/testfile.scala index 1790c6f..44815f3 100644 --- a/syntax/testfile.scala +++ b/syntax/testfile.scala @@ -171,6 +171,8 @@ class ScalaClass(i: Int = 12, b: Trait[A, Trait[B, C]]) extends B with SomeTrait def someFunc[A <: B, X =:= Y] + func["(singleton"] + val soManyEscapes = "\\\"\u0031\n\b\r\f\t" // and a comment val soManyEscapes = """\\\"\u0031\n\b\r\f\t""" // and a comment val soManyEscapes = s"\\\"\u0031\n\b\r\f\t" // and a comment