mirror of
https://github.com/vim/vim.git
synced 2026-05-06 12:26:58 -04:00
runtime(cpp): Fix c++ float and integer literal syntax highlighting
closes: #8939 Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com> Signed-off-by: Dominique Pelle <dominique.pelle@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
e80a4ed845
commit
335aecd98f
+12
-11
@@ -4,8 +4,9 @@
|
||||
" Previous Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp)
|
||||
" Ken Shan <ccshan@post.harvard.edu>
|
||||
" Last Change: 2024 May 04
|
||||
" 2024 May 04 by Vim Project (fix digit separator in octals and floats)
|
||||
" 2026 Jan 06 by Vim Project (announce adoption)
|
||||
" 2024 May 04 by Vim Project fix digit separator in octals and floats
|
||||
" 2026 Jan 06 by Vim Project orphaning announcement
|
||||
" 2026 Jan 08 by Vim Project highlight capital letter prefixes for numbers
|
||||
|
||||
" quit when a syntax file was already loaded
|
||||
if exists("b:current_syntax")
|
||||
@@ -59,11 +60,11 @@ if !exists("cpp_no_cpp14")
|
||||
syn match cppNumber display contained "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<0\('\=\o\+\)\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<\d\('\=\d\+\)*\.\(\d\('\=\d\+\)*\)\=\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\.\d\('\=\d\+\)*\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<0[Bb][01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppNumber display contained "\<0[Xx]\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<\d\('\=\d\+\)*\.\(\d\('\=\d\+\)*\)\=\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\.\d\('\=\d\+\)*\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<\d\+[Ee][-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn region cppString start=+\(L\|u\|u8\|U\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell
|
||||
endif
|
||||
|
||||
@@ -71,8 +72,8 @@ endif
|
||||
if !exists("cpp_no_cpp17")
|
||||
syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
|
||||
syn match cppCast "\<reinterpret_pointer_cast\s*$"
|
||||
syn match cppFloat display contained "\<0x\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<0x\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<0[Xx]\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
syn match cppFloat display contained "\<0[Xx]\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
|
||||
|
||||
" TODO: push this up to c.vim if/when supported in C23
|
||||
syn match cppCharacter "u8'[^\\]'"
|
||||
@@ -94,8 +95,8 @@ if !exists("cpp_no_cpp20")
|
||||
syn match cppNumber display contained "\<0\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<0\o\+\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<0x\x\('\=\x\+\)*\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<0[Bb][01]\('\=[01]\+\)*\(y\|d\)\>"
|
||||
syn match cppNumber display contained "\<0[Xx]\x\('\=\x\+\)*\(y\|d\)\>"
|
||||
syn keyword cppStatement co_await co_return co_yield requires
|
||||
syn keyword cppStorageClass consteval constinit
|
||||
syn keyword cppStructure concept
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
>v+0#00e0003#ffffff0|o|i|d| +0#0000000&|f|o@1|(|)| @64
|
||||
|{| @73
|
||||
@4|{| @69
|
||||
@8|/+0#0000e05&@1| |S|e@1| |h|t@1|p|s|:|/@1|e|n|.|c|p@1|r|e|f|e|r|e|n|c|e|.|c|o|m|/|w|/|c|p@1|/|l|a|n|g|u|a|g|e|/|f|l|o|a|t|i|n|g|_|l|i|t|e|r|a|l| +0#0000000&
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|a| |=| |1+0#e000002&|.|0|E|2|;+0#0000000&| @49
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|b| |=| |1+0#e000002&|.|0|e|2|;+0#0000000&| @49
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|c| |=| |1+0#e000002&|E|2|;+0#0000000&| @51
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|d| |=| |1+0#e000002&|e|2|;+0#0000000&| @51
|
||||
@75
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|e| |=| |0+0#e000002&|X|1|f@1|p|1|0|;+0#0000000&| @46
|
||||
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|f| |=| |0+0#e000002&|x|1|f@1|p|1|0|;+0#0000000&| @46
|
||||
@4|}| @69
|
||||
@75
|
||||
@4|/+0#0000e05&@1| |S|e@1|:| |h|t@1|p|s|:|/@1|e|n|.|c|p@1|r|e|f|e|r|e|n|c|e|.|c|o|m|/|w|/|c|p@1|/|l|a|n|g|u|a|g|e|/|i|n|t|e|g|e|r|_|l|i|t|e|r|a|l| +0#0000000&@4
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|a| |=| |0+0#e000002&|X|1|2|3|;+0#0000000&| @56
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|x|1|2|3|;+0#0000000&| @56
|
||||
@75
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|c| |=| |0+0#e000002&|B|1|0|1|;+0#0000000&| @56
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|d| |=| |0+0#e000002&|b|1|0|1|;+0#0000000&| @56
|
||||
@57|1|,|1| @10|T|o|p|
|
||||
@@ -0,0 +1,20 @@
|
||||
| +0&#ffffff0@3|/+0#0000e05&@1| |S|e@1|:| |h|t@1|p|s|:|/@1|e|n|.|c|p@1|r|e|f|e|r|e|n|c|e|.|c|o|m|/|w|/|c|p@1|/|l|a|n|g|u|a|g|e|/|i|n|t|e|g|e|r|_|l|i|t|e|r|a|l| +0#0000000&@4
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|a| |=| |0+0#e000002&|X|1|2|3|;+0#0000000&| @56
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|x|1|2|3|;+0#0000000&| @56
|
||||
@75
|
||||
@4|i+0#00e0003&|n|t| +0#0000000&|c| |=| |0+0#e000002&|B|1|0|1|;+0#0000000&| @56
|
||||
@4>i+0#00e0003&|n|t| +0#0000000&|d| |=| |0+0#e000002&|b|1|0|1|;+0#0000000&| @56
|
||||
|}| @73
|
||||
|~+0#4040ff13&| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
|~| @73
|
||||
| +0#0000000&@56|1|9|,|5| @9|B|o|t|
|
||||
@@ -0,0 +1,20 @@
|
||||
void foo()
|
||||
{
|
||||
{
|
||||
// See https://en.cppreference.com/w/cpp/language/floating_literal
|
||||
double a = 1.0E2;
|
||||
double b = 1.0e2;
|
||||
double c = 1E2;
|
||||
double d = 1e2;
|
||||
|
||||
double e = 0X1ffp10;
|
||||
double f = 0x1ffp10;
|
||||
}
|
||||
|
||||
// See: https://en.cppreference.com/w/cpp/language/integer_literal
|
||||
int a = 0X123;
|
||||
int b = 0x123;
|
||||
|
||||
int c = 0B101;
|
||||
int d = 0b101;
|
||||
}
|
||||
Reference in New Issue
Block a user