Skip to content

Commit

Permalink
runtime(c): Conditionally highlight C23 UTF-8 character constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dkearns committed Sep 1, 2023
1 parent 85a995d commit 7bb41c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions runtime/doc/syntax.txt
Expand Up @@ -1021,6 +1021,7 @@ Variable Highlight ~
*c_no_cformat* don't highlight %-formats in strings
*c_no_c99* don't highlight C99 standard items
*c_no_c11* don't highlight C11 standard items
*c_no_c23* don't highlight C23 standard items
*c_no_bsd* don't highlight BSD specific types

When 'foldmethod' is set to "syntax" then /* */ comments and { } blocks will
Expand Down
19 changes: 17 additions & 2 deletions runtime/syntax/c.vim
Expand Up @@ -111,6 +111,21 @@ if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_
syn match cSpecialCharacter display "[Uu]'\\x\x\+'"
endif

" TODO: c_no_c23 should default to false when C23 is widely accepted
if (s:ft ==# "c" && !get(g:, "c_no_c23", v:true)) || (s:in_cpp_family && !exists("cpp_no_cpp17"))
syn match cCharacter "u8'[^\\]'"
syn match cCharacter "u8'[^']*'" contains=cSpecial
if exists("c_gnu")
syn match cSpecialError "u8'\\[^'\"?\\abefnrtv]'"
syn match cSpecialCharacter "u8'\\['\"?\\abefnrtv]'"
else
syn match cSpecialError "u8'\\[^'\"?\\abfnrtv]'"
syn match cSpecialCharacter "u8'\\['\"?\\abfnrtv]'"
endif
syn match cSpecialCharacter display "u8'\\\o\{1,3}'"
syn match cSpecialCharacter display "u8'\\x\x\+'"
endif

"when wanted, highlight trailing white space
if exists("c_space_errors")
if !exists("c_no_trail_space_error")
Expand Down Expand Up @@ -277,7 +292,7 @@ if !exists("c_no_c99") " ISO C99
syn keyword cType intptr_t uintptr_t
syn keyword cType intmax_t uintmax_t
endif
if !get(g:, "c_no_c23", v:true) " FIXME: default to false when C23 is widely accepted
if !get(g:, "c_no_c23", v:true)
syn keyword cType _Decimal32 _Decimal64 _Decimal128
endif

Expand Down Expand Up @@ -393,7 +408,7 @@ endif
if !get(g:, "c_no_c23", v:true)
syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(el\)\=\%(if\|ifdef\|ifndef\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
else
syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
endif
syn match cPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
if !exists("c_no_if0")
Expand Down

0 comments on commit 7bb41c9

Please sign in to comment.