Mercurial > vim
view runtime/syntax/xpm2.vim @ 35039:fbdb6aeca2e2
runtime(java): Improve the recognition of the "style" method declarations
Commit: https://github.com/vim/vim/commit/a4c085a3e607bd01d34e1db600b6460fc35fb0a3
Author: Aliaksei Budavei <0x000c70@gmail.com>
Date: Wed Apr 24 21:04:25 2024 +0200
runtime(java): Improve the recognition of the "style" method declarations
- Request the new regexp engine (v7.3.970) for [:upper:] and
[:lower:].
- Recognise declarations of in-line annotated methods.
- Recognise declarations of _strictfp_ methods.
- Establish partial order for method modifiers as shown in
the MethodModifier production; namely, _public_ and
friends should be written the leftmost, possibly followed
by _abstract_ or _default_, or possibly followed by other
modifiers.
- Stop looking for parameterisable primitive types (void<?>,
int<Object>, etc., are malformed).
- Stop looking for arrays of _void_.
- Acknowledge the prevailing convention for method names to
begin with a small letter and for class/interface names to
begin with a capital letter; and, therefore, desist from
claiming declarations of enum constants and constructors
with javaFuncDef.
Rationale:
+ Constructor is distinct from method:
* its (overloaded) name is not arbitrary;
* its return type is implicit;
* its _throws_ clause depends on indirect vagaries of
instance (variable) initialisers;
* its invocation makes other constructors of its type
hierarchy invoked one by one, concluding with the
primordial constructor;
* its explicit invocation, via _this_ or _super_, can
only appear as the first statement in a constructor
(not anymore, see JEP 447); else, its _super_ call
cannot appear in constructors of _record_ or _enum_;
and neither invocation is allowed for the primordial
constructor;
* it is not a member of its class, like initialisers,
and is never inherited;
* it is never _abstract_ or _native_.
+ Constructor declarations tend to be few in number and
merit visual recognition from method declarations.
+ Enum constants define a fixed set of type instances
and more resemble class variable initialisers.
Note that the code duplicated for @javaFuncParams is written
keeping in mind for g:java_highlight_functions a pending 3rd
variant, which would require none of the :syn-cluster added
groups.
closes: #14620
Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 24 Apr 2024 21:15:02 +0200 |
parents | c391bfbdb452 |
children |
line wrap: on
line source
" Vim syntax file " Language: X Pixmap v2 " Maintainer: Steve Wall (hitched97@velnet.com) " Last Change: 2017 Feb 01 " (Dominique Pelle added @Spell) " Version: 5.8 " Jemma Nelson added termguicolors support " " Made from xpm.vim by Ronald Schild <rs@scutum.de> " quit when a syntax file was already loaded if exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim syn region xpm2PixelString start="^" end="$" contains=@xpm2Colors syn keyword xpm2Todo TODO FIXME XXX contained syn match xpm2Comment "\!.*$" contains=@Spell,xpm2Todo command -nargs=+ Hi hi def <args> if has("gui_running") || has("termguicolors") && &termguicolors let color = "" let chars = "" let colors = 0 let cpp = 0 let n = 0 let i = 1 while i <= line("$") " scanning all lines let s = getline(i) if match(s,"\!.*$") != -1 let s = matchstr(s, "^[^\!]*") endif if s != "" " does line contain a string? if n == 0 " first string is the Values string " get the 3rd value: colors = number of colors let colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') " get the 4th value: cpp = number of character per pixel let cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') if cpp =~ '[^0-9]' break " if cpp is not made of digits there must be something wrong endif " Highlight the Values string as normal string (no pixel string). " Only when there is no slash, it would terminate the pattern. if s !~ '/' exe 'syn match xpm2Values /' . s . '/' endif hi def link xpm2Values Statement let n = 1 " n = color index elseif n <= colors " string is a color specification " get chars = <cpp> length string representing the pixels " (first incl. the following whitespace) let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '') " now get color, first try 'c' key if any (color visual) let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '') if color == s " no 'c' key, try 'g' key (grayscale with more than 4 levels) let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '') if color == s " next try: 'g4' key (4-level grayscale) let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '') if color == s " finally try 'm' key (mono visual) let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '') if color == s let color = "" endif endif endif endif " Vim cannot handle RGB codes with more than 6 hex digits if color =~ '#\x\{10,}$' let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g') elseif color =~ '#\x\{7,}$' let color = substitute(color, '\(\x\x\)\x', '\1', 'g') " nor with 3 digits elseif color =~ '#\x\{3}$' let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '') endif " escape meta characters in patterns let s = escape(s, '/\*^$.~[]') let chars = escape(chars, '/\*^$.~[]') " change whitespace to "\s\+" let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g") let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g") " now create syntax items " highlight the color string as normal string (no pixel string) exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef' exe 'hi def link xpm2Col'.n.'Def Constant' " but highlight the first whitespace after chars in its color exe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained' exe 'hi def link xpm2Col'.n.'inDef xpm2Color'.n " remove the following whitespace from chars let chars = substitute(chars, '\\s\\+$', '', '') " and create the syntax item contained in the pixel strings exe 'syn match xpm2Color'.n.' /'.chars.'/ contained' exe 'syn cluster xpm2Colors add=xpm2Color'.n " if no color or color = "None" show background if color == "" || substitute(color, '.*', '\L&', '') == 'none' exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE' elseif color !~ "'" exe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'" endif let n = n + 1 else break " no more color string endif endif let i = i + 1 endwhile unlet color chars colors cpp n i s endif " has("gui_running") || has("termguicolors") && &termguicolors " Define the default highlighting. " Only when an item doesn't have highlighting yet " The default highlighting. hi def link xpm2Type Type hi def link xpm2StorageClass StorageClass hi def link xpm2Todo Todo hi def link xpm2Comment Comment hi def link xpm2PixelString String delcommand Hi let b:current_syntax = "xpm2" let &cpo = s:cpo_save unlet s:cpo_save " vim: ts=8:sw=2:noet: