" Vim syntax file " Language: C0 " Maintainer: Josiah Boning (jboning) " Last Change: 2010 Sep 7 " A modification of the standard vim C syntax file by Bram. " " place in .vim/syntax/ " Quit when a (custom) syntax file was already loaded if exists("b:current_syntax") finish endif " A bunch of useful C keywords syn keyword cStatement break return continue syn keyword cConditional if else syn keyword cRepeat while for syn keyword cMemory alloc alloc_array syn keyword cAssert assert syn keyword cTodo contained TODO FIXME XXX " It's easy to accidentally add a space after a backslash that was intended " for line continuation. Some compilers allow it, which makes it " unpredicatable and should be avoided. syn match cBadContinuation contained "\\\s\+$" " cCommentGroup allows adding matches for special things in comments syn cluster cCommentGroup contains=cTodo,cBadContinuation " String and Character constants " Highlight special characters (those which have a backslash) differently syn match cSpecialError display contained "\\[^0'\"?\\abfnrtv]" syn match cSpecial display contained "\\[0'\"?\\abfnrtv]" if exists("c_no_cformat") syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cSpecialError,@Spell else if !exists("c_no_c99") " ISO C99 syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained else syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained endif syn match cFormat display "%%" contained syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cSpecialError,cFormat,@Spell endif syn match cCharacter "L\='[^\\]'" "syn match cCharacter "L\='[^']*'" contains=cSpecial,cSpecialError syn match cSpecialCharErr "L\='\\[^0'\"?\\abfnrtv]'" syn match cSpecialCharacter "L\='\\[0'\"?\\abfnrtv]'" "when wanted, highlight trailing white space if exists("c_space_errors") if !exists("c_no_trail_space_error") syn match cSpaceError display excludenl "\s\+$" endif if !exists("c_no_tab_space_error") syn match cSpaceError display " \+\t"me=e-1 endif endif " This should be before cErrInParen to avoid problems with #define ({ xxx }) if exists("c_curly_error") syntax match cCurlyError "}" syntax region cBlock start="{" end="}" contains=ALLBUT,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,@Spell fold else syntax region cBlock start="{" end="}" transparent fold endif "catch errors caused by wrong parenthesis and brackets syn cluster cParenGroup contains=cParenError,cUse,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cBitField,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cNumbersCom if exists("c_no_curly_error") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell syn match cParenError display ")" syn match cErrInParen display contained "^[{}]" elseif exists("c_no_bracket_error") syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell syn match cParenError display ")" syn match cErrInParen display contained "[{}]" else syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@Spell " cCppParen: same as cParen but ends at end-of-line; used in cDefine syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell syn match cParenError display "[\])]" syn match cErrInParen display contained "[\]{}]" syn region cBracket transparent start='\[' end=']' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@Spell " cCppBracket: same as cParen but ends at end-of-line; used in cDefine syn region cCppBracket transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell syn match cErrInBracket display contained "[);{}]" endif "integer number syn case ignore syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>" "hex number syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" syn case match " c0 annotations syntax keyword cAnnoSpec contained requires ensures loop_invariant assert syntax match cAnnoVal contained "\\\(result\|length\|old\)" if exists("c_comment_strings") " A comment can contain cString, cCharacter and cNumber. " But a "*/" inside a cString in a cComment DOES end the comment! So we " need to use a special type of cString: cCommentString, which also ends on " "*/", and sees a "*" at the start of the line as comment again. " Unfortunately this doesn't very well work for // type of comments :-( syntax match cCommentSkip contained "^\s*\*\($\|\s\+\)" syntax region cCommentString contained start=+L\=\\\@c and the like don't trigger #use highlighting syn match cUsed display contained "^.*use.*<[^>]*>" syn match cUse display "^\s*#\s*use\>\s*["<]" contains=cUsed if exists("c_minlines") let b:c_minlines = c_minlines else if !exists("c_no_if0") let b:c_minlines = 50 " #if 0 constructs can be long else let b:c_minlines = 15 " mostly for () constructs endif endif if exists("c_curly_error") syn sync fromstart else exec "syn sync ccomment cComment minlines=" . b:c_minlines endif " Define the default highlighting. " Only used when an item doesn't have highlighting yet hi def link cFormat cSpecial hi def link cCommentL cComment hi def link cAnnoL cAnno hi def link cCommentStart cComment hi def link cConditional Conditional hi def link cRepeat Repeat hi def link cMemory Keyword hi def link cAssert Keyword hi def link cCharacter Character hi def link cSpecialCharacter cSpecial hi def link cNumber Number hi def link cParenError cError hi def link cErrInParen cError hi def link cErrInBracket cError hi def link cCommentError cError hi def link cCommentStartError cError hi def link cSpaceError cError hi def link cSpecialCharErr cError hi def link cSpecialError cError hi def link cCurlyError cError hi def link cStructure Structure hi def link cUse Include hi def link cUsed cString hi def link cError Error hi def link cStatement Statement hi def link cPreCondit PreCondit hi def link cType Type hi def link cConstant Constant hi def link cCommentString cString hi def link cComment2String cString hi def link cCommentSkip cComment hi def link cString String hi def link cComment Comment hi def link cAnno Comment hi def link cAnnoSpec Keyword hi def link cAnnoVal Keyword hi def link cSpecial SpecialChar hi def link cTodo Todo hi def link cBadContinuation Error hi def link cCppSkip cCppOut hi def link cCppOut2 cCppOut hi def link cCppOut Comment let b:current_syntax = "c0" " vim: ts=8