blob: 16e66bc8f240508709d58e4202c4ad7644b581b1 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Makefile
Bram Moolenaar4c92e752019-02-17 21:18:32 +01003" Maintainer: Roland Hieber <rohieb+vim-iR0jGdkV@rohieb.name>
4" Previous Maintainer: Claudio Fleiner <claudio@fleiner.com>
5" URL: https://github.com/vim/vim/syntax/make.vim
6" Last Change: 2019 Feb 08
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02008" quit when a syntax file was already loaded
9if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000010 finish
11endif
12
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020013let s:cpo_save = &cpo
14set cpo&vim
15
16
Bram Moolenaar071d4272004-06-13 20:20:40 +000017" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000018syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000019syn match makeNextLine "\\\n\s*"
20
21" some directives
Bram Moolenaar8dff8182006-04-06 20:18:50 +000022syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)"
23syn match makeInclude "^ *[-s]\=include"
24syn match makeStatement "^ *vpath"
25syn match makeExport "^ *\(export\|unexport\)\>"
26syn match makeOverride "^ *override"
Bram Moolenaar071d4272004-06-13 20:20:40 +000027hi link makeOverride makeStatement
28hi link makeExport makeStatement
29
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020030" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
31syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33" Microsoft Makefile specials
34syn case ignore
Bram Moolenaar8dff8182006-04-06 20:18:50 +000035syn match makeInclude "^! *include"
36syn match makePreCondit "! *\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|elseif\|else if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000037syn case match
38
39" identifiers
40syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString
41syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString
42syn match makeIdent "\$\$\w*"
43syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010044syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
45syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000046syn match makeIdent "%"
47
48" Makefile.in variables
49syn match makeConfig "@[A-Za-z0-9_]\+@"
50
51" make targets
52" syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000053syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020054syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010056syn 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,makeComment skipnl nextGroup=makeCommands
57syn match makeTarget "^[~A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget,makeComment skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010059syn 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,makeComment skipnl nextGroup=makeCommands
60syn 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,makeComment skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
62syn match makeCommandError "^\s\+\S.*" contained
63syn 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
64syn match makeCmdNextLine "\\\n."he=e-1 contained
65
66
67" Statements / Functions (GNU make)
Bram Moolenaar4c92e752019-02-17 21:18:32 +010068syn match makeStatement contained "(\(abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|file\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|guile\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|subst\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1
Bram Moolenaar071d4272004-06-13 20:20:40 +000069
70" Comment
71if exists("make_microsoft")
Bram Moolenaar9964e462007-05-05 17:54:07 +000072 syn match makeComment "#.*" contains=@Spell,makeTodo
Bram Moolenaar8dff8182006-04-06 20:18:50 +000073elseif !exists("make_no_comments")
Bram Moolenaar9964e462007-05-05 17:54:07 +000074 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
75 syn match makeComment "#$" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000076endif
77syn keyword makeTodo TODO FIXME XXX contained
78
79" match escaped quotes and any other escaped character
80" except for $, as a backslash in front of a $ does
81" not make it a standard character, but instead it will
82" still act as the beginning of a variable
83" The escaped char is not highlightet currently
84syn match makeEscapedChar "\\[^$]"
85
86
87syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent
88syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent
89syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
90
91" Syncing
92syn sync minlines=20 maxlines=200
93
94" Sync on Make command block region: When searching backwards hits a line that
95" can't be a command or a comment, use makeCommands if it looks like a target,
96" NONE otherwise.
97syn sync match makeCommandSync groupthere NONE "^[^\t#]"
98syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
99syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
100
101" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200102" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200104hi def link makeNextLine makeSpecial
105hi def link makeCmdNextLine makeSpecial
106hi def link makeSpecTarget Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200107if !exists("make_no_commands")
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200108hi def link makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109endif
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200110hi def link makeImplicit Function
111hi def link makeTarget Function
112hi def link makeInclude Include
113hi def link makePreCondit PreCondit
114hi def link makeStatement Statement
115hi def link makeIdent Identifier
116hi def link makeSpecial Special
117hi def link makeComment Comment
118hi def link makeDString String
119hi def link makeSString String
120hi def link makeBString Function
121hi def link makeError Error
122hi def link makeTodo Todo
123hi def link makeDefine Define
124hi def link makeCommandError Error
125hi def link makeConfig PreCondit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126
127let b:current_syntax = "make"
128
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200129let &cpo = s:cpo_save
130unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131" vim: ts=8