home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / share / vim / syntax / c.vim < prev    next >
Encoding:
Text File  |  1999-08-10  |  5.6 KB  |  146 lines

  1. " Vim syntax file
  2. " Language:    C
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    1998 Aug 13
  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. " String and Character constants
  18. " Highlight special characters (those which have a backslash) differently
  19. syn match    cSpecial    contained "\\x\x\+\|\\\o\{1,3\}\|\\.\|\\$"
  20. syn region    cString        start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
  21. syn match    cCharacter    "'[^\\]'"
  22. syn match    cSpecialCharacter "'\\.'"
  23. syn match    cSpecialCharacter "'\\\o\{1,3\}'"
  24.  
  25. "when wanted, highlight trailing white space
  26. if exists("c_space_errors")
  27.   syn match    cSpaceError    "\s*$"
  28.   syn match    cSpaceError    " \+\t"me=e-1
  29. endif
  30.  
  31. "catch errors caused by wrong parenthesis
  32. syn cluster    cParenGroup    contains=cParenError,cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
  33. syn region    cParen        transparent start='(' end=')' contains=ALLBUT,@cParenGroup
  34. syn match    cParenError    ")"
  35. syn match    cInParen    contained "[{}]"
  36.  
  37. "integer number, or floating point number without a dot and with "f".
  38. syn case ignore
  39. syn match    cNumber        "\<\d\+\(u\=l\=\|lu\|f\)\>"
  40. "floating point number, with dot, optional exponent
  41. syn match    cFloat        "\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>"
  42. "floating point number, starting with a dot, optional exponent
  43. syn match    cFloat        "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  44. "floating point number, without dot, with exponent
  45. syn match    cFloat        "\<\d\+e[-+]\=\d\+[fl]\=\>"
  46. "hex number
  47. syn match    cNumber        "\<0x\x\+\(u\=l\=\|lu\)\>"
  48. "syn match cIdentifier    "\<[a-z_][a-z0-9_]*\>"
  49. syn case match
  50. " flag an octal number with wrong digits
  51. syn match    cOctalError    "\<0\o*[89]"
  52.  
  53. if exists("c_comment_strings")
  54.   " A comment can contain cString, cCharacter and cNumber.
  55.   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  56.   " need to use a special type of cString: cCommentString, which also ends on
  57.   " "*/", and sees a "*" at the start of the line as comment again.
  58.   " Unfortunately this doesn't very well work for // type of comments :-(
  59.   syntax match    cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  60.   syntax region cCommentString    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  61.   syntax region cComment2String    contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  62.   syntax region cComment    start="/\*" end="\*/" contains=cTodo,cCommentString,cCharacter,cNumber,cFloat,cSpaceError
  63.   syntax match  cComment    "//.*" contains=cTodo,cComment2String,cCharacter,cNumber,cSpaceError
  64. else
  65.   syn region    cComment    start="/\*" end="\*/" contains=cTodo,cSpaceError
  66.   syn match    cComment    "//.*" contains=cTodo,cSpaceError
  67. endif
  68. syntax match    cCommentError    "\*/"
  69.  
  70. syn keyword    cOperator    sizeof
  71. syn keyword    cType        int long short char void size_t
  72. syn keyword    cType        signed unsigned float double
  73. syn keyword    cStructure    struct union enum typedef
  74. syn keyword    cStorageClass    static register auto volatile extern const
  75.  
  76. syn region    cPreCondit    start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\|elif\>\|else\>\|endif\>\)" skip="\\$" end="$" contains=cComment,cString,cCharacter,cNumber,cCommentError,cSpaceError
  77. syn region    cIncluded    contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  78. syn match    cIncluded    contained "<[^>]*>"
  79. syn match    cInclude    "^\s*#\s*include\>\s*["<]" contains=cIncluded
  80. "syn match cLineSkip    "\\$"
  81. syn cluster    cPreProcGroup    contains=cPreCondit,cIncluded,cInclude,cDefine,cInParen,cUserLabel
  82. syn region    cDefine        start="^\s*#\s*\(define\>\|undef\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup
  83. syn region    cPreProc    start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup
  84.  
  85. " Highlight User Labels
  86. syn cluster    cMultiGroup    contains=cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
  87. syn region    cMulti        transparent start='?' end=':' contains=ALLBUT,@cMultiGroup
  88. " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  89. syn match    cUserCont    "^\s*\I\i*\s*:$" contains=cUserLabel
  90. syn match    cUserCont    ";\s*\I\i*\s*:$" contains=cUserLabel
  91. syn match    cUserCont    "^\s*\I\i*\s*:[^:]"me=e-1 contains=cUserLabel
  92. syn match    cUserCont    ";\s*\I\i*\s*:[^:]"me=e-1 contains=cUserLabel
  93.  
  94. syn match    cUserLabel    "\I\i*" contained
  95.  
  96. " Avoid recognizing most bitfields as labels
  97. syn match    cBitField    "^\s*\I\i*\s*:\s*[1-9]"me=e-1
  98. syn match    cBitField    ";\s*\I\i*\s*:\s*[1-9]"me=e-1
  99.  
  100. if !exists("c_minlines")
  101.   let c_minlines = 15
  102. endif
  103. exec "syn sync ccomment cComment minlines=" . c_minlines
  104.  
  105. if !exists("did_c_syntax_inits")
  106.   let did_c_syntax_inits = 1
  107.   " The default methods for highlighting.  Can be overridden later
  108.   hi link cLabel    Label
  109.   hi link cUserLabel    Label
  110.   hi link cConditional    Conditional
  111.   hi link cRepeat    Repeat
  112.   hi link cCharacter    Character
  113.   hi link cSpecialCharacter cSpecial
  114.   hi link cNumber    Number
  115.   hi link cFloat    Float
  116.   hi link cOctalError    cError
  117.   hi link cParenError    cError
  118.   hi link cInParen    cError
  119.   hi link cCommentError    cError
  120.   hi link cSpaceError    cError
  121.   hi link cOperator    Operator
  122.   hi link cStructure    Structure
  123.   hi link cStorageClass    StorageClass
  124.   hi link cInclude    Include
  125.   hi link cPreProc    PreProc
  126.   hi link cDefine    Macro
  127.   hi link cIncluded    cString
  128.   hi link cError    Error
  129.   hi link cStatement    Statement
  130.   hi link cPreCondit    PreCondit
  131.   hi link cType        Type
  132.   hi link cCommentError    cError
  133.   hi link cCommentString cString
  134.   hi link cComment2String cString
  135.   hi link cCommentSkip    cComment
  136.   hi link cString    String
  137.   hi link cComment    Comment
  138.   hi link cSpecial    SpecialChar
  139.   hi link cTodo        Todo
  140.   "hi link cIdentifier    Identifier
  141. endif
  142.  
  143. let b:current_syntax = "c"
  144.  
  145. " vim: ts=8
  146.