blob: d0d7f1523b5349749b0f358ca3dcf2fd8bcd079e [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Makefile
Bram Moolenaarade0d392020-01-21 22:33:58 +01003" Maintainer: Roland Hieber <rohieb+vim-iR0jGdkV@rohieb.name>, <https://github.com/rohieb>
Bram Moolenaar4c92e752019-02-17 21:18:32 +01004" Previous Maintainer: Claudio Fleiner <claudio@fleiner.com>
Bram Moolenaarade0d392020-01-21 22:33:58 +01005" URL: https://github.com/vim/vim/blob/master/runtime/syntax/make.vim
Bram Moolenaar2cfb4a22020-05-07 18:56:00 +02006" Last Change: 2020 May 03
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
Bram Moolenaar071d4272004-06-13 20:20:40 +000016" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000017syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000018syn match makeNextLine "\\\n\s*"
19
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020020" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
Bram Moolenaarb17893a2020-03-14 08:19:51 +010021syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$"
22 \ contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000023
24" Microsoft Makefile specials
25syn case ignore
Bram Moolenaar9834b962019-12-04 20:43:03 +010026syn match makeInclude "^!\s*include\s.*$"
Bram Moolenaar723dd942019-04-04 13:11:03 +020027syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s*if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000028syn case match
29
30" identifiers
Bram Moolenaar9834b962019-12-04 20:43:03 +010031syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
32syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +000033syn match makeIdent "\$\$\w*"
34syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010035syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
Bram Moolenaarade0d392020-01-21 22:33:58 +010036syn match makeIdent "^ *[^:#= \t]*\s*::="me=e-3
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010037syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000038syn match makeIdent "%"
39
40" Makefile.in variables
41syn match makeConfig "@[A-Za-z0-9_]\+@"
42
43" make targets
Bram Moolenaar9834b962019-12-04 20:43:03 +010044syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1
45syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +000046
Bram Moolenaarb17893a2020-03-14 08:19:51 +010047syn region makeTarget transparent matchgroup=makeTarget
48 \ start="^[~A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"rs=e-1
49 \ end=";"re=e-1,me=e-1 end="[^\\]$"
50 \ keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment,makeDString
51 \ skipnl nextGroup=makeCommands
52syn match makeTarget "^[~A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$"
53 \ contains=makeIdent,makeSpecTarget,makeComment
54 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaarb17893a2020-03-14 08:19:51 +010056syn region makeSpecTarget transparent matchgroup=makeSpecTarget
57 \ 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
58 \ end="[^\\]$" keepend
59 \ 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*$"
61 \ contains=makeIdent,makeComment
62 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
64syn match makeCommandError "^\s\+\S.*" contained
Bram Moolenaarb17893a2020-03-14 08:19:51 +010065syn region makeCommands contained start=";"hs=s+1 start="^\t"
66 \ end="^[^\t#]"me=e-1,re=e-1 end="^$"
67 \ contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString
68 \ nextgroup=makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000069syn match makeCmdNextLine "\\\n."he=e-1 contained
70
Bram Moolenaarb17893a2020-03-14 08:19:51 +010071" some directives
72syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)"
73syn match makeInclude "^ *[-s]\=include\s.*$"
74syn match makeStatement "^ *vpath"
75syn match makeExport "^ *\(export\|unexport\)\>"
Bram Moolenaar2cfb4a22020-05-07 18:56:00 +020076syn match makeOverride "^ *override\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000077" Statements / Functions (GNU make)
Bram Moolenaar4c92e752019-02-17 21:18:32 +010078syn 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 +000079
80" Comment
81if exists("make_microsoft")
Bram Moolenaar9964e462007-05-05 17:54:07 +000082 syn match makeComment "#.*" contains=@Spell,makeTodo
Bram Moolenaar8dff8182006-04-06 20:18:50 +000083elseif !exists("make_no_comments")
Bram Moolenaar9964e462007-05-05 17:54:07 +000084 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
85 syn match makeComment "#$" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000086endif
87syn keyword makeTodo TODO FIXME XXX contained
88
89" match escaped quotes and any other escaped character
90" except for $, as a backslash in front of a $ does
91" not make it a standard character, but instead it will
92" still act as the beginning of a variable
93" The escaped char is not highlightet currently
94syn match makeEscapedChar "\\[^$]"
95
96
Bram Moolenaar9834b962019-12-04 20:43:03 +010097syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent
98syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +000099syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
100
101" Syncing
102syn sync minlines=20 maxlines=200
103
104" Sync on Make command block region: When searching backwards hits a line that
105" can't be a command or a comment, use makeCommands if it looks like a target,
106" NONE otherwise.
107syn sync match makeCommandSync groupthere NONE "^[^\t#]"
108syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
109syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
110
111" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200112" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
Bram Moolenaar723dd942019-04-04 13:11:03 +0200114hi def link makeNextLine makeSpecial
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200115hi def link makeCmdNextLine makeSpecial
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100116hi link makeOverride makeStatement
117hi link makeExport makeStatement
118
Bram Moolenaar723dd942019-04-04 13:11:03 +0200119hi def link makeSpecTarget Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200120if !exists("make_no_commands")
Bram Moolenaar723dd942019-04-04 13:11:03 +0200121hi def link makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122endif
Bram Moolenaar723dd942019-04-04 13:11:03 +0200123hi def link makeImplicit Function
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200124hi def link makeTarget Function
125hi def link makeInclude Include
Bram Moolenaar723dd942019-04-04 13:11:03 +0200126hi def link makePreCondit PreCondit
127hi def link makeStatement Statement
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200128hi def link makeIdent Identifier
129hi def link makeSpecial Special
130hi def link makeComment Comment
131hi def link makeDString String
132hi def link makeSString String
133hi def link makeBString Function
134hi def link makeError Error
135hi def link makeTodo Todo
136hi def link makeDefine Define
137hi def link makeCommandError Error
138hi def link makeConfig PreCondit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139
140let b:current_syntax = "make"
141
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200142let &cpo = s:cpo_save
143unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144" vim: ts=8