3 " Maintainer: Claudio Fleiner <claudio@fleiner.com>
4 " URL: http://www.fleiner.com/vim/syntax/make.vim
5 " Last Change: 2007 Apr 30
7 " For version 5.x: Clear all syntax items
8 " For version 6.x: Quit when a syntax file was already loaded
11 elseif exists("b:current_syntax")
15 " some special characters
16 syn match makeSpecial "^\s*[@+-]\+"
17 syn match makeNextLine "\\\n\s*"
20 syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)"
21 syn match makeInclude "^ *[-s]\=include"
22 syn match makeStatement "^ *vpath"
23 syn match makeExport "^ *\(export\|unexport\)\>"
24 syn match makeOverride "^ *override"
25 hi link makeOverride makeStatement
26 hi link makeExport makeStatement
28 " Koehler: catch unmatched define/endef keywords. endef only matches it is by itself on a line
29 syn region makeDefine start="^\s*define\s" end="^\s*endef\s*$" contains=makeStatement,makeIdent,makePreCondit,makeDefine
31 " Microsoft Makefile specials
33 syn match makeInclude "^! *include"
34 syn match makePreCondit "! *\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|elseif\|else if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
38 syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString
39 syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString
40 syn match makeIdent "\$\$\w*"
41 syn match makeIdent "\$[^({]"
42 syn match makeIdent "^ *\a\w*\s*[:+?!*]="me=e-2
43 syn match makeIdent "^ *\a\w*\s*="me=e-1
44 syn match makeIdent "%"
46 " Makefile.in variables
47 syn match makeConfig "@[A-Za-z0-9_]\+@"
50 " syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>"
51 syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource
52 syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource
54 syn region makeTarget transparent matchgroup=makeTarget start="^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"rs=e-1 end=";"re=e-1,me=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine skipnl nextGroup=makeCommands
55 syn match makeTarget "^[A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget skipnl nextgroup=makeCommands,makeCommandError
57 syn region makeSpecTarget transparent matchgroup=makeSpecTarget start="^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*:\{1,2}[^:=]"rs=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine skipnl nextGroup=makeCommands
58 syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*::\=\s*$" contains=makeIdent skipnl nextgroup=makeCommands,makeCommandError
60 syn match makeCommandError "^\s\+\S.*" contained
61 syn region makeCommands start=";"hs=s+1 start="^\t" end="^[^\t#]"me=e-1,re=e-1 end="^$" contained contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString nextgroup=makeCommandError
62 syn match makeCmdNextLine "\\\n."he=e-1 contained
65 " Statements / Functions (GNU make)
66 syn match makeStatement contained "(\(subst\|addprefix\|addsuffix\|basename\|call\|dir\|error\|eval\|filter-out\|filter\|findstring\|firstword\|foreach\|if\|join\|notdir\|origin\|patsubst\|shell\|sort\|strip\|suffix\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1
69 if exists("make_microsoft")
70 syn match makeComment "#.*" contains=@Spell,makeTodo
71 elseif !exists("make_no_comments")
72 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
73 syn match makeComment "#$" contains=@Spell
75 syn keyword makeTodo TODO FIXME XXX contained
77 " match escaped quotes and any other escaped character
78 " except for $, as a backslash in front of a $ does
79 " not make it a standard character, but instead it will
80 " still act as the beginning of a variable
81 " The escaped char is not highlightet currently
82 syn match makeEscapedChar "\\[^$]"
85 syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent
86 syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent
87 syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
90 syn sync minlines=20 maxlines=200
92 " Sync on Make command block region: When searching backwards hits a line that
93 " can't be a command or a comment, use makeCommands if it looks like a target,
95 syn sync match makeCommandSync groupthere NONE "^[^\t#]"
96 syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
97 syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
99 " Define the default highlighting.
100 " For version 5.7 and earlier: only when not done already
101 " For version 5.8 and later: only when an item doesn't have highlighting yet
102 if version >= 508 || !exists("did_make_syn_inits")
104 let did_make_syn_inits = 1
105 command -nargs=+ HiLink hi link <args>
107 command -nargs=+ HiLink hi def link <args>
110 HiLink makeNextLine makeSpecial
111 HiLink makeCmdNextLine makeSpecial
112 HiLink makeSpecTarget Statement
113 if !exists("make_no_commands")
114 HiLink makeCommands Number
116 HiLink makeImplicit Function
117 HiLink makeTarget Function
118 HiLink makeInclude Include
119 HiLink makePreCondit PreCondit
120 HiLink makeStatement Statement
121 HiLink makeIdent Identifier
122 HiLink makeSpecial Special
123 HiLink makeComment Comment
124 HiLink makeDString String
125 HiLink makeSString String
126 HiLink makeBString Function
127 HiLink makeError Error
129 HiLink makeDefine Define
130 HiLink makeCommandError Error
131 HiLink makeConfig PreCondit
135 let b:current_syntax = "make"