c.vim 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. " Vim syntax file
  2. " Language: C
  3. " Maintainer: Bram Moolenaar <Bram@vim.org>
  4. " Last Change: 2022 Oct 05
  5. " Quit when a (custom) syntax file was already loaded
  6. if exists("b:current_syntax")
  7. finish
  8. endif
  9. let s:cpo_save = &cpo
  10. set cpo&vim
  11. let s:ft = matchstr(&ft, '^\%([^.]\)\+')
  12. " check if this was included from cpp.vim
  13. let s:in_cpp_family = exists("b:filetype_in_cpp_family")
  14. " Optional embedded Autodoc parsing
  15. " To enable it add: let g:c_autodoc = 1
  16. " to your .vimrc
  17. if exists("c_autodoc")
  18. syn include @cAutodoc <sfile>:p:h/autodoc.vim
  19. unlet b:current_syntax
  20. endif
  21. " A bunch of useful C keywords
  22. syn keyword cStatement goto break return continue asm
  23. syn keyword cLabel case default
  24. syn keyword cConditional if else switch
  25. syn keyword cRepeat while for do
  26. syn keyword cTodo contained TODO FIXME XXX
  27. " It's easy to accidentally add a space after a backslash that was intended
  28. " for line continuation. Some compilers allow it, which makes it
  29. " unpredictable and should be avoided.
  30. syn match cBadContinuation contained "\\\s\+$"
  31. " cCommentGroup allows adding matches for special things in comments
  32. syn cluster cCommentGroup contains=cTodo,cBadContinuation
  33. " String and Character constants
  34. " Highlight special characters (those which have a backslash) differently
  35. syn match cSpecial display contained "\\\%(x\x\+\|\o\{1,3}\|.\|$\)"
  36. if !exists("c_no_utf")
  37. syn match cSpecial display contained "\\\%(u\x\{4}\|U\x\{8}\)"
  38. endif
  39. if !exists("c_no_cformat")
  40. " Highlight % items in strings.
  41. if !exists("c_no_c99") " ISO C99
  42. syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjzt]\|ll\|hh\)\=\%([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  43. else
  44. syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlL]\|ll\)\=\%([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  45. endif
  46. syn match cFormat display "%%" contained
  47. endif
  48. " cCppString: same as cString, but ends at end of line
  49. if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat")
  50. " ISO C++11
  51. syn region cString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  52. syn region cCppString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  53. elseif s:ft ==# "c" && !exists("c_no_c11") && !exists("c_no_cformat")
  54. " ISO C99
  55. syn region cString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  56. syn region cCppString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  57. else
  58. " older C or C++
  59. syn match cFormat display "%%" contained
  60. syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  61. syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  62. endif
  63. syn region cCppSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip
  64. syn cluster cStringGroup contains=cCppString,cCppSkip
  65. syn match cCharacter "L\='[^\\]'"
  66. syn match cCharacter "L'[^']*'" contains=cSpecial
  67. if exists("c_gnu")
  68. syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'"
  69. syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'"
  70. else
  71. syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'"
  72. syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
  73. endif
  74. syn match cSpecialCharacter display "L\='\\\o\{1,3}'"
  75. syn match cSpecialCharacter display "'\\x\x\{1,2}'"
  76. syn match cSpecialCharacter display "L'\\x\x\+'"
  77. if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11"))
  78. " ISO C11 or ISO C++ 11
  79. if exists("c_no_cformat")
  80. syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
  81. else
  82. syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  83. endif
  84. syn match cCharacter "[Uu]'[^\\]'"
  85. syn match cCharacter "[Uu]'[^']*'" contains=cSpecial
  86. if exists("c_gnu")
  87. syn match cSpecialError "[Uu]'\\[^'\"?\\abefnrtv]'"
  88. syn match cSpecialCharacter "[Uu]'\\['\"?\\abefnrtv]'"
  89. else
  90. syn match cSpecialError "[Uu]'\\[^'\"?\\abfnrtv]'"
  91. syn match cSpecialCharacter "[Uu]'\\['\"?\\abfnrtv]'"
  92. endif
  93. syn match cSpecialCharacter display "[Uu]'\\\o\{1,3}'"
  94. syn match cSpecialCharacter display "[Uu]'\\x\x\+'"
  95. endif
  96. "when wanted, highlight trailing white space
  97. if exists("c_space_errors")
  98. if !exists("c_no_trail_space_error")
  99. syn match cSpaceError display excludenl "\s\+$"
  100. endif
  101. if !exists("c_no_tab_space_error")
  102. syn match cSpaceError display " \+\t"me=e-1
  103. endif
  104. endif
  105. " This should be before cErrInParen to avoid problems with #define ({ xxx })
  106. if exists("c_curly_error")
  107. syn match cCurlyError "}"
  108. syn region cBlock start="{" end="}" contains=ALLBUT,cBadBlock,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell fold
  109. else
  110. syn region cBlock start="{" end="}" transparent fold
  111. endif
  112. " Catch errors caused by wrong parenthesis and brackets.
  113. " Also accept <% for {, %> for }, <: for [ and :> for ] (C99)
  114. " But avoid matching <::.
  115. syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  116. if exists("c_no_curly_error")
  117. if s:in_cpp_family && !exists("cpp_no_cpp11")
  118. syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
  119. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  120. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  121. syn match cParenError display ")"
  122. syn match cErrInParen display contained "^^<%\|^%>"
  123. else
  124. syn region cParen transparent start='(' end=')' contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell
  125. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  126. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  127. syn match cParenError display ")"
  128. syn match cErrInParen display contained "^[{}]\|^<%\|^%>"
  129. endif
  130. elseif exists("c_no_bracket_error")
  131. if s:in_cpp_family && !exists("cpp_no_cpp11")
  132. syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell
  133. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  134. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  135. syn match cParenError display ")"
  136. syn match cErrInParen display contained "<%\|%>"
  137. else
  138. syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell
  139. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  140. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  141. syn match cParenError display ")"
  142. syn match cErrInParen display contained "[{}]\|<%\|%>"
  143. endif
  144. else
  145. if s:in_cpp_family && !exists("cpp_no_cpp11")
  146. syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
  147. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  148. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  149. syn match cParenError display "[\])]"
  150. syn match cErrInParen display contained "<%\|%>"
  151. syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell
  152. else
  153. syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell
  154. " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  155. syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  156. syn match cParenError display "[\])]"
  157. syn match cErrInParen display contained "[\]{}]\|<%\|%>"
  158. syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell
  159. endif
  160. " cCppBracket: same as cParen but ends at end-of-line; used in cDefine
  161. syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell
  162. syn match cErrInBracket display contained "[);{}]\|<%\|%>"
  163. endif
  164. if s:ft ==# 'c' || exists("cpp_no_cpp11")
  165. syn region cBadBlock keepend start="{" end="}" contained containedin=cParen,cBracket,cBadBlock transparent fold
  166. endif
  167. "integer number, or floating point number without a dot and with "f".
  168. syn case ignore
  169. syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
  170. " Same, but without octal error (for comments)
  171. syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
  172. syn match cNumber display contained "\d\+\%(u\=l\{0,2}\|ll\=u\)\>"
  173. "hex number
  174. syn match cNumber display contained "0x\x\+\%(u\=l\{0,2}\|ll\=u\)\>"
  175. " Flag the first zero of an octal number as something special
  176. syn match cOctal display contained "0\o\+\%(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  177. syn match cOctalZero display contained "\<0"
  178. "floating point number, with dot, optional exponent
  179. syn match cFloat display contained "\d\+\.\d*\%(e[-+]\=\d\+\)\=[fl]\="
  180. "floating point number, starting with a dot, optional exponent
  181. syn match cFloat display contained "\.\d\+\%(e[-+]\=\d\+\)\=[fl]\=\>"
  182. "floating point number, without dot, with exponent
  183. syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>"
  184. if !exists("c_no_c99")
  185. "hexadecimal floating point number, optional leading digits, with dot, with exponent
  186. syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>"
  187. "hexadecimal floating point number, with leading digits, optional dot, with exponent
  188. syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>"
  189. endif
  190. " flag an octal number with wrong digits
  191. syn match cOctalError display contained "0\o*[89]\d*"
  192. syn case match
  193. if exists("c_comment_strings")
  194. " A comment can contain cString, cCharacter and cNumber.
  195. " But a "*/" inside a cString in a cComment DOES end the comment! So we
  196. " need to use a special type of cString: cCommentString, which also ends on
  197. " "*/", and sees a "*" at the start of the line as comment again.
  198. " Unfortunately this doesn't very well work for // type of comments :-(
  199. syn match cCommentSkip contained "^\s*\*\%($\|\s\+\)"
  200. syn region cCommentString contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  201. syn region cComment2String contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  202. syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError,cWrongComTail,@Spell
  203. if exists("c_no_comment_fold")
  204. " Use "extend" here to have preprocessor lines not terminate halfway a
  205. " comment.
  206. syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell extend
  207. else
  208. syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell fold extend
  209. endif
  210. else
  211. syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError,@Spell
  212. if exists("c_no_comment_fold")
  213. syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell extend
  214. else
  215. syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold extend
  216. endif
  217. endif
  218. " keep a // comment separately, it terminates a preproc. conditional
  219. syn match cCommentError display "\*/"
  220. syn match cCommentStartError display "/\*"me=e-1 contained
  221. syn match cWrongComTail display "\*/"
  222. syn keyword cOperator sizeof
  223. if exists("c_gnu")
  224. syn keyword cType __label__ __complex__
  225. syn keyword cStatement __asm__
  226. syn keyword cOperator __alignof__
  227. syn keyword cOperator typeof __typeof__
  228. syn keyword cOperator __real__ __imag__
  229. syn keyword cStorageClass __attribute__ __const__ __extension__
  230. syn keyword cStorageClass inline __inline__
  231. syn keyword cStorageClass __restrict__ __volatile__ __noreturn__
  232. endif
  233. syn keyword cType int long short char void
  234. syn keyword cType signed unsigned float double
  235. if !exists("c_no_ansi") || exists("c_ansi_typedefs")
  236. syn keyword cType size_t ssize_t off_t wchar_t ptrdiff_t sig_atomic_t fpos_t
  237. syn keyword cType clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t
  238. syn keyword cType mbstate_t wctrans_t wint_t wctype_t
  239. endif
  240. if !exists("c_no_c99") " ISO C99
  241. syn keyword cType _Bool bool _Complex complex _Imaginary imaginary
  242. syn keyword cType int8_t int16_t int32_t int64_t
  243. syn keyword cType uint8_t uint16_t uint32_t uint64_t
  244. if !exists("c_no_bsd")
  245. " These are BSD specific.
  246. syn keyword cType u_int8_t u_int16_t u_int32_t u_int64_t
  247. endif
  248. syn keyword cType int_least8_t int_least16_t int_least32_t int_least64_t
  249. syn keyword cType uint_least8_t uint_least16_t uint_least32_t uint_least64_t
  250. syn keyword cType int_fast8_t int_fast16_t int_fast32_t int_fast64_t
  251. syn keyword cType uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
  252. syn keyword cType intptr_t uintptr_t
  253. syn keyword cType intmax_t uintmax_t
  254. endif
  255. syn keyword cTypedef typedef
  256. syn keyword cStructure struct union enum
  257. syn keyword cStorageClass static register auto volatile extern const
  258. if !exists("c_no_c99") && !s:in_cpp_family
  259. syn keyword cStorageClass inline restrict
  260. endif
  261. if !exists("c_no_c11")
  262. syn keyword cStorageClass _Alignas alignas
  263. syn keyword cOperator _Alignof alignof
  264. syn keyword cStorageClass _Atomic
  265. syn keyword cOperator _Generic
  266. syn keyword cStorageClass _Noreturn noreturn
  267. syn keyword cOperator _Static_assert static_assert
  268. syn keyword cStorageClass _Thread_local thread_local
  269. syn keyword cType char16_t char32_t
  270. syn keyword cType max_align_t
  271. " C11 atomics (take down the shield wall!)
  272. syn keyword cType atomic_bool atomic_char atomic_schar atomic_uchar
  273. syn keyword Ctype atomic_short atomic_ushort atomic_int atomic_uint
  274. syn keyword cType atomic_long atomic_ulong atomic_llong atomic_ullong
  275. syn keyword cType atomic_char16_t atomic_char32_t atomic_wchar_t
  276. syn keyword cType atomic_int_least8_t atomic_uint_least8_t
  277. syn keyword cType atomic_int_least16_t atomic_uint_least16_t
  278. syn keyword cType atomic_int_least32_t atomic_uint_least32_t
  279. syn keyword cType atomic_int_least64_t atomic_uint_least64_t
  280. syn keyword cType atomic_int_fast8_t atomic_uint_fast8_t
  281. syn keyword cType atomic_int_fast16_t atomic_uint_fast16_t
  282. syn keyword cType atomic_int_fast32_t atomic_uint_fast32_t
  283. syn keyword cType atomic_int_fast64_t atomic_uint_fast64_t
  284. syn keyword cType atomic_intptr_t atomic_uintptr_t
  285. syn keyword cType atomic_size_t atomic_ptrdiff_t
  286. syn keyword cType atomic_intmax_t atomic_uintmax_t
  287. endif
  288. if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
  289. if exists("c_gnu")
  290. syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
  291. endif
  292. syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__
  293. syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
  294. syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
  295. syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
  296. syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
  297. syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
  298. syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
  299. if !exists("c_no_c99")
  300. syn keyword cConstant __func__ __VA_ARGS__
  301. syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
  302. syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
  303. syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
  304. syn keyword cConstant UINT8_MAX UINT16_MAX UINT32_MAX UINT64_MAX
  305. syn keyword cConstant INT_LEAST8_MIN INT_LEAST16_MIN INT_LEAST32_MIN INT_LEAST64_MIN
  306. syn keyword cConstant INT_LEAST8_MAX INT_LEAST16_MAX INT_LEAST32_MAX INT_LEAST64_MAX
  307. syn keyword cConstant UINT_LEAST8_MAX UINT_LEAST16_MAX UINT_LEAST32_MAX UINT_LEAST64_MAX
  308. syn keyword cConstant INT_FAST8_MIN INT_FAST16_MIN INT_FAST32_MIN INT_FAST64_MIN
  309. syn keyword cConstant INT_FAST8_MAX INT_FAST16_MAX INT_FAST32_MAX INT_FAST64_MAX
  310. syn keyword cConstant UINT_FAST8_MAX UINT_FAST16_MAX UINT_FAST32_MAX UINT_FAST64_MAX
  311. syn keyword cConstant INTPTR_MIN INTPTR_MAX UINTPTR_MAX
  312. syn keyword cConstant INTMAX_MIN INTMAX_MAX UINTMAX_MAX
  313. syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX
  314. syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX
  315. endif
  316. syn keyword cConstant FLT_RADIX FLT_ROUNDS FLT_DIG FLT_MANT_DIG FLT_EPSILON DBL_DIG DBL_MANT_DIG DBL_EPSILON
  317. 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
  318. 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
  319. 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
  320. syn keyword cConstant LC_NUMERIC LC_TIME SIG_DFL SIG_ERR SIG_IGN SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM
  321. " Add POSIX signals as well...
  322. syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  323. syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
  324. syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam
  325. syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX stderr stdin stdout EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  326. " used in assert.h
  327. syn keyword cConstant NDEBUG
  328. " POSIX 2001
  329. syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ
  330. " non-POSIX signals
  331. syn keyword cConstant SIGWINCH SIGINFO
  332. " Add POSIX errors as well. List comes from:
  333. " http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html
  334. syn keyword cConstant E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF
  335. syn keyword cConstant EBADMSG EBUSY ECANCELED ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK
  336. syn keyword cConstant EDESTADDRREQ EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM EILSEQ
  337. syn keyword cConstant EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE
  338. syn keyword cConstant EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS ENODATA
  339. syn keyword cConstant ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR
  340. syn keyword cConstant ENOSTR ENOSYS ENOTBLK ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP
  341. syn keyword cConstant ENOTTY ENXIO EOPNOTSUPP EOVERFLOW EOWNERDEAD EPERM EPIPE EPROTO
  342. syn keyword cConstant EPROTONOSUPPORT EPROTOTYPE ERANGE EROFS ESPIPE ESRCH ESTALE ETIME ETIMEDOUT
  343. syn keyword cConstant ETXTBSY EWOULDBLOCK EXDEV
  344. " math.h
  345. syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4
  346. syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2
  347. endif
  348. if !exists("c_no_c99") " ISO C99
  349. syn keyword cConstant true false
  350. endif
  351. " Accept %: for # (C99)
  352. syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
  353. syn match cPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
  354. if !exists("c_no_if0")
  355. syn cluster cCppOutInGroup contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
  356. syn region cCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold
  357. syn region cCppOutIf contained start="0\+" matchgroup=cCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cCppOutIf2,cCppOutElse
  358. if !exists("c_no_if0_fold")
  359. 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
  360. else
  361. syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  362. endif
  363. syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit
  364. syn region cCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold
  365. syn region cCppInIf contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cPreCondit
  366. if !exists("c_no_if0_fold")
  367. syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold
  368. else
  369. syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2
  370. endif
  371. syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  372. syn region cCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip
  373. 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
  374. endif
  375. syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  376. syn match cIncluded display contained "<[^>]*>"
  377. syn match cInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
  378. "syn match cLineSkip "\\$"
  379. syn 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
  380. syn region cDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  381. syn region cPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  382. " Optional embedded Autodoc parsing
  383. if exists("c_autodoc")
  384. syn match cAutodocReal display contained "\%(//\|[/ \t\v]\*\|^\*\)\@2<=!.*" contains=@cAutodoc containedin=cComment,cCommentL
  385. syn cluster cCommentGroup add=cAutodocReal
  386. syn cluster cPreProcGroup add=cAutodocReal
  387. endif
  388. " be able to fold #pragma regions
  389. syn region cPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
  390. " Highlight User Labels
  391. 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
  392. if s:ft ==# 'c' || exists("cpp_no_cpp11")
  393. syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell,@cStringGroup
  394. endif
  395. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  396. syn cluster cLabelGroup contains=cUserLabel
  397. syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup
  398. syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup
  399. if s:in_cpp_family
  400. syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  401. syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  402. else
  403. syn match cUserCont display "^\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  404. syn match cUserCont display ";\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  405. endif
  406. syn match cUserLabel display "\I\i*" contained
  407. " Avoid recognizing most bitfields as labels
  408. syn match cBitField display "^\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  409. syn match cBitField display ";\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  410. if exists("c_minlines")
  411. let b:c_minlines = c_minlines
  412. else
  413. if !exists("c_no_if0")
  414. let b:c_minlines = 50 " #if 0 constructs can be long
  415. else
  416. let b:c_minlines = 15 " mostly for () constructs
  417. endif
  418. endif
  419. if exists("c_curly_error")
  420. syn sync fromstart
  421. else
  422. exec "syn sync ccomment cComment minlines=" . b:c_minlines
  423. endif
  424. " Define the default highlighting.
  425. " Only used when an item doesn't have highlighting yet
  426. hi def link cFormat cSpecial
  427. hi def link cCppString cString
  428. hi def link cCommentL cComment
  429. hi def link cCommentStart cComment
  430. hi def link cLabel Label
  431. hi def link cUserLabel Label
  432. hi def link cConditional Conditional
  433. hi def link cRepeat Repeat
  434. hi def link cCharacter Character
  435. hi def link cSpecialCharacter cSpecial
  436. hi def link cNumber Number
  437. hi def link cOctal Number
  438. hi def link cOctalZero PreProc " link this to Error if you want
  439. hi def link cFloat Float
  440. hi def link cOctalError cError
  441. hi def link cParenError cError
  442. hi def link cErrInParen cError
  443. hi def link cErrInBracket cError
  444. hi def link cCommentError cError
  445. hi def link cCommentStartError cError
  446. hi def link cSpaceError cError
  447. hi def link cWrongComTail cError
  448. hi def link cSpecialError cError
  449. hi def link cCurlyError cError
  450. hi def link cOperator Operator
  451. hi def link cStructure Structure
  452. hi def link cTypedef Structure
  453. hi def link cStorageClass StorageClass
  454. hi def link cInclude Include
  455. hi def link cPreProc PreProc
  456. hi def link cDefine Macro
  457. hi def link cIncluded cString
  458. hi def link cError Error
  459. hi def link cStatement Statement
  460. hi def link cCppInWrapper cCppOutWrapper
  461. hi def link cCppOutWrapper cPreCondit
  462. hi def link cPreConditMatch cPreCondit
  463. hi def link cPreCondit PreCondit
  464. hi def link cType Type
  465. hi def link cConstant Constant
  466. hi def link cCommentString cString
  467. hi def link cComment2String cString
  468. hi def link cCommentSkip cComment
  469. hi def link cString String
  470. hi def link cComment Comment
  471. hi def link cSpecial SpecialChar
  472. hi def link cTodo Todo
  473. hi def link cBadContinuation Error
  474. hi def link cCppOutSkip cCppOutIf2
  475. hi def link cCppInElse2 cCppOutIf2
  476. hi def link cCppOutIf2 cCppOut
  477. hi def link cCppOut Comment
  478. let b:current_syntax = "c"
  479. unlet s:ft
  480. let &cpo = s:cpo_save
  481. unlet s:cpo_save
  482. " vim: ts=8