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 |
| 6 | " Last Change: 2020 Jan 15 |
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 | |
| 16 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | " some special characters |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 18 | syn match makeSpecial "^\s*[@+-]\+" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | syn match makeNextLine "\\\n\s*" |
| 20 | |
| 21 | " some directives |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 22 | syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)" |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 23 | syn match makeInclude "^ *[-s]\=include\s.*$" |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 24 | syn match makeStatement "^ *vpath" |
| 25 | syn match makeExport "^ *\(export\|unexport\)\>" |
| 26 | syn match makeOverride "^ *override" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 27 | hi link makeOverride makeStatement |
| 28 | hi link makeExport makeStatement |
| 29 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 30 | " catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend |
| 31 | syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
| 33 | " Microsoft Makefile specials |
| 34 | syn case ignore |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 35 | syn match makeInclude "^!\s*include\s.*$" |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 36 | 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] | 37 | syn case match |
| 38 | |
| 39 | " identifiers |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 40 | syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent |
| 41 | syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | syn match makeIdent "\$\$\w*" |
| 43 | syn match makeIdent "\$[^({]" |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 44 | syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2 |
Bram Moolenaar | ade0d39 | 2020-01-21 22:33:58 +0100 | [diff] [blame] | 45 | syn match makeIdent "^ *[^:#= \t]*\s*::="me=e-3 |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 46 | syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | syn match makeIdent "%" |
| 48 | |
| 49 | " Makefile.in variables |
| 50 | syn match makeConfig "@[A-Za-z0-9_]\+@" |
| 51 | |
| 52 | " make targets |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 53 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 |
| 54 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 56 | 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,makeComment,makeDString skipnl nextGroup=makeCommands |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 57 | syn match makeTarget "^[~A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget,makeComment skipnl nextgroup=makeCommands,makeCommandError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 58 | |
Bram Moolenaar | 2b8388b | 2015-02-28 13:11:45 +0100 | [diff] [blame] | 59 | 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,makeComment skipnl nextGroup=makeCommands |
| 60 | 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,makeComment skipnl nextgroup=makeCommands,makeCommandError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 61 | |
| 62 | syn match makeCommandError "^\s\+\S.*" contained |
| 63 | 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 |
| 64 | syn match makeCmdNextLine "\\\n."he=e-1 contained |
| 65 | |
| 66 | |
| 67 | " Statements / Functions (GNU make) |
Bram Moolenaar | 4c92e75 | 2019-02-17 21:18:32 +0100 | [diff] [blame] | 68 | 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] | 69 | |
| 70 | " Comment |
| 71 | if exists("make_microsoft") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 72 | syn match makeComment "#.*" contains=@Spell,makeTodo |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 73 | elseif !exists("make_no_comments") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 74 | syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo |
| 75 | syn match makeComment "#$" contains=@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 76 | endif |
| 77 | syn 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 |
| 84 | syn match makeEscapedChar "\\[^$]" |
| 85 | |
| 86 | |
Bram Moolenaar | 9834b96 | 2019-12-04 20:43:03 +0100 | [diff] [blame] | 87 | syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent |
| 88 | syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 89 | syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine |
| 90 | |
| 91 | " Syncing |
| 92 | syn 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. |
| 97 | syn sync match makeCommandSync groupthere NONE "^[^\t#]" |
| 98 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]" |
| 99 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$" |
| 100 | |
| 101 | " Define the default highlighting. |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 102 | " Only when an item doesn't have highlighting yet |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 103 | |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 104 | hi def link makeNextLine makeSpecial |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 105 | hi def link makeCmdNextLine makeSpecial |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 106 | hi def link makeSpecTarget Statement |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 107 | if !exists("make_no_commands") |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 108 | hi def link makeCommands Number |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 109 | endif |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 110 | hi def link makeImplicit Function |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 111 | hi def link makeTarget Function |
| 112 | hi def link makeInclude Include |
Bram Moolenaar | 723dd94 | 2019-04-04 13:11:03 +0200 | [diff] [blame] | 113 | hi def link makePreCondit PreCondit |
| 114 | hi def link makeStatement Statement |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 115 | hi def link makeIdent Identifier |
| 116 | hi def link makeSpecial Special |
| 117 | hi def link makeComment Comment |
| 118 | hi def link makeDString String |
| 119 | hi def link makeSString String |
| 120 | hi def link makeBString Function |
| 121 | hi def link makeError Error |
| 122 | hi def link makeTodo Todo |
| 123 | hi def link makeDefine Define |
| 124 | hi def link makeCommandError Error |
| 125 | hi def link makeConfig PreCondit |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | |
| 127 | let b:current_syntax = "make" |
| 128 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 129 | let &cpo = s:cpo_save |
| 130 | unlet s:cpo_save |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | " vim: ts=8 |