mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
vim-patch:a2c65809dafe
runtime(java): Recognise string templates (vim/vim#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
a2c65809da
Co-authored-by: Aliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
" Language: Java
|
" Language: Java
|
||||||
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
|
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
|
||||||
" URL: https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
|
" 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.
|
" 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 "'\\[^']\{1,6\}'" contains=javaSpecialChar
|
||||||
syn match javaCommentCharacter contained "'\\''" contains=javaSpecialChar
|
syn match javaCommentCharacter contained "'\\''" contains=javaSpecialChar
|
||||||
syn match javaCommentCharacter contained "'[^\\]'"
|
syn match javaCommentCharacter contained "'[^\\]'"
|
||||||
syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber
|
syn cluster javaCommentSpecial add=javaCommentString,javaCommentCharacter,javaNumber,javaStrTempl
|
||||||
syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber
|
syn cluster javaCommentSpecial2 add=javaComment2String,javaCommentCharacter,javaNumber,javaStrTempl
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
|
syn region javaComment start="/\*" end="\*/" contains=@javaCommentSpecial,javaTodo,@Spell
|
||||||
@@ -234,6 +234,9 @@ syn match javaSpecialChar contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstn
|
|||||||
syn region javaString start=+"+ end=+"+ end=+$+ contains=javaSpecialChar,javaSpecialError,@Spell
|
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 region javaString start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaSpecialChar,javaSpecialError,javaTextBlockError,@Spell
|
||||||
syn match javaTextBlockError +"""\s*"""+
|
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
|
" 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,javaSpecialCharError
|
||||||
@@ -254,7 +257,7 @@ syn match javaNumber "\<0[xX]\%(\x\%(_*\x\)*\.\=\|\%(\x\%(_*\x\)*\)\=\.\x\%(
|
|||||||
" Unicode characters
|
" Unicode characters
|
||||||
syn match javaSpecial "\\u\x\x\x\x"
|
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 exists("java_highlight_functions")
|
||||||
if java_highlight_functions == "indent"
|
if java_highlight_functions == "indent"
|
||||||
@@ -280,6 +283,11 @@ if exists("java_highlight_debug")
|
|||||||
syn match javaDebugSpecial contained "\\\%(u\x\x\x\x\|[0-3]\o\o\|\o\o\=\|[bstnfr"'\\]\)"
|
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=+"+ end=+"+ contains=javaDebugSpecial
|
||||||
syn region javaDebugString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
|
syn region javaDebugString contained start=+"""[ \t\x0c\r]*$+hs=e+1 end=+"""+he=s-1 contains=javaDebugSpecial,javaDebugTextBlockError
|
||||||
|
" 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
|
" The next line is commented out, it can cause a crash for a long line
|
||||||
" syn match javaDebugStringError contained +"\%([^"\\]\|\\.\)*$+
|
" syn match javaDebugStringError contained +"\%([^"\\]\|\\.\)*$+
|
||||||
syn match javaDebugTextBlockError contained +"""\s*"""+
|
syn match javaDebugTextBlockError contained +"""\s*"""+
|
||||||
@@ -307,6 +315,7 @@ if exists("java_highlight_debug")
|
|||||||
|
|
||||||
hi def link javaDebug Debug
|
hi def link javaDebug Debug
|
||||||
hi def link javaDebugString DebugString
|
hi def link javaDebugString DebugString
|
||||||
|
hi def link javaDebugStrTempl Macro
|
||||||
hi def link javaDebugStringError javaError
|
hi def link javaDebugStringError javaError
|
||||||
hi def link javaDebugTextBlockError javaDebugStringError
|
hi def link javaDebugTextBlockError javaDebugStringError
|
||||||
hi def link javaDebugType DebugType
|
hi def link javaDebugType DebugType
|
||||||
@@ -376,6 +385,7 @@ hi def link javaSpecial Special
|
|||||||
hi def link javaSpecialError Error
|
hi def link javaSpecialError Error
|
||||||
hi def link javaSpecialCharError Error
|
hi def link javaSpecialCharError Error
|
||||||
hi def link javaString String
|
hi def link javaString String
|
||||||
|
hi def link javaStrTempl Macro
|
||||||
hi def link javaCharacter Character
|
hi def link javaCharacter Character
|
||||||
hi def link javaSpecialChar SpecialChar
|
hi def link javaSpecialChar SpecialChar
|
||||||
hi def link javaNumber Number
|
hi def link javaNumber Number
|
||||||
|
Reference in New Issue
Block a user