Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Makefile |
Bram Moolenaar | ade0d39 | 2020-01-21 22:33:58 +0100 | [diff] [blame] | 3 | " Maintainer: Roland Hieber <rohieb+vim-iR0jGdkV@rohieb.name>, <https://github.com/rohieb> |
Bram Moolenaar | 4c92e75 | 2019-02-17 21:18:32 +0100 | [diff] [blame] | 4 | " Previous Maintainer: Claudio Fleiner <claudio@fleiner.com> |
Bram Moolenaar | ade0d39 | 2020-01-21 22:33:58 +0100 | [diff] [blame] | 5 | " URL: https://github.com/vim/vim/blob/master/runtime/syntax/make.vim |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 6 | " Last Change: 2022 Nov 06 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 8 | " quit when a syntax file was already loaded |
| 9 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10 | finish |
| 11 | endif |
| 12 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 13 | let s:cpo_save = &cpo |
| 14 | set cpo&vim |
| 15 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | " some special characters |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 17 | syn match makeSpecial "^\s*[@+-]\+" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 18 | syn match makeNextLine "\\\n\s*" |
| 19 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 20 | " catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 21 | syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" |
| 22 | \ contains=makeStatement,makeIdent,makePreCondit,makeDefine |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | |
| 24 | " Microsoft Makefile specials |
| 25 | syn case ignore |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 26 | syn match makeInclude "^!\s*include\s.*$" |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 27 | syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s*if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 28 | syn case match |
| 29 | |
| 30 | " identifiers |
Ken Takata | eb4b903 | 2024-07-25 21:07:13 +0200 | [diff] [blame] | 31 | if 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 |
| 34 | else |
| 35 | syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent |
| 36 | syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent |
| 37 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | syn match makeIdent "\$\$\w*" |
| 39 | syn match makeIdent "\$[^({]" |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 40 | syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2 |
Bram Moolenaar | ade0d39 | 2020-01-21 22:33:58 +0100 | [diff] [blame] | 41 | syn match makeIdent "^ *[^:#= \t]*\s*::="me=e-3 |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 42 | syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 43 | syn match makeIdent "%" |
| 44 | |
| 45 | " Makefile.in variables |
| 46 | syn match makeConfig "@[A-Za-z0-9_]\+@" |
| 47 | |
| 48 | " make targets |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 49 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 |
| 50 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 52 | syn region makeTarget transparent matchgroup=makeTarget |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 53 | \ start="^[~A-Za-z0-9_./$(){}%-][A-Za-z0-9_./\t ${}()%-]*&\?:\?:\{1,2}[^:=]"rs=e-1 |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 54 | \ end="[^\\]$" |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 55 | \ keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment,makeDString |
| 56 | \ skipnl nextGroup=makeCommands |
Bram Moolenaar | 76db9e0 | 2022-11-09 21:21:04 +0000 | [diff] [blame] | 57 | syn match makeTarget "^[~A-Za-z0-9_./$(){}%*@-][A-Za-z0-9_./\t $(){}%*@-]*&\?::\=\s*$" |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 58 | \ contains=makeIdent,makeSpecTarget,makeComment |
| 59 | \ skipnl nextgroup=makeCommands,makeCommandError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 60 | |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 61 | syn region makeSpecTarget transparent matchgroup=makeSpecTarget |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 62 | \ 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 Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 63 | \ end="[^\\]$" keepend |
| 64 | \ contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands |
Bram Moolenaar | b529cfb | 2022-07-25 15:42:07 +0100 | [diff] [blame] | 65 | syn 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 Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 66 | \ contains=makeIdent,makeComment |
| 67 | \ skipnl nextgroup=makeCommands,makeCommandError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | |
| 69 | syn match makeCommandError "^\s\+\S.*" contained |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 70 | syn 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | syn match makeCmdNextLine "\\\n."he=e-1 contained |
| 75 | |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 76 | " some directives |
| 77 | syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)" |
| 78 | syn match makeInclude "^ *[-s]\=include\s.*$" |
| 79 | syn match makeStatement "^ *vpath" |
| 80 | syn match makeExport "^ *\(export\|unexport\)\>" |
Bram Moolenaar | 2cfb4a2 | 2020-05-07 18:56:00 +0200 | [diff] [blame] | 81 | syn match makeOverride "^ *override\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 82 | " Statements / Functions (GNU make) |
Bram Moolenaar | 4c92e75 | 2019-02-17 21:18:32 +0100 | [diff] [blame] | 83 | syn 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 84 | |
| 85 | " Comment |
Ken Takata | eb4b903 | 2024-07-25 21:07:13 +0200 | [diff] [blame] | 86 | if !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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | endif |
| 94 | syn 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 |
| 101 | syn match makeEscapedChar "\\[^$]" |
| 102 | |
| 103 | |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 104 | syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent |
| 105 | syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 106 | syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine |
| 107 | |
| 108 | " Syncing |
| 109 | syn 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. |
| 114 | syn sync match makeCommandSync groupthere NONE "^[^\t#]" |
| 115 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]" |
| 116 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$" |
| 117 | |
| 118 | " Define the default highlighting. |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 119 | " Only when an item doesn't have highlighting yet |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 121 | hi def link makeNextLine makeSpecial |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 122 | hi def link makeCmdNextLine makeSpecial |
Bram Moolenaar | b17893a | 2020-03-14 08:19:51 +0100 | [diff] [blame] | 123 | hi link makeOverride makeStatement |
| 124 | hi link makeExport makeStatement |
| 125 | |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 126 | hi def link makeSpecTarget Statement |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 127 | if !exists("make_no_commands") |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 128 | hi def link makeCommands Number |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | endif |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 130 | hi def link makeImplicit Function |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 131 | hi def link makeTarget Function |
| 132 | hi def link makeInclude Include |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 133 | hi def link makePreCondit PreCondit |
| 134 | hi def link makeStatement Statement |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 135 | hi def link makeIdent Identifier |
| 136 | hi def link makeSpecial Special |
| 137 | hi def link makeComment Comment |
| 138 | hi def link makeDString String |
| 139 | hi def link makeSString String |
| 140 | hi def link makeBString Function |
| 141 | hi def link makeError Error |
| 142 | hi def link makeTodo Todo |
| 143 | hi def link makeDefine Define |
| 144 | hi def link makeCommandError Error |
| 145 | hi def link makeConfig PreCondit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 146 | |
| 147 | let b:current_syntax = "make" |
| 148 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 149 | let &cpo = s:cpo_save |
| 150 | unlet s:cpo_save |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 151 | " vim: ts=8 |