Skip to content

Commit 335aecd

Browse files
dpellee-kwsm
authored andcommitted
runtime(cpp): Fix c++ float and integer literal syntax highlighting
closes: #8939 Co-authored-by: Eisuke Kawashima <[email protected]> Signed-off-by: Dominique Pelle <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e80a4ed commit 335aecd

4 files changed

Lines changed: 72 additions & 11 deletions

File tree

runtime/syntax/cpp.vim

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
" Previous Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp)
55
" Ken Shan <[email protected]>
66
" Last Change: 2024 May 04
7-
" 2024 May 04 by Vim Project (fix digit separator in octals and floats)
8-
" 2026 Jan 06 by Vim Project (announce adoption)
7+
" 2024 May 04 by Vim Project fix digit separator in octals and floats
8+
" 2026 Jan 06 by Vim Project orphaning announcement
9+
" 2026 Jan 08 by Vim Project highlight capital letter prefixes for numbers
910

1011
" quit when a syntax file was already loaded
1112
if exists("b:current_syntax")
@@ -59,20 +60,20 @@ if !exists("cpp_no_cpp14")
5960
syn match cppNumber display contained "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
6061
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*\)\=\>"
6162
syn match cppNumber display contained "\<0\('\=\o\+\)\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
62-
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*\)\=\>"
63-
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*\)\=\>"
64-
syn match cppFloat display contained "\<\d\('\=\d\+\)*\.\(\d\('\=\d\+\)*\)\=\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
65-
syn match cppFloat display contained "\.\d\('\=\d\+\)*\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
66-
syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
63+
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*\)\=\>"
64+
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*\)\=\>"
65+
syn match cppFloat display contained "\<\d\('\=\d\+\)*\.\(\d\('\=\d\+\)*\)\=\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
66+
syn match cppFloat display contained "\.\d\('\=\d\+\)*\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
67+
syn match cppFloat display contained "\<\d\+[Ee][-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
6768
syn region cppString start=+\(L\|u\|u8\|U\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell
6869
endif
6970

7071
" C++ 17 extensions
7172
if !exists("cpp_no_cpp17")
7273
syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
7374
syn match cppCast "\<reinterpret_pointer_cast\s*$"
74-
syn match cppFloat display contained "\<0x\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
75-
syn match cppFloat display contained "\<0x\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
75+
syn match cppFloat display contained "\<0[Xx]\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
76+
syn match cppFloat display contained "\<0[Xx]\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
7677

7778
" TODO: push this up to c.vim if/when supported in C23
7879
syn match cppCharacter "u8'[^\\]'"
@@ -94,8 +95,8 @@ if !exists("cpp_no_cpp20")
9495
syn match cppNumber display contained "\<0\(y\|d\)\>"
9596
syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\(y\|d\)\>"
9697
syn match cppNumber display contained "\<0\o\+\(y\|d\)\>"
97-
syn match cppNumber display contained "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>"
98-
syn match cppNumber display contained "\<0x\x\('\=\x\+\)*\(y\|d\)\>"
98+
syn match cppNumber display contained "\<0[Bb][01]\('\=[01]\+\)*\(y\|d\)\>"
99+
syn match cppNumber display contained "\<0[Xx]\x\('\=\x\+\)*\(y\|d\)\>"
99100
syn keyword cppStatement co_await co_return co_yield requires
100101
syn keyword cppStorageClass consteval constinit
101102
syn keyword cppStructure concept
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
>v+0#00e0003#ffffff0|o|i|d| +0#0000000&|f|o@1|(|)| @64
2+
|{| @73
3+
@4|{| @69
4+
@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&
5+
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|a| |=| |1+0#e000002&|.|0|E|2|;+0#0000000&| @49
6+
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|b| |=| |1+0#e000002&|.|0|e|2|;+0#0000000&| @49
7+
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|c| |=| |1+0#e000002&|E|2|;+0#0000000&| @51
8+
@8|d+0#00e0003&|o|u|b|l|e| +0#0000000&|d| |=| |1+0#e000002&|e|2|;+0#0000000&| @51
9+
@75
10+
@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
11+
@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
12+
@4|}| @69
13+
@75
14+
@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
15+
@4|i+0#00e0003&|n|t| +0#0000000&|a| |=| |0+0#e000002&|X|1|2|3|;+0#0000000&| @56
16+
@4|i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|x|1|2|3|;+0#0000000&| @56
17+
@75
18+
@4|i+0#00e0003&|n|t| +0#0000000&|c| |=| |0+0#e000002&|B|1|0|1|;+0#0000000&| @56
19+
@4|i+0#00e0003&|n|t| +0#0000000&|d| |=| |0+0#e000002&|b|1|0|1|;+0#0000000&| @56
20+
@57|1|,|1| @10|T|o|p|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +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
2+
@4|i+0#00e0003&|n|t| +0#0000000&|a| |=| |0+0#e000002&|X|1|2|3|;+0#0000000&| @56
3+
@4|i+0#00e0003&|n|t| +0#0000000&|b| |=| |0+0#e000002&|x|1|2|3|;+0#0000000&| @56
4+
@75
5+
@4|i+0#00e0003&|n|t| +0#0000000&|c| |=| |0+0#e000002&|B|1|0|1|;+0#0000000&| @56
6+
@4>i+0#00e0003&|n|t| +0#0000000&|d| |=| |0+0#e000002&|b|1|0|1|;+0#0000000&| @56
7+
|}| @73
8+
|~+0#4040ff13&| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|~| @73
13+
|~| @73
14+
|~| @73
15+
|~| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|~| @73
20+
| +0#0000000&@56|1|9|,|5| @9|B|o|t|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
void foo()
2+
{
3+
{
4+
// See https://en.cppreference.com/w/cpp/language/floating_literal
5+
double a = 1.0E2;
6+
double b = 1.0e2;
7+
double c = 1E2;
8+
double d = 1e2;
9+
10+
double e = 0X1ffp10;
11+
double f = 0x1ffp10;
12+
}
13+
14+
// See: https://en.cppreference.com/w/cpp/language/integer_literal
15+
int a = 0X123;
16+
int b = 0x123;
17+
18+
int c = 0B101;
19+
int d = 0b101;
20+
}

0 commit comments

Comments
 (0)