diff runtime/syntax/java.vim @ 34514:728675946924

runtime(java): Recognise string templates (#14150) Commit: https://github.com/vim/vim/commit/a2c65809dafe5c4f45f278fddf368c7c971d83e9 Author: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com> Date: Sat Mar 9 20:03:11 2024 +0300 runtime(java): Recognise string templates (https://github.com/vim/vim/issues/14150) As this is encouraged in the referenced JEPs, "to visually distinguish a string template from a string literal, and a text block template from a text block", the default colours for java\%[Debug]StrTempl are made distinct from java\%[Debug]String. According to ?3.2 Lexical Translations (JLS, c. 1996 or any more recent version), line terminators, white space, and comments are discarded before tokens are accepted. Since a template expression comprises a template processor, a dot, and a template, it may be visually appealing to break up its head across a few lines whenever its tail already spans multiple lines. Curiously, no allowance for it is made in the distributed tests for OpenJDK 21; the proposed regexp patterns take in consideration a line terminator and white space after a dot. References: https://openjdk.org/jeps/430 (Preview) https://openjdk.org/jeps/459 (Second Preview) https://openjdk.org/jeps/465 Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 09 Mar 2024 18:15:04 +0100
parents f5d114f7440e
children b0d91b836400
line wrap: on
line diff
--- a/runtime/syntax/java.vim
+++ b/runtime/syntax/java.vim
@@ -2,7 +2,7 @@
 " Language:	Java
 " Maintainer:	Claudio Fleiner <claudio@fleiner.com>
 " URL:          https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
-" Last Change:	2024 Mar 02
+" Last Change:	2024 Mar 06
 
 " Please check :help java.vim for comments on some of the options available.
 
@@ -187,8 +187,8 @@ if exists("java_comment_strings")
   syn match   javaCommentCharacter contained "'\\[^']\{1,6\}'" contains=javaSpecialChar
   syn match   javaCommentCharacter contained "'\\''" contains=javaSpecialChar
   syn match   javaCommentCharacter contained "'[^\\]'"
-  syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber
-  syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber
+  syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber,javaStrTempl
+  syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber,javaStrTempl
 endif
 
 syn region  javaComment		 start="/\*"  end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
@@ -234,6 +234,9 @@ syn match   javaSpecialChar	 contained "
 syn region  javaString		start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
 syn region  javaString		start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
 syn match   javaTextBlockError	+"""\s*"""+
+syn region  javaStrTemplEmbExp	 contained matchgroup=javaStrTempl start="\\{" end="}" contains=TOP
+syn region  javaStrTempl	 start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,@Spell
+syn region  javaStrTempl	 start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaStrTemplEmbExp,javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
 " The next line is commented out, it can cause a crash for a long line
 "syn match   javaStringError	  +"\%([^"\\]\|\\.\)*$+
 syn match   javaCharacter	 "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
@@ -254,7 +257,7 @@ syn match   javaNumber		 "\<0[xX]\%(\x\%
 " Unicode characters
 syn match   javaSpecial "\\u\x\x\x\x"
 
-syn cluster javaTop add=javaString,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
+syn cluster javaTop add=javaString,javaStrTempl,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
 
 if exists("java_highlight_functions")
   if java_highlight_functions == "indent"
@@ -280,7 +283,12 @@ if exists("java_highlight_debug")
   syn match   javaDebugSpecial		contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
   syn region  javaDebugString		contained start=+"+  end=+"+  contains=javaDebugSpecial
   syn region  javaDebugString		contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
-" The next line is commented out, it can cause a crash for a long line
+  " The highlight groups of java{StrTempl,Debug{,Paren,StrTempl}}\,
+  " share one colour by default. Do not conflate unrelated parens.
+  syn region  javaDebugStrTemplEmbExp	contained matchgroup=javaDebugStrTempl start="\\{" end="}" contains=javaComment,javaLineComment,javaDebug\%(Paren\)\@!.*
+  syn region  javaDebugStrTempl		contained start=+\%(\.[[:space:]\n]*\)\@<="+ end=+"+ contains=javaDebugStrTemplEmbExp,javaDebugSpecial
+  syn region  javaDebugStrTempl		contained start=+\%(\.[[:space:]\n]*\)\@<="""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugStrTemplEmbExp,javaDebugSpecial,javaDebugTextBlockError
+  " The next line is commented out, it can cause a crash for a long line
 " syn match   javaDebugStringError	contained +"\%([^"\\]\|\\.\)*$+
   syn match   javaDebugTextBlockError	contained +"""\s*"""+
   syn match   javaDebugCharacter	contained "'[^\\]'"
@@ -307,6 +315,7 @@ if exists("java_highlight_debug")
 
   hi def link javaDebug		 Debug
   hi def link javaDebugString		 DebugString
+  hi def link javaDebugStrTempl		 Macro
   hi def link javaDebugStringError	 javaError
   hi def link javaDebugTextBlockError	 javaDebugStringError
   hi def link javaDebugType		 DebugType
@@ -376,6 +385,7 @@ hi def link javaSpecial		Special
 hi def link javaSpecialError		Error
 hi def link javaSpecialCharError	Error
 hi def link javaString			String
+hi def link javaStrTempl		Macro
 hi def link javaCharacter		Character
 hi def link javaSpecialChar		SpecialChar
 hi def link javaNumber			Number