vb@0: " Vim syntax file vb@0: " Language: YML2 generating C vb@0: " Maintainer: Volker Birk vb@0: " Last Change: 2016 July 10 vb@0: vb@0: " Quit when a (custom) syntax file was already loaded vb@0: if exists("b:current_syntax") vb@0: finish vb@0: endif vb@0: vb@0: " A bunch of useful YSLT keywords vb@1: syn keyword cStatement include in decl is alias operator document def param const output value indent all text with withIndent element attrib processing number sort import message debug assert operator goto break return continue asm vb@0: syn keyword cLabel stylesheet estylesheet textstylesheet tstylesheet template function case default vb@0: syn keyword cConditional choose when otherwise if else switch vb@0: syn keyword cRepeat for foreach apply while do vb@0: vb@0: syn keyword cTodo contained TODO FIXME XXX vb@0: vb@0: " It's easy to accidentally add a space after a backslash that was intended vb@0: " for line continuation. Some compilers allow it, which makes it vb@0: " unpredicatable and should be avoided. vb@0: syn match cBadContinuation contained "\\\s\+$" vb@0: vb@0: " cCommentGroup allows adding matches for special things in comments vb@2: syn cluster cCommentGroup contains=cTodo,cBadContinuation,ymlStringComment vb@0: vb@0: " String and Character constants vb@0: " Highlight special characters (those which have a backslash) differently vb@0: syn match cSpecial display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" vb@0: if !exists("c_no_utf") vb@0: syn match cSpecial display contained "\\\(u\x\{4}\|U\x\{8}\)" vb@0: endif vb@2: syn region ymlString start=+L\=«+ end=+»+ contains=cSpecial,@Spell vb@2: syn region ymlStringComment start=+L\=«+ end=+»+ contains=cSpecial,@Spell vb@0: if exists("c_no_cformat") vb@0: syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell,ymlString vb@0: " cCppString: same as cString, but ends at end of line vb@0: syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,@Spell,ymlString vb@0: else vb@0: if !exists("c_no_c99") " ISO C99 vb@0: syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained vb@0: else vb@0: syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained vb@0: endif vb@0: syn match cFormat display "%%" contained vb@0: syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell,ymlString vb@0: " cCppString: same as cString, but ends at end of line vb@0: syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell,ymlString vb@0: endif vb@0: vb@0: syn match cCharacter "L\='[^\\]'" vb@0: syn match cCharacter "L'[^']*'" contains=cSpecial vb@0: if exists("c_gnu") vb@0: syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'" vb@0: syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'" vb@0: else vb@0: syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'" vb@0: syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'" vb@0: endif vb@0: syn match cSpecialCharacter display "L\='\\\o\{1,3}'" vb@0: syn match cSpecialCharacter display "'\\x\x\{1,2}'" vb@0: syn match cSpecialCharacter display "L'\\x\x\+'" vb@0: vb@0: "when wanted, highlight trailing white space vb@0: if exists("c_space_errors") vb@0: if !exists("c_no_trail_space_error") vb@0: syn match cSpaceError display excludenl "\s\+$" vb@0: endif vb@0: if !exists("c_no_tab_space_error") vb@0: syn match cSpaceError display " \+\t"me=e-1 vb@0: endif vb@0: endif vb@0: vb@0: " This should be before cErrInParen to avoid problems with #define ({ xxx }) vb@0: if exists("c_curly_error") vb@0: syntax match cCurlyError "}" vb@0: syntax region cBlock start="{" end="}" contains=ALLBUT,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell fold vb@0: else vb@0: syntax region cBlock start="{" end="}" transparent fold vb@0: endif vb@0: vb@0: "catch errors caused by wrong parenthesis and brackets vb@0: " also accept <% for {, %> for }, <: for [ and :> for ] (C99) vb@0: " But avoid matching <::. vb@0: syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom vb@0: if exists("c_no_curly_error") vb@0: syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell vb@0: " cCppParen: same as cParen but ends at end-of-line; used in cDefine vb@0: syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell vb@0: syn match cParenError display ")" vb@0: syn match cErrInParen display contained "^[{}]\|^<%\|^%>" vb@0: elseif exists("c_no_bracket_error") vb@0: syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell vb@0: " cCppParen: same as cParen but ends at end-of-line; used in cDefine vb@0: syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell vb@0: syn match cParenError display ")" vb@0: syn match cErrInParen display contained "[{}]\|<%\|%>" vb@0: else vb@0: syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell vb@0: " cCppParen: same as cParen but ends at end-of-line; used in cDefine vb@0: syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell vb@0: syn match cParenError display "[\])]" vb@0: syn match cErrInParen display contained "[\]{}]\|<%\|%>" vb@0: syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell vb@0: " cCppBracket: same as cParen but ends at end-of-line; used in cDefine vb@0: syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell vb@0: syn match cErrInBracket display contained "[);{}]\|<%\|%>" vb@0: endif vb@0: vb@0: "integer number, or floating point number without a dot and with "f". vb@0: syn case ignore vb@0: syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal vb@0: " Same, but without octal error (for comments) vb@0: syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal vb@0: syn match cNumber display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>" vb@0: "hex number vb@0: syn match cNumber display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>" vb@0: " Flag the first zero of an octal number as something special vb@0: syn match cOctal display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero vb@0: syn match cOctalZero display contained "\<0" vb@0: syn match cFloat display contained "\d\+f" vb@0: "floating point number, with dot, optional exponent vb@0: syn match cFloat display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=" vb@0: "floating point number, starting with a dot, optional exponent vb@0: syn match cFloat display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>" vb@0: "floating point number, without dot, with exponent vb@0: syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" vb@0: if !exists("c_no_c99") vb@0: "hexadecimal floating point number, optional leading digits, with dot, with exponent vb@0: syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>" vb@0: "hexadecimal floating point number, with leading digits, optional dot, with exponent vb@0: syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>" vb@0: endif vb@0: vb@0: " flag an octal number with wrong digits vb@0: syn match cOctalError display contained "0\o*[89]\d*" vb@0: syn case match vb@0: vb@0: if exists("c_comment_strings") vb@0: " A comment can contain cString, cCharacter and cNumber. vb@0: " But a "*/" inside a cString in a cComment DOES end the comment! So we vb@0: " need to use a special type of cString: cCommentString, which also ends on vb@0: " "*/", and sees a "*" at the start of the line as comment again. vb@0: " Unfortunately this doesn't very well work for // type of comments :-( vb@0: syntax match cCommentSkip contained "^\s*\*\($\|\s\+\)" vb@0: syntax region cCommentString contained start=+L\=\\\@" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError vb@0: syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>" vb@0: if !exists("c_no_if0") vb@0: if !exists("c_no_if0_fold") vb@0: syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 fold vb@0: else vb@0: syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=cCppOut2 vb@0: endif vb@0: syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip vb@0: syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip vb@0: endif vb@0: syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=ymlString vb@0: syn match cIncluded display contained "<[^>]*>" contains=ymlString vb@0: syn match cInclude display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded vb@0: "syn match cLineSkip "\\$" vb@0: syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti vb@0: syn region cDefine start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell vb@0: syn region cPreProc start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell vb@0: vb@0: " Highlight User Labels vb@0: syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString vb@0: syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell vb@0: " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' vb@0: syn cluster cLabelGroup contains=cUserLabel vb@0: syn match cUserCont display "^\s*\I\i*\s*:$" contains=@cLabelGroup vb@0: syn match cUserCont display ";\s*\I\i*\s*:$" contains=@cLabelGroup vb@0: syn match cUserCont display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup vb@0: syn match cUserCont display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup vb@0: vb@0: syn match cUserLabel display "\I\i*" contained vb@0: vb@0: " Avoid recognizing most bitfields as labels vb@0: syn match cBitField display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType vb@0: syn match cBitField display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType vb@0: vb@0: if exists("c_minlines") vb@0: let b:c_minlines = c_minlines vb@0: else vb@0: if !exists("c_no_if0") vb@0: let b:c_minlines = 50 " #if 0 constructs can be long vb@0: else vb@0: let b:c_minlines = 15 " mostly for () constructs vb@0: endif vb@0: endif vb@0: if exists("c_curly_error") vb@0: syn sync fromstart vb@0: else vb@0: exec "syn sync ccomment cComment minlines=" . b:c_minlines vb@0: endif vb@0: vb@0: " Define the default highlighting. vb@0: " Only used when an item doesn't have highlighting yet vb@0: hi def link cFormat cSpecial vb@0: hi def link cCppString cString vb@0: hi def link cCommentL cComment vb@0: hi def link cCommentStart cComment vb@0: hi def link cLabel Label vb@0: hi def link cUserLabel Label vb@0: hi def link cConditional Conditional vb@0: hi def link cRepeat Repeat vb@0: hi def link cCharacter Character vb@0: hi def link cSpecialCharacter cSpecial vb@0: hi def link cNumber Number vb@0: hi def link cOctal Number vb@0: hi def link cOctalZero PreProc " link this to Error if you want vb@0: hi def link cFloat Float vb@0: hi def link cOctalError cError vb@0: hi def link cParenError cError vb@0: hi def link cErrInParen cError vb@0: hi def link cErrInBracket cError vb@0: hi def link cCommentError cError vb@0: hi def link cCommentStartError cError vb@0: hi def link cSpaceError cError vb@0: hi def link cSpecialError cError vb@0: hi def link cCurlyError cError vb@0: hi def link cOperator Operator vb@0: hi def link cStructure Structure vb@0: hi def link cStorageClass StorageClass vb@0: hi def link cInclude Include vb@0: hi def link cPreProc PreProc vb@0: hi def link cDefine Macro vb@0: hi def link cIncluded cString vb@0: hi def link cError Error vb@0: hi def link cStatement Statement vb@0: hi def link cPreCondit PreCondit vb@0: hi def link cType Type vb@0: hi def link cConstant Constant vb@0: hi def link cCommentString cString vb@0: hi def link cComment2String cString vb@0: hi def link cCommentSkip cComment vb@0: hi def link cString String vb@0: hi def link cComment Comment vb@0: hi def link cSpecial SpecialChar vb@0: hi def link cTodo Todo vb@0: hi def link cBadContinuation Error vb@0: hi def link cCppSkip cCppOut vb@0: hi def link cCppOut2 cCppOut vb@0: hi def link cCppOut Comment vb@0: hi def link ymlString Operator vb@2: hi def link ymlStringComment Operator vb@0: let b:current_syntax = "yml2" vb@0: vb@0: " vim: ts=8