robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
ab20681c52
master
1" Vim syntax file 2" Language: C macro for C preprocessor 3" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu> 4" Last Change: 2024 Dec 31 5" modified from syntax/c.vim 6 7" C compiler has a preprocessor: `cpp -P test.txt` 8" test.txt doesn't need to be a C file 9if exists ( "b:current_syntax" ) 10finish 11endif 12 13let s: cpo_save = & cpo 14set cpo & vim 15 16" Accept %: for # (C99) 17syn region cmacroPreCondit start = "^\s * \zs\%(%:\|#\)\s * \%(if\|ifdef\|ifndef\|elif\)\> "skip = "\\$ "end = "$ "keepend contains = cmacroCppParen , cmacroNumbers 18syn match cmacroPreConditMatch display "^\s * \zs\%(%:\|#\)\s * \%(else\|endif\)\> " 19if ! exists ( "c_no_if0" ) 20syn cluster cmacroCppOutInGroup contains = cmacroCppInIf , cmacroCppInElse , cmacroCppInElse2 , cmacroCppOutIf , cmacroCppOutIf2 , cmacroCppOutElse , cmacroCppInSkip , cmacroCppOutSkip 21syn region cmacroCppOutWrapper start = "^\s * \zs\%(%:\|#\)\s * if\s\+0\+\s * \%($\|//\|/\*\|&\) "end = ".\@=\|$ "contains = cmacroCppOutIf , cmacroCppOutElse , @NoSpell fold 22syn region cmacroCppOutIf contained start = "0\+ "matchgroup = cmacroCppOutWrapper end = "^\s * \%(%:\|#\)\s * endif\> "contains = cmacroCppOutIf2 , cmacroCppOutElse 23if ! exists ( "c_no_if0_fold" ) 24syn region cmacroCppOutIf2 contained matchgroup = cmacroCppOutWrapper start = "0\+ "end = "^\s * \%(%:\|#\)\s * \%(else\>\|elif\s\+\%(0\+\s * \%($\|//\|/\*\|&\)\)\@!\|endif\>\) "me= s-1contains = cmacroCppOutSkip , @Spell fold 25else 26syn region cmacroCppOutIf2 contained matchgroup = cmacroCppOutWrapper start = "0\+ "end = "^\s * \%(%:\|#\)\s * \%(else\>\|elif\s\+\%(0\+\s * \%($\|//\|/\*\|&\)\)\@!\|endif\>\) "me= s-1contains = cmacroCppOutSkip , @Spell 27endif 28syn region cmacroCppOutElse contained matchgroup = cmacroCppOutWrapper start = "^\s * \%(%:\|#\)\s * \%(else\|elif\) "end = "^\s * \%(%:\|#\)\s * endif\> "me= s-1contains = TOP , cmacroPreCondit 29syn region cmacroCppInWrapper start = "^\s * \zs\%(%:\|#\)\s * if\s\+0 * [ 1-9 ] \d * \s * \%($\|//\|/\*\||\) "end = ".\@=\|$ "contains = cmacroCppInIf , cmacroCppInElse fold 30syn region cmacroCppInIf contained matchgroup = cmacroCppInWrapper start = "\d\+ "end = "^\s * \%(%:\|#\)\s * endif\> "contains = TOP , cmacroPreCondit 31if ! exists ( "c_no_if0_fold" ) 32syn region cmacroCppInElse contained start = "^\s * \%(%:\|#\)\s * \%(else\>\|elif\s\+\%(0 * [ 1-9 ] \d * \s * \%($\|//\|/\*\||\)\)\@!\) "end = ".\@=\|$ "containedin = cmacroCppInIf contains = cmacroCppInElse2 fold 33else 34syn region cmacroCppInElse contained start = "^\s * \%(%:\|#\)\s * \%(else\>\|elif\s\+\%(0 * [ 1-9 ] \d * \s * \%($\|//\|/\*\||\)\)\@!\) "end = ".\@=\|$ "containedin = cmacroCppInIf contains = cmacroCppInElse2 35endif 36syn region cmacroCppInElse2 contained matchgroup = cmacroCppInWrapper start = "^\s * \%(%:\|#\)\s * \%(else\|elif\)\%( [ ^/ ] \|/ [ ^/* ] \) * "end = "^\s * \%(%:\|#\)\s * endif\> "me= s-1contains = cmacroCppOutSkip , @Spell 37syn region cmacroCppOutSkip contained start = "^\s * \%(%:\|#\)\s * \%(if\>\|ifdef\>\|ifndef\>\) "skip = "\\$ "end = "^\s * \%(%:\|#\)\s * endif\> "contains = cmacroCppOutSkip 38syn region cmacroCppInSkip contained matchgroup = cmacroCppInWrapper start = "^\s * \%(%:\|#\)\s * \%(if\s\+\%(\d\+\s * \%($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\) "skip = "\\$ "end = "^\s * \%(%:\|#\)\s * endif\> "containedin = cmacroCppOutElse , cmacroCppInIf , cmacroCppInSkip contains = TOP , cmacroPreProc 39endif 40syn region cmacroIncluded display contained start = +" +skip = +\\\\\|\\" +end = +" + 41syn match cmacroIncluded display contained "< [ ^> ] * > " 42syn match cmacroInclude display "^\s * \zs\%(%:\|#\)\s * include\>\s * [ "< ] "contains = cmacroIncluded 43"syn match cmacroLineSkip "\\$" 44syn cluster cmacroPreProcmacroGroup contains = cmacroPreCondit , cmacroIncluded , cmacroInclude , cmacroDefine , cmacroCppOutWrapper , cmacroCppInWrapper , @cmacroCppOutInGroup , cmacroNumbersCom , @cmacroCommentGroup , cmacroParen , cmacroBracket , cmacroMulti , cmacroBadBlock 45syn region cmacroDefine start = "^\s * \zs\%(%:\|#\)\s * \%(define\|undef\)\> "skip = "\\$ "end = "$ "keepend contains = ALLBUT , @cmacroPreProcmacroGroup , @Spell 46syn region cmacroPreProc start = "^\s * \zs\%(%:\|#\)\s * \%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\) "skip = "\\$ "end = "$ "keepend contains = ALLBUT , @cmacroPreProcmacroGroup , @Spell 47 48" be able to fold #pragma regions 49syn region cmacroPragma start = "^\s * #pragma\s\+region\> "end = "^\s * #pragma\s\+endregion\> "transparent keepend extend fold 50 51syn keyword cmacroTodo contained TODO FIXME XXX NOTE 52syn region cmacroComment start = '/\* 'end = '\*/ 'contains = cmacroTodo , @Spell 53syn match cmacroCommentError "\*/ " 54syn region cmacroComment start = '// 'end = '$ 'contains = cmacroTodo , @Spell 55 56" Define the default highlighting. 57" Only used when an item doesn't have highlighting yet 58hi def link cmacroInclude Include 59hi def link cmacroPreProc PreProc 60hi def link cmacroDefine Macro 61hi def link cmacroIncluded cmacroString 62hi def link cmacroCppInWrapper cmacroCppOutWrapper 63hi def link cmacroCppOutWrapper cmacroPreCondit 64hi def link cmacroPreConditMatch cmacroPreCondit 65hi def link cmacroPreCondit PreCondit 66hi def link cmacroCppOutSkip cmacroCppOutIf2 67hi def link cmacroCppInElse2 cmacroCppOutIf2 68hi def link cmacroCppOutIf2 cmacroCppOut 69hi def link cmacroCppOut Comment 70hi def link cmacroTodo Todo 71hi def link cmacroComment Comment 72hi def link cmacroCommentError Error 73 74let b: current_syntax = "cmacro" 75 76let & cpo = s: cpo_save 77unlet s: cpo_save