changeset 34468:f5d114f7440e

runtime(java): Recognise text blocks (#14128) Commit: https://github.com/vim/vim/commit/b3030b653bbdc08c91138001d1987d804f6ebf46 Author: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com> Date: Sun Mar 3 17:51:01 2024 +0300 runtime(java): Recognise text blocks (https://github.com/vim/vim/issues/14128) Also, accept as valid the space escape sequence `\s`. Also, consistently use the claimed `javaDebug` prefix for syntax group definitions kept under `g:java_highlight_debug`. Since `javaStringError` is commented out for its generality, let's comment out `javaDebugStringError`, its copy, as well. References: https://openjdk.org/jeps/378 https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#jls-3.10.7 Closes #10910. Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sun, 03 Mar 2024 16:00:10 +0100
parents 95da9260ac66
children 055c08ca0446
files runtime/syntax/java.vim runtime/syntax/testdir/dumps/java_escapes_00.dump runtime/syntax/testdir/dumps/java_escapes_01.dump runtime/syntax/testdir/dumps/java_string_00.dump runtime/syntax/testdir/dumps/java_string_01.dump runtime/syntax/testdir/dumps/java_string_02.dump runtime/syntax/testdir/dumps/java_string_99.dump runtime/syntax/testdir/input/java_escapes.java runtime/syntax/testdir/input/java_string.java
diffstat 9 files changed, 147 insertions(+), 14 deletions(-) [+]
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 01
+" Last Change:	2024 Mar 02
 
 " Please check :help java.vim for comments on some of the options available.
 
@@ -179,15 +179,18 @@ syn cluster javaTop add=javaExternal,jav
 
 " Comments
 syn keyword javaTodo		 contained TODO FIXME XXX
+
 if exists("java_comment_strings")
   syn region  javaCommentString    contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell
-  syn region  javaComment2String   contained start=+"+	end=+$\|"+  contains=javaSpecial,javaSpecialChar,@Spell
+  syn region  javaCommentString    contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecial,javaCommentStar,javaSpecialChar,@Spell,javaSpecialError,javaTextBlockError
+  syn region  javaComment2String   contained start=+"+ end=+$\|"+ contains=javaSpecial,javaSpecialChar,@Spell
   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
 endif
+
 syn region  javaComment		 start="/\*"  end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
 syn match   javaCommentStar	 contained "^\s*\*[^/]"me=e-1
 syn match   javaCommentStar	 contained "^\s*\*$"
@@ -227,10 +230,12 @@ syn match   javaComment		 "/\*\*/"
 syn match   javaSpecialError	 contained "\\."
 syn match   javaSpecialCharError contained "[^']"
 " Escape Sequences (JLS-17, ยง3.10.7):
-syn match   javaSpecialChar	 contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[btnfr"'\\]\)"
+syn match   javaSpecialChar	 contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
 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*"""+
 " The next line is commented out, it can cause a crash for a long line
-"syn match   javaStringError	  +"\([^"\\]\|\\.\)*$+
+"syn match   javaStringError	  +"\%([^"\\]\|\\.\)*$+
 syn match   javaCharacter	 "'[^']*'" contains=javaSpecialChar,javaSpecialCharError
 syn match   javaCharacter	 "'\\''" contains=javaSpecialChar
 syn match   javaCharacter	 "'[^\\]'"
@@ -249,7 +254,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
+syn cluster javaTop add=javaString,javaCharacter,javaNumber,javaSpecial,javaStringError,javaTextBlockError
 
 if exists("java_highlight_functions")
   if java_highlight_functions == "indent"
@@ -271,16 +276,18 @@ if exists("java_highlight_functions")
 endif
 
 if exists("java_highlight_debug")
-
   " Strings and constants
-  syn match   javaDebugSpecial		contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[btnfr"'\\]\)"
+  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 match   javaDebugStringError	contained +"\%([^"\\]\|\\.\)*$+
+  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
+" syn match   javaDebugStringError	contained +"\%([^"\\]\|\\.\)*$+
+  syn match   javaDebugTextBlockError	contained +"""\s*"""+
   syn match   javaDebugCharacter	contained "'[^\\]'"
   syn match   javaDebugSpecialCharacter contained "'\\.'"
   syn match   javaDebugSpecialCharacter contained "'\\''"
   syn keyword javaDebugNumber		contained 0 0l 0L
-  syn match   javaNumber		contained "\<\d\%(_*\d\)*\."
+  syn match   javaDebugNumber		contained "\<\d\%(_*\d\)*\."
   syn match   javaDebugNumber		contained "\<\%(0\%([xX]\x\%(_*\x\)*\|_*\o\%(_*\o\)*\|[bB][01]\%(_*[01]\)*\)\|[1-9]\%(_*\d\)*\)[lL]\=\>"
   syn match   javaDebugNumber		contained "\%(\<\d\%(_*\d\)*\.\%(\d\%(_*\d\)*\)\=\|\.\d\%(_*\d\)*\)\%([eE][-+]\=\d\%(_*\d\)*\)\=[fFdD]\=\>"
   syn match   javaDebugNumber		contained "\<\d\%(_*\d\)*[eE][-+]\=\d\%(_*\d\)*[fFdD]\=\>"
@@ -301,6 +308,7 @@ if exists("java_highlight_debug")
   hi def link javaDebug		 Debug
   hi def link javaDebugString		 DebugString
   hi def link javaDebugStringError	 javaError
+  hi def link javaDebugTextBlockError	 javaDebugStringError
   hi def link javaDebugType		 DebugType
   hi def link javaDebugBoolean		 DebugBoolean
   hi def link javaDebugNumber		 Debug
@@ -373,6 +381,7 @@ hi def link javaSpecialChar		SpecialChar
 hi def link javaNumber			Number
 hi def link javaError			Error
 hi def link javaStringError		Error
+hi def link javaTextBlockError		javaStringError
 hi def link javaStatement		Statement
 hi def link javaOperator		Operator
 hi def link javaComment		Comment
--- a/runtime/syntax/testdir/dumps/java_escapes_00.dump
+++ b/runtime/syntax/testdir/dumps/java_escapes_00.dump
@@ -11,7 +11,7 @@
 @75
 @4|s+0#00e0003&|t|a|t|i|c| +0#0000000&|{| @62
 @8|c+0#00e0003&|h|a|r| +0#0000000&|e@1|[|]| |=| |{| @53
-@12|'+0#e000002&|\+0#e000e06&|b|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|t|'+0#e000002&|,+0#0000000&| @51
+@12|'+0#e000002&|\+0#e000e06&|b|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|s|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|t|'+0#e000002&|,+0#0000000&| @45
 @12|'+0#e000002&|\+0#e000e06&|n|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|f|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|r|'+0#e000002&|,+0#0000000&| @45
 @12|'+0#e000002&|\+0#e000e06&|"|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|'|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&@1|'+0#e000002&|,+0#0000000&| @45
 @8|}|;| @64
--- a/runtime/syntax/testdir/dumps/java_escapes_01.dump
+++ b/runtime/syntax/testdir/dumps/java_escapes_01.dump
@@ -1,10 +1,10 @@
-| +0&#ffffff0@11|'+0#e000002&|\+0#e000e06&|b|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|t|'+0#e000002&|,+0#0000000&| @51
+| +0&#ffffff0@11|'+0#e000002&|\+0#e000e06&|b|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|s|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|t|'+0#e000002&|,+0#0000000&| @45
 @12|'+0#e000002&|\+0#e000e06&|n|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|f|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|r|'+0#e000002&|,+0#0000000&| @45
 @12|'+0#e000002&|\+0#e000e06&|"|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&|'|'+0#e000002&|,+0#0000000&| |'+0#e000002&|\+0#e000e06&@1|'+0#e000002&|,+0#0000000&| @45
 @8|}|;| @64
 @75
 @8>S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|n+0#af5f00255&|e|w| +0#0000000&|S|t|r|i|n|g|[|]| |{| @33
-@12|"+0#e000002&|\+0#e000e06&|b|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|t|"+0#e000002&|,+0#0000000&| @51
+@12|"+0#e000002&|\+0#e000e06&|b|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|s|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|t|"+0#e000002&|,+0#0000000&| @45
 @12|"+0#e000002&|\+0#e000e06&|n|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|f|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|r|"+0#e000002&|,+0#0000000&| @45
 @12|"+0#e000002&|\+0#e000e06&|"|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&|'|"+0#e000002&|,+0#0000000&| |"+0#e000002&|\+0#e000e06&@1|"+0#e000002&|,+0#0000000&| @45
 @8|}|)|;| @63
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/java_string_00.dump
@@ -0,0 +1,20 @@
+>c+0#00e0003#ffffff0|l|a|s@1| +0#0000000&|S|t|r|i|n|g|T|e|s|t|s| @57
+|{| @73
+@4|s+0#00e0003&|t|a|t|i|c| +0#0000000&|{| @62
+@8|S|t|r|i|n|g| |s|1| |=| |"+0#e000002&|A| |q|u|i|c|k| |b|r|o|w|n| |f|o|x| |j|u|m|p|s| |o|v|e|r| |t|h|e| |l|a|z|y| |d|o|g|"|;+0#0000000&| @10
+@8|S|t|r|i|n|g| |s|2| |=| |"+0#e000002&|\+0#e000e06&|"|W+0#e000002&|o@1|f|\+0#e000e06&|s|!+0#e000002&|\+0#e000e06&|"|"+0#e000002&|;+0#0000000&| @40
+@8|S|t|r|i|n|g| |s|3| |=| |"@2| @51
+| +0#e000002&@11|A|\+0#e000e06&|s|\+0#e000002&| +0#0000000&@58
+| +0#e000002&@11|q|u|i|c|k| |\| +0#0000000&@55
+| +0#e000002&@11|b|r|o|w|n|\+0#e000e06&|s|\+0#e000002&| +0#0000000&@54
+| +0#e000002&@11|f|o|x| |\| +0#0000000&@57
+| +0#e000002&@11|j|u|m|p|s|\+0#e000e06&|s|\+0#e000002&| +0#0000000&@54
+| +0#e000002&@11|o|v|e|r| |\| +0#0000000&@56
+| +0#e000002&@11|t|h|e|\+0#e000e06&|s|\+0#e000002&| +0#0000000&@56
+| +0#e000002&@11|l|a|z|y| |\| +0#0000000&@56
+| +0#e000002&@11|d|o|g|"+0#0000000&@2|;| @55
+@8|S|t|r|i|n|g| |s|4| |=| |"@2| @51
+| +0#e000002&@11|"|W|o@1|f|\+0#e000e06&|s|!+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|;| @48
+@8|S|t|r|i|n|g| |s|5| |=| |"@2| @51
+| +0#e000002&@7|S|t|r|i|n|g| |s|3| |=| |\+0#e000e06&|"|"+0#e000002&@1| +0#0000000&@50
+@57|1|,|1| @10|T|o|p| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/java_string_01.dump
@@ -0,0 +1,20 @@
+| +0#e000002#ffffff0@11|l|a|z|y| |\| +0#0000000&@56
+| +0#e000002&@11|d|o|g|"+0#0000000&@2|;| @55
+@8|S|t|r|i|n|g| |s|4| |=| |"@2| @51
+| +0#e000002&@11|"|W|o@1|f|\+0#e000e06&|s|!+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|;| @48
+@8|S|t|r|i|n|g| |s|5| |=| |"@2| @51
+| +0#e000002&@7>S|t|r|i|n|g| |s|3| |=| |\+0#e000e06&|"|"+0#e000002&@1| +0#0000000&@50
+| +0#e000002&@11|A|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@56
+| +0#e000002&@11|q|u|i|c|k| |\+0#e000e06&@1| +0#0000000&@54
+| +0#e000002&@11|b|r|o|w|n|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@52
+| +0#e000002&@11|f|o|x| |\+0#e000e06&@1| +0#0000000&@56
+| +0#e000002&@11|j|u|m|p|s|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@52
+| +0#e000002&@11|o|v|e|r| |\+0#e000e06&@1| +0#0000000&@55
+| +0#e000002&@11|t|h|e|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@54
+| +0#e000002&@11|l|a|z|y| |\+0#e000e06&@1| +0#0000000&@55
+| +0#e000002&@11|d|o|g|\+0#e000e06&|"|"+0#e000002&@1|;|"+0#0000000&@2|;| @50
+@75
+@8|/+0#0000e05&@1| |T|h|e|r|e| |a|r|e| |S|P|A|C|E|,| |F@1|,| |H|T|,| |C|R|,| |a|n|d| |L|F| |a|f|t|e|r| |"@2|.| +0#0000000&@17
+@8|S|t|r|i|n|g| |e|m|p|t|y| |=| |"@2| |^+0#0000e05&|L| +0#0000000&@2|^+0#0000e05&|M| +0#0000000&@40
+| +0#e000002&@11|"+0#0000000&@2|;| @58
+@57|1|9|,|3|-|9| @7|5|2|%| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/java_string_02.dump
@@ -0,0 +1,20 @@
+| +0#e000002#ffffff0@11|"+0#0000000&@2|;| @58
+@75
+@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"@2| @44
+| +0#e000002&@7|"| +0#0000000&@65
+| +0#e000002&@7|"@1| +0#0000000&@64
+| +0#e000002&@7>"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&| +0#0000000&@57
+| +0#e000002&@7|"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&@1| +0#0000000&@56
+| +0#e000002&@7|"@1|\+0#e000e06&|"|\|u|0@1|2@1|\|u|0@1|2@1| +0#0000000&@50
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1| +0#0000000&@48
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&| +0#0000000&@57
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|)|;| @50
+@4|}| @69
+|}| @73
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|3|7|,|3|-|9| @7|B|o|t| 
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/java_string_99.dump
@@ -0,0 +1,20 @@
+| +0#e000002#ffffff0@11|t|h|e|\+0#e000e06&@1|s+0#e000002&|\+0#e000e06&@1| +0#0000000&@54
+| +0#e000002&@11|l|a|z|y| |\+0#e000e06&@1| +0#0000000&@55
+| +0#e000002&@11|d|o|g|\+0#e000e06&|"|"+0#e000002&@1|;|"+0#0000000&@2|;| @50
+@75
+@8|/+0#0000e05&@1| |T|h|e|r|e| |a|r|e| |S|P|A|C|E|,| |F@1|,| |H|T|,| |C|R|,| |a|n|d| |L|F| |a|f|t|e|r| |"@2|.| +0#0000000&@17
+@8|S|t|r|i|n|g| |e|m|p|t|y| |=| |"@2| |^+0#0000e05&|L| +0#0000000&@2|^+0#0000e05&|M| +0#0000000&@40
+| +0#e000002&@11|"+0#0000000&@2|;| @58
+@75
+@8|S|y|s|t|e|m|.|o|u|t|.|p|r|i|n|t|l|n|(|"@2| @44
+| +0#e000002&@7|"| +0#0000000&@65
+| +0#e000002&@7|"@1| +0#0000000&@64
+| +0#e000002&@7|"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&| +0#0000000&@57
+| +0#e000002&@7|"@1|\+0#e000e06&|u|0@1|5|c|"+0#e000002&@1| +0#0000000&@56
+| +0#e000002&@7|"@1|\+0#e000e06&|"|\|u|0@1|2@1|\|u|0@1|2@1| +0#0000000&@50
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|u|0@1|5|c|\|u|0@1|2@1| +0#0000000&@48
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&| +0#0000000&@57
+| +0#e000002&@7|"@1|\+0#e000e06&|"|"+0#e000002&@1|\+0#e000e06&|"|"+0#e000002&|\+0#e000e06&|"|"+0#0000000&@2|)|;| @50
+@4|}| @69
+>}| @73
+@57|4@1|,|1| @9|B|o|t| 
--- a/runtime/syntax/testdir/input/java_escapes.java
+++ b/runtime/syntax/testdir/input/java_escapes.java
@@ -11,13 +11,13 @@ class EscapesTests
 
 	static {
 		char ee[] = {
-			'\b', '\t',
+			'\b', '\s', '\t',
 			'\n', '\f', '\r',
 			'\"', '\'', '\\',
 		};
 
 		System.out.println(new String[] {
-			"\b", "\t",
+			"\b", "\s", "\t",
 			"\n", "\f", "\r",
 			"\"", "\'", "\\",
 		});
new file mode 100644
--- /dev/null
+++ b/runtime/syntax/testdir/input/java_string.java
@@ -0,0 +1,44 @@
+class StringTests
+{
+	static {
+		String s1 = "A quick brown fox jumps over the lazy dog";
+		String s2 = "\"Woof\s!\"";
+		String s3 = """
+			A\s\
+			quick \
+			brown\s\
+			fox \
+			jumps\s\
+			over \
+			the\s\
+			lazy \
+			dog""";
+		String s4 = """
+			"Woof\s!\"""";
+		String s5 = """
+		String s3 = \"""
+			A\\s\\
+			quick \\
+			brown\\s\\
+			fox \\
+			jumps\\s\\
+			over \\
+			the\\s\\
+			lazy \\
+			dog\""";""";
+
+		// There are SPACE, FF, HT, CR, and LF after """.
+		String empty = """ 	
+			""";
+
+		System.out.println("""
+		"
+		""
+		""\u005c"
+		""\u005c""
+		""\"\u0022\u0022
+		""\"""\u005c\u0022
+		""\"""\""
+		""\"""\""\"""");
+	}
+}