From 2d46cb53adc4e750d35657a6302f1e9e646d0bf0 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Fri, 16 Jun 2017 11:14:56 -0700 Subject: [PATCH 01/23] Remove date field in header Remove the "Last Change" field from cpp files. Despite multiple updates this year, both files had last changed marked as 2016. (Obviously the effort to update these files is not worth doing it. I think it's better to not be misleading.) Not changing c.vim because that date is being updated by Bram. This change was motivated by finding these files inside vim-polyglot and trying to find out where and when they're from. Better to provide less information than incorrect information. --- syntax/cpp.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 495a335..68b909b 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,6 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2016 Oct 28 " quit when a syntax file was already loaded if exists("b:current_syntax") From 9344c8e190ec3a9219b11f1559d428befcbc981f Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Mon, 14 Aug 2017 19:05:10 -0700 Subject: [PATCH 02/23] add support for shared_ptr casts Note that this commit also introduces a new config variable, cpp_no_cpp17. --- syntax/cpp.vim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 68b909b..06fd9af 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -41,6 +41,8 @@ if !exists("cpp_no_cpp11") syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell + syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1 + syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$" endif " C++ 14 extensions @@ -52,6 +54,12 @@ if !exists("cpp_no_cpp14") syn case match endif +" C++ 17 extensions +if !exists("cpp_no_cpp17") + syn match cppCast "\]?" From a6bfc592af16e1c90ca2f445e2df8fc553265c1a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 4 Dec 2019 10:57:49 +0100 Subject: [PATCH 03/23] Add C++20 extensions for cpp.vim --- syntax/cpp.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 68b909b..974fa17 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -52,6 +52,15 @@ if !exists("cpp_no_cpp14") syn case match endif +" C++ 20 extensions +if !exists("cpp_no_cpp20") + syn keyword cppStatement co_await co_return co_yield requires + syn keyword cppStorageClass consteval constinit + syn keyword cppStructure concept + syn keyword cppType char8_t + syn keyword cppModule import module export +endif + " The minimum and maximum operators in GNU C++ syn match cppMinMax "[<>]?" @@ -70,6 +79,7 @@ hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String hi def link cppNumber Number +hi def link cppModule Include let b:current_syntax = "cpp" From 567e85f141a03f0de1e76d707e639ba7180d7fa8 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 17 Dec 2019 19:36:34 +0900 Subject: [PATCH 04/23] Sync upstream --- syntax/c.vim | 95 ++++++++++++++++++++++++++++++-------------------- syntax/cpp.vim | 4 +-- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/syntax/c.vim b/syntax/c.vim index 16c7ce4..79c12ab 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: C " Maintainer: Bram Moolenaar -" Last Change: 2016 Nov 18 +" Last Change: 2019 Nov 29 " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") @@ -13,6 +13,14 @@ set cpo&vim let s:ft = matchstr(&ft, '^\([^.]\)\+') +" Optional embedded Autodoc parsing +" To enable it add: let g:c_autodoc = 1 +" to your .vimrc +if exists("c_autodoc") + syn include @cAutodoc :p:h/autodoc.vim + unlet b:current_syntax +endif + " A bunch of useful C keywords syn keyword cStatement goto break return continue asm syn keyword cLabel case default @@ -129,7 +137,7 @@ if exists("c_no_curly_error") syn match cParenError display ")" syn match cErrInParen display contained "^^<%\|^%>" else - syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell + syn region cParen transparent start='(' end=')' contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell syn match cParenError display ")" @@ -212,7 +220,7 @@ if exists("c_comment_strings") syn match cCommentSkip contained "^\s*\*\($\|\s\+\)" syn region cCommentString contained start=+L\=\\\@" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell syn region cPreProc start="^\s*\zs\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell +" Optional embedded Autodoc parsing +if exists("c_autodoc") + syn match cAutodocReal display contained "\%(//\|[/ \t\v]\*\|^\*\)\@2<=!.*" contains=@cAutodoc containedin=cComment,cCommentL + syn cluster cCommentGroup add=cAutodocReal + syn cluster cPreProcGroup add=cAutodocReal +endif + " Highlight User Labels syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString if s:ft ==# 'c' || exists("cpp_no_cpp11") @@ -450,6 +470,7 @@ hi def link cErrInBracket cError hi def link cCommentError cError hi def link cCommentStartError cError hi def link cSpaceError cError +hi def link cWrongComTail cError hi def link cSpecialError cError hi def link cCurlyError cError hi def link cOperator Operator diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 5a478fb..9cb0860 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2016 Oct 28 +" Last Change: 2017 Jun 05 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -48,7 +48,7 @@ endif if !exists("cpp_no_cpp14") syn case ignore syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>" syn case match endif From 432b2fc57e3d72e61e94830de7b4e9be35ba990c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 17 Dec 2019 19:39:02 +0900 Subject: [PATCH 05/23] Rebase from upstream --- syntax/c.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/syntax/c.vim b/syntax/c.vim index 52193a6..79c12ab 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -382,17 +382,17 @@ if !exists("c_no_if0") else syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell endif - syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\zs\(%:\|#\)\s*\(else\|elif\)" end="^\s*\zs\(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit + syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit syn region cCppInWrapper start="^\s*\zs\(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold - syn region cCppInIf contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\zs\(%:\|#\)\s*endif\>" contains=TOP,cPreCondit + syn region cCppInIf contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\(%:\|#\)\s*endif\>" contains=TOP,cPreCondit if !exists("c_no_if0_fold") - syn region cCppInElse contained start="^\s*\zs\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold + syn region cCppInElse contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold else - syn region cCppInElse contained start="^\s*\zs\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 + syn region cCppInElse contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 endif - syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\zs\(%:\|#\)\s*\(else\|elif\)\([^/]\|/[^/*]\)*" end="^\s*\zs\(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell - syn region cCppOutSkip contained start="^\s*\zs\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\zs\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip - syn region cCppInSkip contained matchgroup=cCppInWrapper start="^\s*\zs\(%:\|#\)\s*\(if\s\+\(\d\+\s*\($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\zs\(%:\|#\)\s*endif\>" containedin=cCppOutElse,cCppInIf,cCppInSkip contains=TOP,cPreProc + syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)\([^/]\|/[^/*]\)*" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell + syn region cCppOutSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip + syn region cCppInSkip contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(if\s\+\(\d\+\s*\($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" containedin=cCppOutElse,cCppInIf,cCppInSkip contains=TOP,cPreProc endif syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ syn match cIncluded display contained "<[^>]*>" From 0357d5d7ce9225566a8775cdbfd50131b0092e13 Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Wed, 4 Dec 2019 10:57:49 +0100 Subject: [PATCH 06/23] Add C++20 extensions for cpp.vim --- syntax/cpp.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 9cb0860..0449c07 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -53,6 +53,15 @@ if !exists("cpp_no_cpp14") syn case match endif +" C++ 20 extensions +if !exists("cpp_no_cpp20") + syn keyword cppStatement co_await co_return co_yield requires + syn keyword cppStorageClass consteval constinit + syn keyword cppStructure concept + syn keyword cppType char8_t + syn keyword cppModule import module export +endif + " The minimum and maximum operators in GNU C++ syn match cppMinMax "[<>]?" @@ -71,6 +80,7 @@ hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String hi def link cppNumber Number +hi def link cppModule Include let b:current_syntax = "cpp" From 71c7a0683781e4397086e4fbd097632c9d090038 Mon Sep 17 00:00:00 2001 From: rgreenblatt Date: Mon, 11 Jan 2021 21:19:00 -0500 Subject: [PATCH 07/23] Check if in_cpp_family rather than just cpp, also latest c.vim --- syntax/c.vim | 28 +++++++++++++++++----------- syntax/cpp.vim | 3 +++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/syntax/c.vim b/syntax/c.vim index 79c12ab..d07aaf2 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: C " Maintainer: Bram Moolenaar -" Last Change: 2019 Nov 29 +" Last Change: 2021 Jan 11 " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") @@ -13,6 +13,9 @@ set cpo&vim let s:ft = matchstr(&ft, '^\([^.]\)\+') +" check if this was included from cpp.vim +let s:in_cpp_family = exists("b:filetype_in_cpp_family") + " Optional embedded Autodoc parsing " To enable it add: let g:c_autodoc = 1 " to your .vimrc @@ -55,7 +58,7 @@ if !exists("c_no_cformat") endif " cCppString: same as cString, but ends at end of line -if s:ft ==# "cpp" && !exists("cpp_no_cpp11") && !exists("c_no_cformat") +if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat") " ISO C++11 syn region cString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend syn region cCppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell @@ -87,7 +90,7 @@ syn match cSpecialCharacter display "L\='\\\o\{1,3}'" syn match cSpecialCharacter display "'\\x\x\{1,2}'" syn match cSpecialCharacter display "L'\\x\x\+'" -if (s:ft ==# "c" && !exists("c_no_c11")) || (s:ft ==# "cpp" && !exists("cpp_no_cpp11")) +if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) " ISO C11 or ISO C++ 11 if exists("c_no_cformat") syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend @@ -130,7 +133,7 @@ endif " But avoid matching <::. syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom if exists("c_no_curly_error") - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell @@ -144,7 +147,7 @@ if exists("c_no_curly_error") syn match cErrInParen display contained "^[{}]\|^<%\|^%>" endif elseif exists("c_no_bracket_error") - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell @@ -158,7 +161,7 @@ elseif exists("c_no_bracket_error") syn match cErrInParen display contained "[{}]\|<%\|%>" endif else - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell @@ -272,12 +275,13 @@ if exists("c_gnu") syn keyword cType __label__ __complex__ __volatile__ endif -syn keyword cStructure struct union enum typedef +syn keyword cTypedef typedef +syn keyword cStructure struct union enum syn keyword cStorageClass static register auto volatile extern const if exists("c_gnu") syn keyword cStorageClass inline __attribute__ endif -if !exists("c_no_c99") && s:ft !=# 'cpp' +if !exists("c_no_c99") && !s:in_cpp_family syn keyword cStorageClass inline restrict endif if !exists("c_no_c11") @@ -311,8 +315,7 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu") if exists("c_gnu") syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__ endif - syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ - syn keyword cConstant __STDC_VERSION__ + syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__ syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN @@ -346,6 +349,8 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu") syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX stderr stdin stdout EXIT_FAILURE EXIT_SUCCESS RAND_MAX + " used in assert.h + syn keyword cConstant NDEBUG " POSIX 2001 syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ " non-POSIX signals @@ -418,7 +423,7 @@ endif syn cluster cLabelGroup contains=cUserLabel syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup -if s:ft ==# 'cpp' +if s:in_cpp_family syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup else @@ -475,6 +480,7 @@ hi def link cSpecialError cError hi def link cCurlyError cError hi def link cOperator Operator hi def link cStructure Structure +hi def link cTypedef Structure hi def link cStorageClass StorageClass hi def link cInclude Include hi def link cPreProc PreProc diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 820425b..6f5c5a8 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -9,6 +9,9 @@ if exists("b:current_syntax") finish endif +" inform C syntax that the file was included from cpp.vim +let b:filetype_in_cpp_family = 1 + " Read the C syntax to start with runtime! syntax/c.vim unlet b:current_syntax From a36fc80c236d3f4c95d0a44e3bad9be34fe79050 Mon Sep 17 00:00:00 2001 From: "K.Takata" Date: Tue, 19 Jan 2021 11:49:50 +0900 Subject: [PATCH 08/23] Sync upstream --- syntax/cpp.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 6f5c5a8..ed38913 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2017 Jun 05 +" Last Change: 2021 Jan 12 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -58,12 +58,6 @@ if !exists("cpp_no_cpp14") syn case match endif -" C++ 17 extensions -if !exists("cpp_no_cpp17") - syn match cppCast "\]?" From 617a0e4aa7dd2558e3484c5de65544d86fc6346f Mon Sep 17 00:00:00 2001 From: "K.Takata" Date: Tue, 19 Jan 2021 11:53:47 +0900 Subject: [PATCH 09/23] Sync upstream --- syntax/c.vim | 28 +++++++++++++++++----------- syntax/cpp.vim | 23 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/syntax/c.vim b/syntax/c.vim index 79c12ab..d07aaf2 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: C " Maintainer: Bram Moolenaar -" Last Change: 2019 Nov 29 +" Last Change: 2021 Jan 11 " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") @@ -13,6 +13,9 @@ set cpo&vim let s:ft = matchstr(&ft, '^\([^.]\)\+') +" check if this was included from cpp.vim +let s:in_cpp_family = exists("b:filetype_in_cpp_family") + " Optional embedded Autodoc parsing " To enable it add: let g:c_autodoc = 1 " to your .vimrc @@ -55,7 +58,7 @@ if !exists("c_no_cformat") endif " cCppString: same as cString, but ends at end of line -if s:ft ==# "cpp" && !exists("cpp_no_cpp11") && !exists("c_no_cformat") +if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat") " ISO C++11 syn region cString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend syn region cCppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell @@ -87,7 +90,7 @@ syn match cSpecialCharacter display "L\='\\\o\{1,3}'" syn match cSpecialCharacter display "'\\x\x\{1,2}'" syn match cSpecialCharacter display "L'\\x\x\+'" -if (s:ft ==# "c" && !exists("c_no_c11")) || (s:ft ==# "cpp" && !exists("cpp_no_cpp11")) +if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) " ISO C11 or ISO C++ 11 if exists("c_no_cformat") syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend @@ -130,7 +133,7 @@ endif " But avoid matching <::. syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom if exists("c_no_curly_error") - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell @@ -144,7 +147,7 @@ if exists("c_no_curly_error") syn match cErrInParen display contained "^[{}]\|^<%\|^%>" endif elseif exists("c_no_bracket_error") - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell @@ -158,7 +161,7 @@ elseif exists("c_no_bracket_error") syn match cErrInParen display contained "[{}]\|<%\|%>" endif else - if s:ft ==# 'cpp' && !exists("cpp_no_cpp11") + if s:in_cpp_family && !exists("cpp_no_cpp11") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell @@ -272,12 +275,13 @@ if exists("c_gnu") syn keyword cType __label__ __complex__ __volatile__ endif -syn keyword cStructure struct union enum typedef +syn keyword cTypedef typedef +syn keyword cStructure struct union enum syn keyword cStorageClass static register auto volatile extern const if exists("c_gnu") syn keyword cStorageClass inline __attribute__ endif -if !exists("c_no_c99") && s:ft !=# 'cpp' +if !exists("c_no_c99") && !s:in_cpp_family syn keyword cStorageClass inline restrict endif if !exists("c_no_c11") @@ -311,8 +315,7 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu") if exists("c_gnu") syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__ endif - syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ - syn keyword cConstant __STDC_VERSION__ + syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__ syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN @@ -346,6 +349,8 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu") syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX stderr stdin stdout EXIT_FAILURE EXIT_SUCCESS RAND_MAX + " used in assert.h + syn keyword cConstant NDEBUG " POSIX 2001 syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ " non-POSIX signals @@ -418,7 +423,7 @@ endif syn cluster cLabelGroup contains=cUserLabel syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup -if s:ft ==# 'cpp' +if s:in_cpp_family syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup else @@ -475,6 +480,7 @@ hi def link cSpecialError cError hi def link cCurlyError cError hi def link cOperator Operator hi def link cStructure Structure +hi def link cTypedef Structure hi def link cStorageClass StorageClass hi def link cInclude Include hi def link cPreProc PreProc diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 9cb0860..ed38913 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,13 +2,16 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2017 Jun 05 +" Last Change: 2021 Jan 12 " quit when a syntax file was already loaded if exists("b:current_syntax") finish endif +" inform C syntax that the file was included from cpp.vim +let b:filetype_in_cpp_family = 1 + " Read the C syntax to start with runtime! syntax/c.vim unlet b:current_syntax @@ -42,6 +45,8 @@ if !exists("cpp_no_cpp11") syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell + syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1 + syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$" endif " C++ 14 extensions @@ -53,6 +58,21 @@ if !exists("cpp_no_cpp14") syn case match endif +" C++ 20 extensions +if !exists("cpp_no_cpp20") + syn keyword cppStatement co_await co_return co_yield requires + syn keyword cppStorageClass consteval constinit + syn keyword cppStructure concept + syn keyword cppType char8_t + syn keyword cppModule import module export +endif + +" C++ 17 extensions +if !exists("cpp_no_cpp17") + syn match cppCast "\]?" @@ -71,6 +91,7 @@ hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String hi def link cppNumber Number +hi def link cppModule Include let b:current_syntax = "cpp" From 502a16b6bb892f5d25fc3bc11b15099539c38aaf Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Mon, 12 Apr 2021 22:59:02 +0800 Subject: [PATCH 10/23] Add C++ syntax support for user-defined literals --- syntax/cpp.vim | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index ed38913..de5e7a9 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2021 Jan 12 +" Last Change: 2021 Apr 12 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -44,7 +44,7 @@ if !exists("cpp_no_cpp11") syn keyword cppConstant ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE - syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell + syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ contains=@Spell syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$" endif @@ -52,14 +52,21 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") syn case ignore - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>" + syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ end='$' contains=cSpecial,cFormat,@Spell syn case match endif " C++ 20 extensions if !exists("cpp_no_cpp20") + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(y\|d\)\>" + syn match cppNumber display "\<0x\x\('\=\x\+\)*\(y\|d\)\>" syn keyword cppStatement co_await co_return co_yield requires syn keyword cppStorageClass consteval constinit syn keyword cppStructure concept @@ -90,7 +97,9 @@ hi def link cppBoolean Boolean hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String +hi def link cppString String hi def link cppNumber Number +hi def link cppFloat Number hi def link cppModule Include let b:current_syntax = "cpp" From 39764b5fc9ff2ee9c6ceb659deecaa85e95d49c1 Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Tue, 13 Apr 2021 22:55:34 +0800 Subject: [PATCH 11/23] Support user-defined literals on octals and 0. --- syntax/cpp.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index de5e7a9..5ad1bc9 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -56,6 +56,8 @@ if !exists("cpp_no_cpp14") syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0\o\+\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" contains=cppFloat syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ end='$' contains=cSpecial,cFormat,@Spell @@ -65,6 +67,8 @@ endif " C++ 20 extensions if !exists("cpp_no_cpp20") syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>" + syn match cppNumber display "\<0\o\+\(y\|d\)\>" + syn match cppNumber display "\<0\(y\|d\)\>" syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(y\|d\)\>" syn match cppNumber display "\<0x\x\('\=\x\+\)*\(y\|d\)\>" syn keyword cppStatement co_await co_return co_yield requires From b70920eca22a4b78aa8424e9bac60c0235fa125c Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Sat, 17 Apr 2021 00:02:25 +0800 Subject: [PATCH 12/23] Fix: user-defined suffixes are case-sensitive Fix the problem that user-defined literals are highlighted in a way that ignores the case of suffixes. Also, suffixes Ll and lL, which are rejected by compilers, are no longer highlighted as well. --- syntax/cpp.vim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 5ad1bc9..0c5406a 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -51,17 +51,15 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") - syn case ignore - syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([fl]\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0\o\+\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=ll\=\|ll\=u\|if\|il\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ end='$' contains=cSpecial,cFormat,@Spell - syn case match endif " C++ 20 extensions From 2b204b2f4b8216520d904d67e884b229da70a0cc Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Sat, 17 Apr 2021 00:21:08 +0800 Subject: [PATCH 13/23] Better specify user-defined suffixes. Two fixes: 1) allow a single `_`, which is a valid user-defined suffix; 2) use `\i`, which is more concise and arguable better (as many Unicode characters are allowed in identifiers). --- syntax/cpp.vim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 0c5406a..2de826b 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2021 Apr 12 +" Last Change: 2021 Apr 17 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -51,15 +51,15 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") - syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=\>" - syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ end='$' contains=cSpecial,cFormat,@Spell + syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif " C++ 20 extensions From 802644f2557b43772d3cc4afb94cb3530fae57c3 Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Sat, 17 Apr 2021 23:16:20 +0800 Subject: [PATCH 14/23] Simplify patterns a bit --- syntax/cpp.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 2de826b..22a91ac 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -51,14 +51,14 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") - syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FLfl]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[Ff]\|i[Ll]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif From e17fffdbc945ed4a31c59fe62f49949e0fbe8559 Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Sat, 17 Apr 2021 23:22:18 +0800 Subject: [PATCH 15/23] Fix: forms like 2u were not highlighted as cppNumber They were highlighted as cNumber only. --- syntax/cpp.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 22a91ac..3885caa 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -54,11 +54,11 @@ if !exists("cpp_no_cpp14") syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif From 289c780fbfbf2dfe7049b0cbba9c8b1ef18d5672 Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Sat, 17 Apr 2021 23:36:20 +0800 Subject: [PATCH 16/23] Fix: some supported forms were not standard Forms like 2Li or 3.0iF are accepted by GCC, but are not in the standard, and are rejected by some other compilers. Do not highlight them. --- syntax/cpp.vim | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 3885caa..3b12089 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -51,14 +51,14 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") - syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\(i\=[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[FfLl]\|i\|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 cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" + syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat + syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif From 912a74f4688ab41de7a0bc42523c9585cc6ff52a Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Tue, 4 May 2021 15:00:54 +0800 Subject: [PATCH 17/23] Fix the unintended interaction with c.vim --- syntax/cpp.vim | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 3b12089..32cec34 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -2,7 +2,7 @@ " Language: C++ " Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) " Previous Maintainer: Ken Shan -" Last Change: 2021 Apr 17 +" Last Change: 2021 May 04 " quit when a syntax file was already loaded if exists("b:current_syntax") @@ -51,24 +51,25 @@ endif " C++ 14 extensions if !exists("cpp_no_cpp14") + syn match cppNumbers display transparent "\<\d\|\.\d" contains=cppNumber,cppFloat + 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*\(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 cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" contains=cppFloat - syn match cppNumber display "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif " C++ 20 extensions if !exists("cpp_no_cpp20") - syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>" - syn match cppNumber display "\<0\o\+\(y\|d\)\>" - syn match cppNumber display "\<0\(y\|d\)\>" - syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(y\|d\)\>" - syn match cppNumber display "\<0x\x\('\=\x\+\)*\(y\|d\)\>" + 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 keyword cppStatement co_await co_return co_yield requires syn keyword cppStorageClass consteval constinit syn keyword cppStructure concept From 42ea4533364b7f5e9bf085589f0de3ffb6d83d34 Mon Sep 17 00:00:00 2001 From: Wu Yongwei Date: Tue, 4 May 2021 15:13:38 +0800 Subject: [PATCH 18/23] Add support for C++17 hexadecimal float literals --- syntax/cpp.vim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 32cec34..3ad79d5 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -63,6 +63,14 @@ if !exists("cpp_no_cpp14") syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif +" C++ 17 extensions +if !exists("cpp_no_cpp17") + syn match cppCast "\" + syn match cppFloat display contained "\<0x\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" +endif + " C++ 20 extensions if !exists("cpp_no_cpp20") syn match cppNumber display contained "\<0\(y\|d\)\>" @@ -77,12 +85,6 @@ if !exists("cpp_no_cpp20") syn keyword cppModule import module export endif -" C++ 17 extensions -if !exists("cpp_no_cpp17") - syn match cppCast "\]?" From 15b8dd1ee346d6df713ba4da1e84f0432fb5076f Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 16 Aug 2021 02:52:57 +1000 Subject: [PATCH 19/23] Fix error highlighting in valid mulitline raw string literals Fixes #56. --- syntax/cpp.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 3ad79d5..8e2c8e9 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -60,7 +60,7 @@ if !exists("cpp_no_cpp14") 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 cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" - syn region cppString start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell + syn region cppString start=+\(L\|u\|u8\|U\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell endif " C++ 17 extensions From 491499215044ce4b08eb15dca36b0fd70b5cf075 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 23 Aug 2021 22:44:10 +1000 Subject: [PATCH 20/23] Add syntax support for u8 character literals --- syntax/cpp.vim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 3ad79d5..42709df 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -69,6 +69,20 @@ if !exists("cpp_no_cpp17") syn match cppCast "\" syn match cppFloat display contained "\<0x\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'[^\\]'" + syn match cppCharacter "u8'[^']*'" contains=cSpecial + if exists("c_gnu") + syn match cppSpecialError "u8'\\[^'\"?\\abefnrtv]'" + syn match cppSpecialCharacter "u8'\\['\"?\\abefnrtv]'" + else + syn match cppSpecialError "u8'\\[^'\"?\\abfnrtv]'" + syn match cppSpecialCharacter "u8'\\['\"?\\abfnrtv]'" + endif + syn match cppSpecialCharacter display "u8'\\\o\{1,3}'" + syn match cppSpecialCharacter display "u8'\\x\x\+'" + endif " C++ 20 extensions @@ -99,6 +113,9 @@ hi def link cppType Type hi def link cppStorageClass StorageClass hi def link cppStructure Structure hi def link cppBoolean Boolean +hi def link cppCharacter cCharacter +hi def link cppSpecialCharacter cSpecialCharacter +hi def link cppSpecialError cSpecialError hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String From e955eeb11f328b4bddbfa66527fe9da1af99990b Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 23 Aug 2021 22:46:24 +1000 Subject: [PATCH 21/23] Whitespace fixes --- syntax/cpp.vim | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index 42709df..03f9eb9 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -103,26 +103,26 @@ endif syn match cppMinMax "[<>]?" " Default highlighting -hi def link cppAccess cppStatement -hi def link cppCast cppStatement +hi def link cppAccess cppStatement +hi def link cppCast cppStatement hi def link cppExceptions Exception -hi def link cppOperator Operator +hi def link cppOperator Operator hi def link cppStatement Statement -hi def link cppModifier Type -hi def link cppType Type -hi def link cppStorageClass StorageClass +hi def link cppModifier Type +hi def link cppType Type +hi def link cppStorageClass StorageClass hi def link cppStructure Structure -hi def link cppBoolean Boolean -hi def link cppCharacter cCharacter -hi def link cppSpecialCharacter cSpecialCharacter -hi def link cppSpecialError cSpecialError -hi def link cppConstant Constant +hi def link cppBoolean Boolean +hi def link cppCharacter cCharacter +hi def link cppSpecialCharacter cSpecialCharacter +hi def link cppSpecialError cSpecialError +hi def link cppConstant Constant hi def link cppRawStringDelimiter Delimiter hi def link cppRawString String -hi def link cppString String -hi def link cppNumber Number -hi def link cppFloat Number -hi def link cppModule Include +hi def link cppString String +hi def link cppNumber Number +hi def link cppFloat Number +hi def link cppModule Include let b:current_syntax = "cpp" From fd95282ade646759dffed24af64c657285094fdf Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 23 Aug 2021 23:37:26 +0900 Subject: [PATCH 22/23] Merge vim/runtime/syntax/c.vim --- syntax/c.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syntax/c.vim b/syntax/c.vim index d07aaf2..20f8632 100644 --- a/syntax/c.vim +++ b/syntax/c.vim @@ -1,7 +1,7 @@ " Vim syntax file " Language: C " Maintainer: Bram Moolenaar -" Last Change: 2021 Jan 11 +" Last Change: 2021 May 24 " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") @@ -414,6 +414,9 @@ if exists("c_autodoc") syn cluster cPreProcGroup add=cAutodocReal endif +" be able to fold #pragma regions +syn region cPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold + " Highlight User Labels syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString if s:ft ==# 'c' || exists("cpp_no_cpp11") From 14906011df332c191f52f9abb84f375ea11590bf Mon Sep 17 00:00:00 2001 From: Dominique Pelle Date: Fri, 20 Jan 2023 22:33:50 +0100 Subject: [PATCH 23/23] fix: incorrect syntax highlighting of literals (fixes #62) --- syntax/cpp.vim | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/syntax/cpp.vim b/syntax/cpp.vim index ee3b86f..2026225 100644 --- a/syntax/cpp.vim +++ b/syntax/cpp.vim @@ -55,11 +55,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*\(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 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*\([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 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 @@ -67,8 +67,8 @@ endif if !exists("cpp_no_cpp17") syn match cppCast "\" - 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'[^\\]'" @@ -82,7 +82,6 @@ if !exists("cpp_no_cpp17") endif syn match cppSpecialCharacter display "u8'\\\o\{1,3}'" syn match cppSpecialCharacter display "u8'\\x\x\+'" - endif " C++ 20 extensions @@ -90,8 +89,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