Skip to content

Commit 4052474

Browse files
authored
runtime(java): Recognise non-ASCII identifiers (#14543)
* runtime(java): Recognise non-ASCII identifiers Also: - Remove the already commented out and less general in its definition javaFuncDef alternative. - Stop recognising some bespoke {p,trace} debugging API. Non-ASCII identifiers have been supported from the outset of the Java language. > An _identifier_ is an unlimited-length sequence of _Java > letters_ and _Java digits_, the first of which must be a > Java letter. An identifier cannot have the same spelling > (Unicode character sequence) as a keyword . . . Boolean > literal . . . or the null literal . . . > . . . . . . . . > Letters and digits may be drawn from the entire Unicode > character set . . . > . . . . . . . . > A Java letter is a character for which the method > Character.isJavaLetter . . . returns true. A Java > letter-or-digit is a character for which the method > Character.isJavaLetterOrDigit . . . returns true. > . . . . . . . . > The Java letters include . . . for historical reasons, the > ASCII underscore (_) . . . and dollar sign ($) . . . (Separate syntax tests will be written when particular parts now touched will have been further improved.) Reference: https://javaalmanac.io/jdk/1.0/langspec.pdf [§3.8] * Take on the maintenance of Java filetype and syntax files Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 05aacec commit 4052474

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ runtime/ftplugin/icon.vim @dkearns
156156
runtime/ftplugin/indent.vim @dkearns
157157
runtime/ftplugin/ishd.vim @dkearns
158158
runtime/ftplugin/j.vim @glts
159+
runtime/ftplugin/java.vim @zzzyxwvut
159160
runtime/ftplugin/javascript.vim @dkearns
160161
runtime/ftplugin/javascriptreact.vim @dkearns
161162
runtime/ftplugin/json.vim @dbarnett
@@ -397,7 +398,7 @@ runtime/syntax/icon.vim @dkearns
397398
runtime/syntax/indent.vim @dkearns
398399
runtime/syntax/j.vim @glts
399400
runtime/syntax/jargon.vim @h3xx
400-
runtime/syntax/java.vim @fleiner
401+
runtime/syntax/java.vim @zzzyxwvut
401402
runtime/syntax/javascript.vim @fleiner
402403
runtime/syntax/jsonc.vim @izhakjakov
403404
runtime/syntax/julia.vim @carlobaldassi

runtime/ftplugin/java.vim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
" Vim filetype plugin file
22
" Language: Java
3-
"
4-
" This runtime file is looking for a new maintainer.
5-
"
6-
" Former maintainer: Dan Sharp
7-
" Last Change: 2012 Mar 11
3+
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
4+
" Former Maintainer: Dan Sharp
5+
" Repository: https://github.com/zzzyxwvut/java-vim.git
6+
" Last Change: 2024 Apr 13
87
" 2024 Jan 14 by Vim Project (browsefilter)
98

109
if exists("b:did_ftplugin") | finish | endif

runtime/syntax/java.vim

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
" Vim syntax file
2-
" Language: Java
3-
" Maintainer: Claudio Fleiner <claudio@fleiner.com>
4-
" URL: https://github.com/fleiner/vim/blob/master/runtime/syntax/java.vim
5-
" Last Change: 2024 Apr 04
2+
" Language: Java
3+
" Maintainer: Aliaksei Budavei <0x000c70 AT gmail DOT com>
4+
" Former Maintainer: Claudio Fleiner <claudio@fleiner.com>
5+
" Repository: https://github.com/zzzyxwvut/java-vim.git
6+
" Last Change: 2024 Apr 13
67

78
" Please check :help java.vim for comments on some of the options available.
89

@@ -63,7 +64,7 @@ syn match javaClassDecl "\<permits\>\%(\s*(\)\@!"
6364
syn match javaClassDecl "\<record\>\%(\s*(\)\@!"
6465
syn match javaClassDecl "^class\>"
6566
syn match javaClassDecl "[^.]\s*\<class\>"ms=s+1
66-
syn match javaAnnotation "@\([_$a-zA-Z][_$a-zA-Z0-9]*\.\)*[_$a-zA-Z][_$a-zA-Z0-9]*\>" contains=javaString
67+
syn match javaAnnotation "@\%(\K\k*\.\)*\K\k*\>"
6768
syn match javaClassDecl "@interface\>"
6869
syn keyword javaBranch break continue nextgroup=javaUserLabelRef skipwhite
6970
syn match javaUserLabelRef "\k\+" contained
@@ -288,18 +289,24 @@ syn cluster javaTop add=javaString,javaStrTempl,javaCharacter,javaNumber,javaSpe
288289

289290
if exists("java_highlight_functions")
290291
if java_highlight_functions == "indent"
291-
syn match javaFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]<>]*([^-+*/]*)" contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
292-
syn region javaFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*,\s*+ end=+)+ contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
293-
syn match javaFuncDef "^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*)" contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
294-
syn region javaFuncDef start=+^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]<>]*([^-+*/]*,\s*+ end=+)+ contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
292+
syn match javaFuncDef "^\%(\t\| \%( \{6\}\)\=\)\K\%(\k\|[ .,<>\[\]]\)*([^-+*/]*)" contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
293+
syn region javaFuncDef start=+^\%(\t\| \%( \{6\}\)\=\)\K\%(\k\|[ .,<>\[\]]\)*([^-+*/]*,\s*+ end=+)+ contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,@javaClasses,javaAnnotation
295294
else
296-
" This line catches method declarations at any indentation>0, but it assumes
297-
" two things:
298-
" 1. class names are always capitalized (ie: Button)
299-
" 2. method names are never capitalized (except constructors, of course)
300-
"syn region javaFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(<[^>]*>\)\=\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*([^0-9]+ end=+)+ contains=javaScopeDecl,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses
301-
syn region javaFuncDef start=+^\s\+\%(\%(public\|protected\|private\|static\|\%(abstract\|default\)\|final\|native\|synchronized\)\s\+\)*\%(<.*>\s\+\)\?\%(\%(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\%([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\%(<[^(){}]*>\)\=\%(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+)+ contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses,javaAnnotation
295+
" This is the "style" variant (:help ft-java-syntax).
296+
"
297+
" Match arbitrarily indented method and constructor declarations
298+
" and some enum constants.
299+
"
300+
" TODO: Come back to refine and fix the parts of javaFuncDef.
301+
" TODO: Request the new regexp engine for [:upper:] and [:lower:].
302+
"
303+
" XXX: \C\<[^a-z0-9]\k*\> rejects "type", but matches "τύπος".
304+
" XXX: \C\<[^A-Z0-9]\k*\> rejects "Method", but matches "Μέθοδος".
305+
"
306+
" Match: [abstract] [<α, β>] [Τʬ][<γ>][[][]] [μΜ]ʭʭ(/* ... */);
307+
syn region javaFuncDef start=+^\s\+\%(\%(public\|protected\|private\|static\|\%(abstract\|default\)\|final\|native\|synchronized\)\s\+\)*\%(<.*>\s\+\)\=\%(\%(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\%(\K\k*\.\)*\<[^a-z0-9]\k*\>\)\%(<[^(){}]*>\)\=\%(\[\]\)*\s\+\<[^A-Z0-9]\k*\>\|\<[^a-z0-9]\k*\>\)\s*(+ end=+)+ contains=javaScopeDecl,javaConceptKind,javaType,javaStorageClass,javaComment,javaLineComment,@javaClasses,javaAnnotation
302308
endif
309+
303310
syn match javaLambdaDef "\<\K\k*\>\%(\<default\>\)\@<!\s*->"
304311
syn match javaBraces "[{}]"
305312
syn cluster javaTop add=javaFuncDef,javaBraces,javaLambdaDef
@@ -332,11 +339,13 @@ if exists("java_highlight_debug")
332339
syn keyword javaDebugType contained null this super
333340
syn region javaDebugParen start=+(+ end=+)+ contained contains=javaDebug.*,javaDebugParen
334341

335-
" to make this work you must define the highlighting for these groups
336-
syn match javaDebug "\<System\.\(out\|err\)\.print\(ln\)*\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
337-
syn match javaDebug "\<p\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
338-
syn match javaDebug "[A-Za-z][a-zA-Z0-9_]*\.printStackTrace\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
339-
syn match javaDebug "\<trace[SL]\=\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
342+
" To make this work, define the highlighting for these groups.
343+
syn match javaDebug "\<System\.\%(out\|err\)\.print\%(ln\)\=\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
344+
" FIXME: What API does "p" belong to?
345+
" syn match javaDebug "\<p\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
346+
syn match javaDebug "\<\K\k*\.printStackTrace\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
347+
" FIXME: What API do "trace*" belong to?
348+
" syn match javaDebug "\<trace[SL]\=\s*("me=e-1 contains=javaDebug.* nextgroup=javaDebugParen
340349

341350
syn cluster javaTop add=javaDebug
342351

@@ -379,8 +388,8 @@ syn match javaParenError "\]"
379388
hi def link javaParenError javaError
380389

381390
if exists("java_highlight_functions")
382-
syn match javaLambdaDef "([a-zA-Z0-9_<>\[\], \t]*)\s*->"
383-
" needs to be defined after the parenthesis error catcher to work
391+
" Make ()-matching definitions after the parenthesis error catcher.
392+
syn match javaLambdaDef "\k\@4<!(\%(\k\|[[:space:]<>?\[\]@,.]\)*)\s*->"
384393
endif
385394

386395
if !exists("java_minlines")

0 commit comments

Comments
 (0)