home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / syntax / c.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  10.4 KB  |  236 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:    C
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    1999 Sep 18
  5.  
  6. " Remove any old syntax stuff hanging around
  7. syn clear
  8.  
  9. " A bunch of useful C keywords
  10. syn keyword    cStatement    goto break return continue asm
  11. syn keyword    cLabel        case default
  12. syn keyword    cConditional    if else switch
  13. syn keyword    cRepeat        while for do
  14.  
  15. syn keyword    cTodo        contained TODO FIXME XXX
  16.  
  17. " cCommentGroup allows adding matches for special things in comments
  18. syn cluster    cCommentGroup    contains=cTodo
  19.  
  20. " String and Character constants
  21. " Highlight special characters (those which have a backslash) differently
  22. syn match    cSpecial    contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)"
  23. if !exists("c_no_utf")
  24.   syn match    cSpecial    contained "\\\(u\x\{4}\|U\x\{8}\)"
  25. endif
  26. if exists("c_no_cformat")
  27.   syn region    cString        start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
  28. else
  29.   syn match    cFormat        "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([diuoxXfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  30.   syn match    cFormat        "%%" contained
  31.   syn region    cString        start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat
  32.   hi link cFormat cSpecial
  33. endif
  34. syn match    cCharacter    "L\='[^\\]'"
  35. syn match    cCharacter    "L'[^']*'" contains=cSpecial
  36. syn match    cSpecialError    "L\='\\[^'\"?\\abfnrtv]'"
  37. syn match    cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
  38. syn match    cSpecialCharacter "L\='\\\o\{1,3}'"
  39. syn match    cSpecialCharacter "'\\x\x\{1,2}'"
  40. syn match    cSpecialCharacter "L'\\x\x\+'"
  41.  
  42. "when wanted, highlight trailing white space
  43. if exists("c_space_errors")
  44.   if !exists("c_no_trail_space_error")
  45.     syn match    cSpaceError    "\s\+$"
  46.   endif
  47.   if !exists("c_no_tab_space_error")
  48.     syn match    cSpaceError    " \+\t"me=e-1
  49.   endif
  50. endif
  51.  
  52. "catch errors caused by wrong parenthesis and brackets
  53. syn cluster    cParenGroup    contains=cParenError,cIncluded,cSpecial,@cCommentGroup,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  54. if exists("c_no_bracket_error")
  55.   syn region    cParen        transparent start='(' end=')' contains=ALLBUT,@cParenGroup
  56.   syn match    cParenError    ")"
  57.   syn match    cErrInParen    contained "[{}]"
  58. else
  59.   syn region    cParen        transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cErrInBracket
  60.   syn match    cParenError    "[\])]"
  61.   syn match    cErrInParen    contained "[\]{}]"
  62.   syn region    cBracket    transparent start='\[' end=']' contains=ALLBUT,@cParenGroup,cErrInParen
  63.   syn match    cErrInBracket    contained "[);{}]"
  64. endif
  65.  
  66. "integer number, or floating point number without a dot and with "f".
  67. syn case ignore
  68. syn match    cNumbers    transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
  69. " Same, but without octal error (for comments)
  70. syn match    cNumbersCom    contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
  71. syn match    cNumber        contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  72. "hex number
  73. syn match    cNumber        contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
  74. " Flag the first zero of an octal number as something special
  75. syn match    cOctal        contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  76. syn match    cOctalZero    contained "\<0"
  77. syn match    cFloat        contained "\d\+f"
  78. "floating point number, with dot, optional exponent
  79. syn match    cFloat        contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
  80. "floating point number, starting with a dot, optional exponent
  81. syn match    cFloat        contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  82. "floating point number, without dot, with exponent
  83. syn match    cFloat        contained "\d\+e[-+]\=\d\+[fl]\=\>"
  84. " flag an octal number with wrong digits
  85. syn match    cOctalError    contained "0\o*[89]\d*"
  86. syn case match
  87.  
  88. if exists("c_comment_strings")
  89.   " A comment can contain cString, cCharacter and cNumber.
  90.   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  91.   " need to use a special type of cString: cCommentString, which also ends on
  92.   " "*/", and sees a "*" at the start of the line as comment again.
  93.   " Unfortunately this doesn't very well work for // type of comments :-(
  94.   syntax match    cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  95.   syntax region cCommentString    contained start=+L\="+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  96.   syntax region cComment2String    contained start=+L\="+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  97.   syntax region  cCommentL    start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError
  98.   syntax region cComment    start="/\*" end="\*/" contains=@cCommentGroup,cCommentString,cCharacter,cNumbersCom,cSpaceError
  99. else
  100.   syn region    cCommentL    start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError
  101.   syn region    cComment    start="/\*" end="\*/" contains=@cCommentGroup,cSpaceError
  102. endif
  103. " keep a // comment separately, it terminates a preproc. conditional
  104. hi link cCommentL cComment
  105. syntax match    cCommentError    "\*/"
  106.  
  107. syn keyword    cOperator    sizeof
  108. syn keyword    cType        int long short char void
  109. syn keyword    cType        signed unsigned float double
  110. if !exists("c_no_ansi") || exists("c_ansi_typedefs")
  111.   syn keyword   cType           size_t wchar_t ptrdiff_t sig_atomic_t fpos_t
  112.   syn keyword   cType           clock_t time_t va_list jmp_buf FILE div_t ldiv_t
  113. endif
  114.  
  115. syn keyword    cStructure    struct union enum typedef
  116. syn keyword    cStorageClass    static register auto volatile extern const
  117.  
  118. if !exists("c_no_ansi") || exists("c_ansi_constants")
  119.   syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__
  120.   syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
  121.   syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
  122.   syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
  123.   syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
  124.   syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
  125.   syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
  126.   syn keyword cConstant FLT_RADIX FLT_ROUNDS
  127.   syn keyword cConstant FLT_DIG FLT_MANT_DIG FLT_EPSILON
  128.   syn keyword cConstant DBL_DIG DBL_MANT_DIG DBL_EPSILON
  129.   syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON
  130.   syn keyword cConstant FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP
  131.   syn keyword cConstant FLT_MIN_10_EXP FLT_MAX_10_EXP
  132.   syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP
  133.   syn keyword cConstant DBL_MIN_10_EXP DBL_MAX_10_EXP
  134.   syn keyword cConstant LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP
  135.   syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP
  136.   syn keyword cConstant HUGE_VAL EDOM ERANGE CLOCKS_PER_SEC NULL
  137.   syn keyword cConstant LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY
  138.   syn keyword cConstant LC_NUMERIC LC_TIME
  139.   syn keyword cConstant SIG_DFL SIG_ERR SIG_IGN
  140.   syn keyword cConstant SIGABRT SIGFPE SIGILL SIGINT SIGSEGV SIGTERM
  141.   syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF
  142.   syn keyword cConstant FOPEN_MAX FILENAME_MAX L_tmpnam
  143.   syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET
  144.   syn keyword cConstant TMP_MAX stderr stdin stdout
  145.   syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  146. endif
  147.  
  148. syn region    cPreCondit    start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\|else\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cString,cCharacter,cNumbers,cCommentError,cSpaceError
  149. syn match    cPreCondit    "^\s*#\s*\(else\|endif\)\>"
  150. if !exists("c_no_if0")
  151.   syn region    cCppOut        start="^\s*#\s*if\s\+0\>" end=".\|$" contains=cCppOut2
  152.   syn region    cCppOut2    contained start="0" end="^\s*#\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip
  153.   syn region    cCppSkip    contained start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*#\s*endif\>" contains=cSpaceError,cCppSkip
  154. endif
  155. syn region    cIncluded    contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  156. syn match    cIncluded    contained "<[^>]*>"
  157. syn match    cInclude    "^\s*#\s*include\>\s*["<]" contains=cIncluded
  158. "syn match cLineSkip    "\\$"
  159. syn cluster    cPreProcGroup    contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  160. syn region    cDefine        start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup
  161. syn region    cPreProc    start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup
  162.  
  163. " Highlight User Labels
  164. syn cluster    cMultiGroup    contains=cIncluded,cSpecial,@cCommentGroup,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  165. syn region    cMulti        transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup
  166. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  167. syn cluster    cLabelGroup    contains=cUserLabel
  168. syn match    cUserCont    "^\s*\I\i*\s*:$" contains=@cLabelGroup
  169. syn match    cUserCont    ";\s*\I\i*\s*:$" contains=@cLabelGroup
  170. syn match    cUserCont    "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  171. syn match    cUserCont    ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  172.  
  173. syn match    cUserLabel    "\I\i*" contained
  174.  
  175. " Avoid recognizing most bitfields as labels
  176. syn match    cBitField    "^\s*\I\i*\s*:\s*[1-9]"me=e-1
  177. syn match    cBitField    ";\s*\I\i*\s*:\s*[1-9]"me=e-1
  178.  
  179. if !exists("c_minlines")
  180.   if !exists("c_no_if0")
  181.     let c_minlines = 50        " #if 0 constructs can be long
  182.   else
  183.     let c_minlines = 15        " mostly for () constructs
  184.   endif
  185. endif
  186. exec "syn sync ccomment cComment minlines=" . c_minlines
  187.  
  188. if !exists("did_c_syntax_inits")
  189.   let did_c_syntax_inits = 1
  190.   " The default methods for highlighting.  Can be overridden later
  191.   hi link cLabel    Label
  192.   hi link cUserLabel    Label
  193.   hi link cConditional    Conditional
  194.   hi link cRepeat    Repeat
  195.   hi link cCharacter    Character
  196.   hi link cSpecialCharacter cSpecial
  197.   hi link cNumber    Number
  198.   hi link cOctal    Number
  199.   hi link cOctalZero    PreProc        " link this to Error if you want
  200.   hi link cFloat    Float
  201.   hi link cOctalError    cError
  202.   hi link cParenError    cError
  203.   hi link cErrInParen    cError
  204.   hi link cErrInBracket    cError
  205.   hi link cCommentError    cError
  206.   hi link cSpaceError    cError
  207.   hi link cSpecialError    cError
  208.   hi link cOperator    Operator
  209.   hi link cStructure    Structure
  210.   hi link cStorageClass    StorageClass
  211.   hi link cInclude    Include
  212.   hi link cPreProc    PreProc
  213.   hi link cDefine    Macro
  214.   hi link cIncluded    cString
  215.   hi link cError    Error
  216.   hi link cStatement    Statement
  217.   hi link cPreCondit    PreCondit
  218.   hi link cType        Type
  219.   hi link cConstant    Constant
  220.   hi link cCommentError    cError
  221.   hi link cCommentString cString
  222.   hi link cComment2String cString
  223.   hi link cCommentSkip    cComment
  224.   hi link cString    String
  225.   hi link cComment    Comment
  226.   hi link cSpecial    SpecialChar
  227.   hi link cTodo        Todo
  228.   hi link cCppSkip    cCppOut
  229.   hi link cCppOut2    cCppOut
  230.   hi link cCppOut    Comment
  231. endif
  232.  
  233. let b:current_syntax = "c"
  234.  
  235. " vim: ts=8
  236.