blob: d3ddf782912d401152ffa608a457cee7ef169147 [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 Moolenaar76db9e02022-11-09 21:21:04 +00006" Last Change: 2022 Nov 06
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
Ken Takataeb4b9032024-07-25 21:07:13 +020031if exists("b:make_microsoft") || exists("make_microsoft")
32 syn region makeIdent start="\$(" end=")" contains=makeStatement,makeIdent
33 syn region makeIdent start="\${" end="}" contains=makeStatement,makeIdent
34else
35 syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
36 syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
37endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000038syn match makeIdent "\$\$\w*"
39syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010040syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
Bram Moolenaarade0d392020-01-21 22:33:58 +010041syn match makeIdent "^ *[^:#= \t]*\s*::="me=e-3
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010042syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000043syn match makeIdent "%"
44
45" Makefile.in variables
46syn match makeConfig "@[A-Za-z0-9_]\+@"
47
48" make targets
Bram Moolenaar9834b962019-12-04 20:43:03 +010049syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1
50syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaarb17893a2020-03-14 08:19:51 +010052syn region makeTarget transparent matchgroup=makeTarget
Bram Moolenaar76db9e02022-11-09 21:21:04 +000053 \ start="^[~A-Za-z0-9_./$(){}%-][A-Za-z0-9_./\t ${}()%-]*&\?:\?:\{1,2}[^:=]"rs=e-1
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010054 \ end="[^\\]$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010055 \ keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment,makeDString
56 \ skipnl nextGroup=makeCommands
Bram Moolenaar76db9e02022-11-09 21:21:04 +000057syn match makeTarget "^[~A-Za-z0-9_./$(){}%*@-][A-Za-z0-9_./\t $(){}%*@-]*&\?::\=\s*$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010058 \ contains=makeIdent,makeSpecTarget,makeComment
59 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
Bram Moolenaarb17893a2020-03-14 08:19:51 +010061syn region makeSpecTarget transparent matchgroup=makeSpecTarget
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010062 \ start="^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\|ONESHELL\)\>\s*:\{1,2}[^:=]"rs=e-1
Bram Moolenaarb17893a2020-03-14 08:19:51 +010063 \ end="[^\\]$" keepend
64 \ contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010065syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\|ONESHELL\)\>\s*::\=\s*$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010066 \ contains=makeIdent,makeComment
67 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
69syn match makeCommandError "^\s\+\S.*" contained
Bram Moolenaarb17893a2020-03-14 08:19:51 +010070syn region makeCommands contained start=";"hs=s+1 start="^\t"
71 \ end="^[^\t#]"me=e-1,re=e-1 end="^$"
72 \ contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString
73 \ nextgroup=makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000074syn match makeCmdNextLine "\\\n."he=e-1 contained
75
Bram Moolenaarb17893a2020-03-14 08:19:51 +010076" some directives
77syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)"
78syn match makeInclude "^ *[-s]\=include\s.*$"
79syn match makeStatement "^ *vpath"
80syn match makeExport "^ *\(export\|unexport\)\>"
Bram Moolenaar2cfb4a22020-05-07 18:56:00 +020081syn match makeOverride "^ *override\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000082" Statements / Functions (GNU make)
Bram Moolenaar4c92e752019-02-17 21:18:32 +010083syn 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 +000084
85" Comment
Ken Takataeb4b9032024-07-25 21:07:13 +020086if !exists("make_no_comments")
87 if exists("b:make_microsoft") || exists("make_microsoft")
88 syn match makeComment "#.*" contains=@Spell,makeTodo
89 else
90 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
91 syn match makeComment "#$" contains=@Spell
92 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000093endif
94syn keyword makeTodo TODO FIXME XXX contained
95
96" match escaped quotes and any other escaped character
97" except for $, as a backslash in front of a $ does
98" not make it a standard character, but instead it will
99" still act as the beginning of a variable
100" The escaped char is not highlightet currently
101syn match makeEscapedChar "\\[^$]"
102
103
Bram Moolenaar9834b962019-12-04 20:43:03 +0100104syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent
105syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
107
108" Syncing
109syn sync minlines=20 maxlines=200
110
111" Sync on Make command block region: When searching backwards hits a line that
112" can't be a command or a comment, use makeCommands if it looks like a target,
113" NONE otherwise.
114syn sync match makeCommandSync groupthere NONE "^[^\t#]"
115syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
116syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
117
118" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200119" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
Bram Moolenaar723dd942019-04-04 13:11:03 +0200121hi def link makeNextLine makeSpecial
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200122hi def link makeCmdNextLine makeSpecial
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100123hi link makeOverride makeStatement
124hi link makeExport makeStatement
125
Bram Moolenaar723dd942019-04-04 13:11:03 +0200126hi def link makeSpecTarget Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200127if !exists("make_no_commands")
Bram Moolenaar723dd942019-04-04 13:11:03 +0200128hi def link makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129endif
Bram Moolenaar723dd942019-04-04 13:11:03 +0200130hi def link makeImplicit Function
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200131hi def link makeTarget Function
132hi def link makeInclude Include
Bram Moolenaar723dd942019-04-04 13:11:03 +0200133hi def link makePreCondit PreCondit
134hi def link makeStatement Statement
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200135hi def link makeIdent Identifier
136hi def link makeSpecial Special
137hi def link makeComment Comment
138hi def link makeDString String
139hi def link makeSString String
140hi def link makeBString Function
141hi def link makeError Error
142hi def link makeTodo Todo
143hi def link makeDefine Define
144hi def link makeCommandError Error
145hi def link makeConfig PreCondit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
147let b:current_syntax = "make"
148
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200149let &cpo = s:cpo_save
150unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151" vim: ts=8