blob: eb56239f3d4fd221f36d1ae52b76d8800a9e2fa9 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Doug Kearnsc2a967a2025-01-17 14:12:16 +01002" Language: C
3" Maintainer: The Vim Project <https://github.com/vim/vim>
4" Last Change: 2025 Jan 15
Christian Brabandte978b452023-08-13 10:33:05 +02005" Former Maintainer: Bram Moolenaar <Bram@vim.org>
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007" Quit when a (custom) syntax file was already loaded
8if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00009 finish
10endif
11
Bram Moolenaarb6b046b2011-12-30 13:11:27 +010012let s:cpo_save = &cpo
13set cpo&vim
14
Bram Moolenaarce001a32022-04-27 15:25:03 +010015let s:ft = matchstr(&ft, '^\%([^.]\)\+')
Bram Moolenaarbc488a72013-07-05 21:01:22 +020016
Bram Moolenaar98a29d02021-01-18 19:55:44 +010017" check if this was included from cpp.vim
18let s:in_cpp_family = exists("b:filetype_in_cpp_family")
19
Bram Moolenaar40962ec2018-01-28 22:47:25 +010020" Optional embedded Autodoc parsing
21" To enable it add: let g:c_autodoc = 1
22" to your .vimrc
23if exists("c_autodoc")
24 syn include @cAutodoc <sfile>:p:h/autodoc.vim
25 unlet b:current_syntax
26endif
27
Bram Moolenaar071d4272004-06-13 20:20:40 +000028" A bunch of useful C keywords
29syn keyword cStatement goto break return continue asm
30syn keyword cLabel case default
31syn keyword cConditional if else switch
32syn keyword cRepeat while for do
33
34syn keyword cTodo contained TODO FIXME XXX
35
Bram Moolenaar5c736222010-01-06 20:54:52 +010036" It's easy to accidentally add a space after a backslash that was intended
37" for line continuation. Some compilers allow it, which makes it
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020038" unpredictable and should be avoided.
Bram Moolenaar5c736222010-01-06 20:54:52 +010039syn match cBadContinuation contained "\\\s\+$"
40
Bram Moolenaar071d4272004-06-13 20:20:40 +000041" cCommentGroup allows adding matches for special things in comments
Bram Moolenaar5c736222010-01-06 20:54:52 +010042syn cluster cCommentGroup contains=cTodo,cBadContinuation
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
44" String and Character constants
45" Highlight special characters (those which have a backslash) differently
Bram Moolenaarce001a32022-04-27 15:25:03 +010046syn match cSpecial display contained "\\\%(x\x\+\|\o\{1,3}\|.\|$\)"
Bram Moolenaar071d4272004-06-13 20:20:40 +000047if !exists("c_no_utf")
Bram Moolenaarce001a32022-04-27 15:25:03 +010048 syn match cSpecial display contained "\\\%(u\x\{4}\|U\x\{8}\)"
Bram Moolenaar071d4272004-06-13 20:20:40 +000049endif
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020050
51if !exists("c_no_cformat")
52 " Highlight % items in strings.
Bram Moolenaar18144c82006-04-12 21:52:12 +000053 if !exists("c_no_c99") " ISO C99
Bram Moolenaarce001a32022-04-27 15:25:03 +010054 syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjzt]\|ll\|hh\)\=\%([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
Bram Moolenaar18144c82006-04-12 21:52:12 +000055 else
Bram Moolenaarce001a32022-04-27 15:25:03 +010056 syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlL]\|ll\)\=\%([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
Bram Moolenaar18144c82006-04-12 21:52:12 +000057 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000058 syn match cFormat display "%%" contained
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020059endif
60
61" cCppString: same as cString, but ends at end of line
Bram Moolenaar98a29d02021-01-18 19:55:44 +010062if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020063 " ISO C++11
Bram Moolenaarce001a32022-04-27 15:25:03 +010064 syn region cString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
65 syn region cCppString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
Bram Moolenaard8b77f72015-03-05 21:21:19 +010066elseif s:ft ==# "c" && !exists("c_no_c11") && !exists("c_no_cformat")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020067 " ISO C99
68 syn region cString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
69 syn region cCppString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
70else
71 " older C or C++
Bram Moolenaard8b77f72015-03-05 21:21:19 +010072 syn match cFormat display "%%" contained
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +020073 syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
Bram Moolenaar071d4272004-06-13 20:20:40 +000074 syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
75endif
76
Bram Moolenaarce001a32022-04-27 15:25:03 +010077syn region cCppSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020078
Bram Moolenaar2f3b5102014-11-19 18:54:17 +010079syn cluster cStringGroup contains=cCppString,cCppSkip
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020080
Bram Moolenaar071d4272004-06-13 20:20:40 +000081syn match cCharacter "L\='[^\\]'"
82syn match cCharacter "L'[^']*'" contains=cSpecial
83if exists("c_gnu")
84 syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'"
85 syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'"
86else
87 syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'"
88 syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
89endif
90syn match cSpecialCharacter display "L\='\\\o\{1,3}'"
91syn match cSpecialCharacter display "'\\x\x\{1,2}'"
92syn match cSpecialCharacter display "L'\\x\x\+'"
93
Bram Moolenaar98a29d02021-01-18 19:55:44 +010094if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11"))
Bram Moolenaar3a991dd2014-10-02 01:41:41 +020095 " ISO C11 or ISO C++ 11
Bram Moolenaard8b77f72015-03-05 21:21:19 +010096 if exists("c_no_cformat")
97 syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
98 else
99 syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
100 endif
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100101 syn match cCharacter "[Uu]'[^\\]'"
102 syn match cCharacter "[Uu]'[^']*'" contains=cSpecial
103 if exists("c_gnu")
104 syn match cSpecialError "[Uu]'\\[^'\"?\\abefnrtv]'"
105 syn match cSpecialCharacter "[Uu]'\\['\"?\\abefnrtv]'"
106 else
107 syn match cSpecialError "[Uu]'\\[^'\"?\\abfnrtv]'"
108 syn match cSpecialCharacter "[Uu]'\\['\"?\\abfnrtv]'"
109 endif
110 syn match cSpecialCharacter display "[Uu]'\\\o\{1,3}'"
111 syn match cSpecialCharacter display "[Uu]'\\x\x\+'"
112endif
113
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100114if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp17"))
115 syn match cCharacter "u8'[^\\]'"
116 syn match cCharacter "u8'[^']*'" contains=cSpecial
117 if exists("c_gnu")
118 syn match cSpecialError "u8'\\[^'\"?\\abefnrtv]'"
119 syn match cSpecialCharacter "u8'\\['\"?\\abefnrtv]'"
120 else
121 syn match cSpecialError "u8'\\[^'\"?\\abfnrtv]'"
122 syn match cSpecialCharacter "u8'\\['\"?\\abfnrtv]'"
123 endif
124 syn match cSpecialCharacter display "u8'\\\o\{1,3}'"
125 syn match cSpecialCharacter display "u8'\\x\x\+'"
126endif
127
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128"when wanted, highlight trailing white space
129if exists("c_space_errors")
130 if !exists("c_no_trail_space_error")
131 syn match cSpaceError display excludenl "\s\+$"
132 endif
133 if !exists("c_no_tab_space_error")
134 syn match cSpaceError display " \+\t"me=e-1
135 endif
136endif
137
Bram Moolenaar9964e462007-05-05 17:54:07 +0000138" This should be before cErrInParen to avoid problems with #define ({ xxx })
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000139if exists("c_curly_error")
Bram Moolenaara3e6bc92013-01-30 14:18:00 +0100140 syn match cCurlyError "}"
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200141 syn region cBlock start="{" end="}" contains=ALLBUT,cBadBlock,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell fold
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000142else
Bram Moolenaara3e6bc92013-01-30 14:18:00 +0100143 syn region cBlock start="{" end="}" transparent fold
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000144endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000145
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200146" Catch errors caused by wrong parenthesis and brackets.
147" Also accept <% for {, %> for }, <: for [ and :> for ] (C99)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148" But avoid matching <::.
Bram Moolenaara3e6bc92013-01-30 14:18:00 +0100149syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
Bram Moolenaar677ee682005-01-27 14:41:15 +0000150if exists("c_no_curly_error")
Bram Moolenaar98a29d02021-01-18 19:55:44 +0100151 if s:in_cpp_family && !exists("cpp_no_cpp11")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200152 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100153 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
154 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
155 syn match cParenError display ")"
156 syn match cErrInParen display contained "^^<%\|^%>"
157 else
Bram Moolenaar91359012019-11-30 17:57:03 +0100158 syn region cParen transparent start='(' end=')' contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100159 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
160 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
161 syn match cParenError display ")"
162 syn match cErrInParen display contained "^[{}]\|^<%\|^%>"
163 endif
Bram Moolenaar677ee682005-01-27 14:41:15 +0000164elseif exists("c_no_bracket_error")
Bram Moolenaar98a29d02021-01-18 19:55:44 +0100165 if s:in_cpp_family && !exists("cpp_no_cpp11")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200166 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100167 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
168 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
169 syn match cParenError display ")"
170 syn match cErrInParen display contained "<%\|%>"
171 else
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200172 syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100173 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
174 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
175 syn match cParenError display ")"
176 syn match cErrInParen display contained "[{}]\|<%\|%>"
177 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178else
Bram Moolenaar98a29d02021-01-18 19:55:44 +0100179 if s:in_cpp_family && !exists("cpp_no_cpp11")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200180 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100181 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
182 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
183 syn match cParenError display "[\])]"
184 syn match cErrInParen display contained "<%\|%>"
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200185 syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100186 else
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200187 syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100188 " cCppParen: same as cParen but ends at end-of-line; used in cDefine
189 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
190 syn match cParenError display "[\])]"
191 syn match cErrInParen display contained "[\]{}]\|<%\|%>"
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200192 syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100193 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194 " cCppBracket: same as cParen but ends at end-of-line; used in cDefine
195 syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell
196 syn match cErrInBracket display contained "[);{}]\|<%\|%>"
197endif
198
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200199if s:ft ==# 'c' || exists("cpp_no_cpp11")
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100200 syn region cBadBlock keepend start="{" end="}" contained containedin=cParen,cBracket,cBadBlock transparent fold
201endif
Bram Moolenaar97293012011-07-18 19:40:27 +0200202
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203"integer number, or floating point number without a dot and with "f".
204syn case ignore
205syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
206" Same, but without octal error (for comments)
207syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100208
209" cpp.vim handles these
210if !exists("c_no_c23") && !s:in_cpp_family
211 syn match cNumber display contained "\d\%('\=\d\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>"
212 "hex number
213 syn match cNumber display contained "0x\x\%('\=\x\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>"
214 " Flag the first zero of an octal number as something special
215 syn match cOctal display contained "0\o\%('\=\o\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" contains=cOctalZero
216 "binary number
217 syn match cNumber display contained "0b[01]\%('\=[01]\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>"
218else
219 syn match cNumber display contained "\d\+\%(u\=l\{0,2}\|ll\=u\)\>"
220 "hex number
221 syn match cNumber display contained "0x\x\+\%(u\=l\{0,2}\|ll\=u\)\>"
222 " Flag the first zero of an octal number as something special
223 syn match cOctal display contained "0\o\+\%(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
224 syn match cOctalZero display contained "\<0"
225endif
226
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227"floating point number, with dot, optional exponent
Bram Moolenaarce001a32022-04-27 15:25:03 +0100228syn match cFloat display contained "\d\+\.\d*\%(e[-+]\=\d\+\)\=[fl]\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229"floating point number, starting with a dot, optional exponent
Bram Moolenaarce001a32022-04-27 15:25:03 +0100230syn match cFloat display contained "\.\d\+\%(e[-+]\=\d\+\)\=[fl]\=\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231"floating point number, without dot, with exponent
232syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>"
233if !exists("c_no_c99")
234 "hexadecimal floating point number, optional leading digits, with dot, with exponent
235 syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>"
236 "hexadecimal floating point number, with leading digits, optional dot, with exponent
237 syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>"
238endif
239
240" flag an octal number with wrong digits
241syn match cOctalError display contained "0\o*[89]\d*"
242syn case match
243
244if exists("c_comment_strings")
245 " A comment can contain cString, cCharacter and cNumber.
246 " But a "*/" inside a cString in a cComment DOES end the comment! So we
247 " need to use a special type of cString: cCommentString, which also ends on
248 " "*/", and sees a "*" at the start of the line as comment again.
249 " Unfortunately this doesn't very well work for // type of comments :-(
Bram Moolenaarce001a32022-04-27 15:25:03 +0100250 syn match cCommentSkip contained "^\s*\*\%($\|\s\+\)"
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100251 syn region cCommentString contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
252 syn region cComment2String contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
Bram Moolenaar95bafa22018-10-02 13:26:25 +0200253 syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError,cWrongComTail,@Spell
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000254 if exists("c_no_comment_fold")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000255 " Use "extend" here to have preprocessor lines not terminate halfway a
256 " comment.
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100257 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell extend
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000258 else
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100259 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell fold extend
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000260 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261else
262 syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError,@Spell
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000263 if exists("c_no_comment_fold")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000264 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell extend
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000265 else
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000266 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold extend
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000267 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268endif
269" keep a // comment separately, it terminates a preproc. conditional
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100270syn match cCommentError display "\*/"
271syn match cCommentStartError display "/\*"me=e-1 contained
Bram Moolenaar95bafa22018-10-02 13:26:25 +0200272syn match cWrongComTail display "\*/"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000273
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274syn keyword cOperator sizeof
275if exists("c_gnu")
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000276 syn keyword cType __label__ __complex__
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277 syn keyword cStatement __asm__
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000278 syn keyword cOperator __alignof__
279 syn keyword cOperator typeof __typeof__
280 syn keyword cOperator __real__ __imag__
281 syn keyword cStorageClass __attribute__ __const__ __extension__
Wu Yongwei63c39e42024-03-06 03:27:27 +0800282 syn keyword cStorageClass inline __inline __inline__
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000283 syn keyword cStorageClass __restrict__ __volatile__ __noreturn__
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284endif
285syn keyword cType int long short char void
286syn keyword cType signed unsigned float double
287if !exists("c_no_ansi") || exists("c_ansi_typedefs")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000288 syn keyword cType size_t ssize_t off_t wchar_t ptrdiff_t sig_atomic_t fpos_t
Bram Moolenaar071d4272004-06-13 20:20:40 +0000289 syn keyword cType clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t
290 syn keyword cType mbstate_t wctrans_t wint_t wctype_t
291endif
292if !exists("c_no_c99") " ISO C99
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100293 syn keyword cType _Bool bool _Complex complex _Imaginary imaginary
Bram Moolenaar071d4272004-06-13 20:20:40 +0000294 syn keyword cType int8_t int16_t int32_t int64_t
295 syn keyword cType uint8_t uint16_t uint32_t uint64_t
Bram Moolenaar03413f42016-04-12 21:07:15 +0200296 if !exists("c_no_bsd")
297 " These are BSD specific.
298 syn keyword cType u_int8_t u_int16_t u_int32_t u_int64_t
299 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000300 syn keyword cType int_least8_t int_least16_t int_least32_t int_least64_t
301 syn keyword cType uint_least8_t uint_least16_t uint_least32_t uint_least64_t
302 syn keyword cType int_fast8_t int_fast16_t int_fast32_t int_fast64_t
303 syn keyword cType uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
304 syn keyword cType intptr_t uintptr_t
305 syn keyword cType intmax_t uintmax_t
306endif
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100307if !exists("c_no_c23") && !s:in_cpp_family
308 syn keyword cOperator typeof typeof_unqual
309 syn keyword cType _BitInt _Decimal32 _Decimal64 _Decimal128
310endif
311if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp11"))
312 syn keyword cType nullptr_t
313endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314
Bram Moolenaar3d1cde82020-08-15 18:55:18 +0200315syn keyword cTypedef typedef
316syn keyword cStructure struct union enum
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317syn keyword cStorageClass static register auto volatile extern const
Bram Moolenaar98a29d02021-01-18 19:55:44 +0100318if !exists("c_no_c99") && !s:in_cpp_family
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319 syn keyword cStorageClass inline restrict
320endif
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100321if !exists("c_no_c11")
322 syn keyword cStorageClass _Alignas alignas
323 syn keyword cOperator _Alignof alignof
324 syn keyword cStorageClass _Atomic
325 syn keyword cOperator _Generic
326 syn keyword cStorageClass _Noreturn noreturn
327 syn keyword cOperator _Static_assert static_assert
328 syn keyword cStorageClass _Thread_local thread_local
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100329 syn keyword cType char16_t char32_t
Bram Moolenaar47c532e2022-03-19 15:18:53 +0000330 syn keyword cType max_align_t
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200331 " C11 atomics (take down the shield wall!)
332 syn keyword cType atomic_bool atomic_char atomic_schar atomic_uchar
333 syn keyword Ctype atomic_short atomic_ushort atomic_int atomic_uint
334 syn keyword cType atomic_long atomic_ulong atomic_llong atomic_ullong
335 syn keyword cType atomic_char16_t atomic_char32_t atomic_wchar_t
336 syn keyword cType atomic_int_least8_t atomic_uint_least8_t
337 syn keyword cType atomic_int_least16_t atomic_uint_least16_t
338 syn keyword cType atomic_int_least32_t atomic_uint_least32_t
339 syn keyword cType atomic_int_least64_t atomic_uint_least64_t
340 syn keyword cType atomic_int_fast8_t atomic_uint_fast8_t
341 syn keyword cType atomic_int_fast16_t atomic_uint_fast16_t
342 syn keyword cType atomic_int_fast32_t atomic_uint_fast32_t
343 syn keyword cType atomic_int_fast64_t atomic_uint_fast64_t
344 syn keyword cType atomic_intptr_t atomic_uintptr_t
345 syn keyword cType atomic_size_t atomic_ptrdiff_t
346 syn keyword cType atomic_intmax_t atomic_uintmax_t
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100347endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100349if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp20"))
350 syn keyword cType char8_t
351endif
352
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
354 if exists("c_gnu")
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000355 syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356 endif
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100357 " TODO: __STDC_HOSTED__ is C99 and C++11
Bram Moolenaar3d1cde82020-08-15 18:55:18 +0200358 syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359 syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
360 syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
361 syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
362 syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
363 syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
364 syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
365 if !exists("c_no_c99")
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100366 syn keyword cConstant __STDC_ISO_10646__ __STDC_IEC_559_COMPLEX__
367 syn keyword cConstant __STDC_MB_MIGHT_NEQ_WC__
Bram Moolenaar063b9d12016-07-09 20:21:48 +0200368 syn keyword cConstant __func__ __VA_ARGS__
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000369 syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370 syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
371 syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
372 syn keyword cConstant UINT8_MAX UINT16_MAX UINT32_MAX UINT64_MAX
373 syn keyword cConstant INT_LEAST8_MIN INT_LEAST16_MIN INT_LEAST32_MIN INT_LEAST64_MIN
374 syn keyword cConstant INT_LEAST8_MAX INT_LEAST16_MAX INT_LEAST32_MAX INT_LEAST64_MAX
375 syn keyword cConstant UINT_LEAST8_MAX UINT_LEAST16_MAX UINT_LEAST32_MAX UINT_LEAST64_MAX
376 syn keyword cConstant INT_FAST8_MIN INT_FAST16_MIN INT_FAST32_MIN INT_FAST64_MIN
377 syn keyword cConstant INT_FAST8_MAX INT_FAST16_MAX INT_FAST32_MAX INT_FAST64_MAX
378 syn keyword cConstant UINT_FAST8_MAX UINT_FAST16_MAX UINT_FAST32_MAX UINT_FAST64_MAX
379 syn keyword cConstant INTPTR_MIN INTPTR_MAX UINTPTR_MAX
380 syn keyword cConstant INTMAX_MIN INTMAX_MAX UINTMAX_MAX
381 syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX
382 syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX
383 endif
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100384 if !exists("c_no_c11")
385 syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__ __STDC_ANALYZABLE__
386 syn keyword cConstant __STDC_LIB_EXT1__ __STDC_NO_ATOMICS__
387 syn keyword cConstant __STDC_NO_COMPLEX__ __STDC_NO_THREADS__
388 syn keyword cConstant __STDC_NO_VLA__
389 endif
390 if !exists("c_no_c23")
391 syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__
392 syn keyword cConstant __STDC_EMBED_NOT_FOUND__ __STDC_EMBED_FOUND__
393 syn keyword cConstant __STDC_EMBED_EMPTY__ __STDC_IEC_60559_BFP__
394 syn keyword cConstant __STDC_IEC_60559_DFP__ __STDC_IEC_60559_COMPLEX__
395 syn keyword cConstant __STDC_IEC_60559_TYPES__
396 syn keyword cConstant BITINT_MAXWIDTH
397 endif
398 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp20"))
399 syn keyword cConstant __VA_OPT__
400 endif
401 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp11"))
402 syn keyword cConstant nullptr
403 endif
Bram Moolenaarb4d6c3e2017-05-27 16:45:17 +0200404 syn keyword cConstant FLT_RADIX FLT_ROUNDS FLT_DIG FLT_MANT_DIG FLT_EPSILON DBL_DIG DBL_MANT_DIG DBL_EPSILON
405 syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP FLT_MIN_10_EXP FLT_MAX_10_EXP
406 syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP DBL_MIN_10_EXP DBL_MAX_10_EXP LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP
407 syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP HUGE_VAL CLOCKS_PER_SEC NULL LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY
408 syn keyword cConstant LC_NUMERIC LC_TIME SIG_DFL SIG_ERR SIG_IGN SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM
Bram Moolenaar071d4272004-06-13 20:20:40 +0000409 " Add POSIX signals as well...
Bram Moolenaarb4d6c3e2017-05-27 16:45:17 +0200410 syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
411 syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
412 syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam
Bram Moolenaar71badf92023-04-22 22:40:14 +0100413 syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX EXIT_FAILURE EXIT_SUCCESS RAND_MAX
414 syn keyword cConstant stdin stdout stderr
415 " POSIX 2001, in unistd.h
416 syn keyword cConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO
Bram Moolenaar207f0092020-08-30 17:20:20 +0200417 " used in assert.h
418 syn keyword cConstant NDEBUG
Bram Moolenaar822ff862014-06-12 21:46:14 +0200419 " POSIX 2001
Bram Moolenaarb4d6c3e2017-05-27 16:45:17 +0200420 syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ
Bram Moolenaar2b8388b2015-02-28 13:11:45 +0100421 " non-POSIX signals
422 syn keyword cConstant SIGWINCH SIGINFO
Bram Moolenaarb4d6c3e2017-05-27 16:45:17 +0200423 " Add POSIX errors as well. List comes from:
424 " http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
425 syn keyword cConstant E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF
426 syn keyword cConstant EBADMSG EBUSY ECANCELED ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK
427 syn keyword cConstant EDESTADDRREQ EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM EILSEQ
428 syn keyword cConstant EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE
429 syn keyword cConstant EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS ENODATA
430 syn keyword cConstant ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR
Bram Moolenaar4c92e752019-02-17 21:18:32 +0100431 syn keyword cConstant ENOSTR ENOSYS ENOTBLK ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP
Bram Moolenaarb4d6c3e2017-05-27 16:45:17 +0200432 syn keyword cConstant ENOTTY ENXIO EOPNOTSUPP EOVERFLOW EOWNERDEAD EPERM EPIPE EPROTO
433 syn keyword cConstant EPROTONOSUPPORT EPROTOTYPE ERANGE EROFS ESPIPE ESRCH ESTALE ETIME ETIMEDOUT
434 syn keyword cConstant ETXTBSY EWOULDBLOCK EXDEV
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435 " math.h
436 syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4
437 syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2
438endif
439if !exists("c_no_c99") " ISO C99
440 syn keyword cConstant true false
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100441 syn keyword cConstant INFINITY NAN
442 " math.h
443 syn keyword cConstant HUGE_VAL HUGE_VALF HUGE_VALL
444 syn keyword cConstant FP_FAST_FMAF FP_FAST_FMA FP_FAST_FMAL
445 syn keyword cConstant FP_ILOGB0 FP_ILOGBNAN
446 syn keyword cConstant math_errhandling MATH_ERRNO MATH_ERREXCEPT
447 syn keyword cConstant FP_NORMAL FP_SUBNORMAL FP_ZERO FP_INFINITE FP_NAN
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448endif
449
450" Accept %: for # (C99)
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100451syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock
452if !exists("c_no_c23")
453 syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(el\)\=\%(if\|ifdef\|ifndef\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
454else
455 syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
456endif
Bram Moolenaarce001a32022-04-27 15:25:03 +0100457syn match cPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458if !exists("c_no_if0")
Bram Moolenaar97293012011-07-18 19:40:27 +0200459 syn cluster cCppOutInGroup contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
Bram Moolenaarce001a32022-04-27 15:25:03 +0100460 syn region cCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold
461 syn region cCppOutIf contained start="0\+" matchgroup=cCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cCppOutIf2,cCppOutElse
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000462 if !exists("c_no_if0_fold")
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100463 if !exists("c_no_c23")
464 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold
465 else
466 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold
467 endif
Bram Moolenaar5302d9e2011-09-14 17:55:08 +0200468 else
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100469 if !exists("c_no_c23")
470 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
471 else
472 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
473 endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +0000474 endif
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100475 if !exists("c_no_c23")
476 syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|el\%(if\|ifdef\|ifndef\)\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit
477 else
478 syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit
479 endif
Bram Moolenaarce001a32022-04-27 15:25:03 +0100480 syn region cCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold
481 syn region cCppInIf contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cPreCondit
Bram Moolenaar97293012011-07-18 19:40:27 +0200482 if !exists("c_no_if0_fold")
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100483 if !exists("c_no_c23")
484 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold
485 else
486 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold
487 endif
Bram Moolenaar97293012011-07-18 19:40:27 +0200488 else
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100489 if !exists("c_no_c23")
490 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2
491 else
492 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2
493 endif
Bram Moolenaar97293012011-07-18 19:40:27 +0200494 endif
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100495 if !exists("c_no_c23")
496 syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|el\%(if\|ifdef\|ifndef\)\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
497 else
498 syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
499 endif
Bram Moolenaarce001a32022-04-27 15:25:03 +0100500 syn region cCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip
501 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502endif
503syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
504syn match cIncluded display contained "<[^>]*>"
Bram Moolenaarce001a32022-04-27 15:25:03 +0100505syn match cInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
Doug Kearnsc2a967a2025-01-17 14:12:16 +0100506if !exists("c_no_c23") && !s:in_cpp_family
507 syn region cInclude start="^\s*\zs\%(%:\|#\)\s*embed\>" skip="\\$" end="$" keepend contains=cEmbed,cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
508 syn match cEmbed contained "\%(%:\|#\)\s*embed\>" nextgroup=cIncluded skipwhite transparent
509 syn cluster cPreProcGroup add=cEmbed
510endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511"syn match cLineSkip "\\$"
Bram Moolenaarce001a32022-04-27 15:25:03 +0100512syn region cDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
513syn region cPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514
Bram Moolenaar40962ec2018-01-28 22:47:25 +0100515" Optional embedded Autodoc parsing
516if exists("c_autodoc")
517 syn match cAutodocReal display contained "\%(//\|[/ \t\v]\*\|^\*\)\@2<=!.*" contains=@cAutodoc containedin=cComment,cCommentL
518 syn cluster cCommentGroup add=cAutodocReal
519 syn cluster cPreProcGroup add=cAutodocReal
520endif
521
Bram Moolenaard2ea7cf2021-05-30 20:54:13 +0200522" be able to fold #pragma regions
523syn region cPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
524
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525" Highlight User Labels
Bram Moolenaar97293012011-07-18 19:40:27 +0200526syn 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
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200527if s:ft ==# 'c' || exists("cpp_no_cpp11")
Bram Moolenaar3a991dd2014-10-02 01:41:41 +0200528 syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell,@cStringGroup
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100529endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530" Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
531syn cluster cLabelGroup contains=cUserLabel
Bram Moolenaar6d5ad4c2016-10-27 17:00:16 +0200532syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup
533syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup
Bram Moolenaar98a29d02021-01-18 19:55:44 +0100534if s:in_cpp_family
Bram Moolenaar6d5ad4c2016-10-27 17:00:16 +0200535 syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
536 syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
Bram Moolenaard8b77f72015-03-05 21:21:19 +0100537else
Bram Moolenaar6d5ad4c2016-10-27 17:00:16 +0200538 syn match cUserCont display "^\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
539 syn match cUserCont display ";\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
Bram Moolenaard8b77f72015-03-05 21:21:19 +0100540endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000541
542syn match cUserLabel display "\I\i*" contained
543
544" Avoid recognizing most bitfields as labels
Bram Moolenaar6d5ad4c2016-10-27 17:00:16 +0200545syn match cBitField display "^\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
546syn match cBitField display ";\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547
Luca Saccarolaca0e9822023-12-24 18:57:02 +0100548if exists("c_functions")
549 syn match cFunction "\<\h\w*\ze\_s*("
550 endif
551
552if exists("c_function_pointers")
553 syn match cFunctionPointer "\%((\s*\*\s*\)\@<=\h\w*\ze\s*)\_s*(.*)"
554endif
555
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556if exists("c_minlines")
557 let b:c_minlines = c_minlines
558else
559 if !exists("c_no_if0")
560 let b:c_minlines = 50 " #if 0 constructs can be long
561 else
562 let b:c_minlines = 15 " mostly for () constructs
563 endif
564endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000565if exists("c_curly_error")
566 syn sync fromstart
567else
568 exec "syn sync ccomment cComment minlines=" . b:c_minlines
569endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570
571" Define the default highlighting.
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000572" Only used when an item doesn't have highlighting yet
573hi def link cFormat cSpecial
574hi def link cCppString cString
575hi def link cCommentL cComment
576hi def link cCommentStart cComment
577hi def link cLabel Label
578hi def link cUserLabel Label
579hi def link cConditional Conditional
580hi def link cRepeat Repeat
581hi def link cCharacter Character
582hi def link cSpecialCharacter cSpecial
583hi def link cNumber Number
584hi def link cOctal Number
585hi def link cOctalZero PreProc " link this to Error if you want
586hi def link cFloat Float
587hi def link cOctalError cError
588hi def link cParenError cError
589hi def link cErrInParen cError
590hi def link cErrInBracket cError
591hi def link cCommentError cError
592hi def link cCommentStartError cError
593hi def link cSpaceError cError
Bram Moolenaar95bafa22018-10-02 13:26:25 +0200594hi def link cWrongComTail cError
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000595hi def link cSpecialError cError
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000596hi def link cCurlyError cError
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000597hi def link cOperator Operator
598hi def link cStructure Structure
Bram Moolenaar3d1cde82020-08-15 18:55:18 +0200599hi def link cTypedef Structure
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000600hi def link cStorageClass StorageClass
601hi def link cInclude Include
602hi def link cPreProc PreProc
603hi def link cDefine Macro
604hi def link cIncluded cString
605hi def link cError Error
606hi def link cStatement Statement
Bram Moolenaar97293012011-07-18 19:40:27 +0200607hi def link cCppInWrapper cCppOutWrapper
608hi def link cCppOutWrapper cPreCondit
609hi def link cPreConditMatch cPreCondit
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000610hi def link cPreCondit PreCondit
611hi def link cType Type
612hi def link cConstant Constant
613hi def link cCommentString cString
614hi def link cComment2String cString
615hi def link cCommentSkip cComment
616hi def link cString String
617hi def link cComment Comment
618hi def link cSpecial SpecialChar
619hi def link cTodo Todo
Bram Moolenaar5c736222010-01-06 20:54:52 +0100620hi def link cBadContinuation Error
Bram Moolenaar97293012011-07-18 19:40:27 +0200621hi def link cCppOutSkip cCppOutIf2
622hi def link cCppInElse2 cCppOutIf2
Bram Moolenaar2f3b5102014-11-19 18:54:17 +0100623hi def link cCppOutIf2 cCppOut
Bram Moolenaard857f0e2005-06-21 22:37:39 +0000624hi def link cCppOut Comment
Luca Saccarolaca0e9822023-12-24 18:57:02 +0100625hi def link cFunction Function
626hi def link cFunctionPointer Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627
628let b:current_syntax = "c"
629
Bram Moolenaarbc488a72013-07-05 21:01:22 +0200630unlet s:ft
631
Bram Moolenaarb6b046b2011-12-30 13:11:27 +0100632let &cpo = s:cpo_save
633unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634" vim: ts=8