Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Makefile |
| 3 | " Maintainer: Claudio Fleiner <claudio@fleiner.com> |
| 4 | " URL: http://www.fleiner.com/vim/syntax/make.vim |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 5 | " Last Change: 2012 Oct 05 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6 | |
| 7 | " For version 5.x: Clear all syntax items |
| 8 | " For version 6.x: Quit when a syntax file was already loaded |
| 9 | if version < 600 |
| 10 | syntax clear |
| 11 | elseif exists("b:current_syntax") |
| 12 | finish |
| 13 | endif |
| 14 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 15 | let s:cpo_save = &cpo |
| 16 | set cpo&vim |
| 17 | |
| 18 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | " some special characters |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 20 | syn match makeSpecial "^\s*[@+-]\+" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | syn match makeNextLine "\\\n\s*" |
| 22 | |
| 23 | " some directives |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 24 | syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)" |
| 25 | syn match makeInclude "^ *[-s]\=include" |
| 26 | syn match makeStatement "^ *vpath" |
| 27 | syn match makeExport "^ *\(export\|unexport\)\>" |
| 28 | syn match makeOverride "^ *override" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 29 | hi link makeOverride makeStatement |
| 30 | hi link makeExport makeStatement |
| 31 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 32 | " catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend |
| 33 | 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] | 34 | |
| 35 | " Microsoft Makefile specials |
| 36 | syn case ignore |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 37 | syn match makeInclude "^! *include" |
| 38 | syn match makePreCondit "! *\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|elseif\|else if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 39 | syn case match |
| 40 | |
| 41 | " identifiers |
| 42 | syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString |
| 43 | syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString |
| 44 | syn match makeIdent "\$\$\w*" |
| 45 | syn match makeIdent "\$[^({]" |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 46 | syn match makeIdent "^ *\a\w*\s*[:+?!*]="me=e-2 |
| 47 | syn match makeIdent "^ *\a\w*\s*="me=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 48 | syn match makeIdent "%" |
| 49 | |
| 50 | " Makefile.in variables |
| 51 | syn match makeConfig "@[A-Za-z0-9_]\+@" |
| 52 | |
| 53 | " make targets |
| 54 | " syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 55 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 56 | syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | |
| 58 | 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 skipnl nextGroup=makeCommands |
| 59 | syn match makeTarget "^[A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget skipnl nextgroup=makeCommands,makeCommandError |
| 60 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 61 | 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 skipnl nextGroup=makeCommands |
| 62 | 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 skipnl nextgroup=makeCommands,makeCommandError |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 63 | |
| 64 | syn match makeCommandError "^\s\+\S.*" contained |
| 65 | 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 |
| 66 | syn match makeCmdNextLine "\\\n."he=e-1 contained |
| 67 | |
| 68 | |
| 69 | " Statements / Functions (GNU make) |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 70 | syn match makeStatement contained "(\(subst\|abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 71 | |
| 72 | " Comment |
| 73 | if exists("make_microsoft") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 74 | syn match makeComment "#.*" contains=@Spell,makeTodo |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 75 | elseif !exists("make_no_comments") |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 76 | syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo |
| 77 | syn match makeComment "#$" contains=@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 78 | endif |
| 79 | syn keyword makeTodo TODO FIXME XXX contained |
| 80 | |
| 81 | " match escaped quotes and any other escaped character |
| 82 | " except for $, as a backslash in front of a $ does |
| 83 | " not make it a standard character, but instead it will |
| 84 | " still act as the beginning of a variable |
| 85 | " The escaped char is not highlightet currently |
| 86 | syn match makeEscapedChar "\\[^$]" |
| 87 | |
| 88 | |
| 89 | syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent |
| 90 | syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent |
| 91 | syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine |
| 92 | |
| 93 | " Syncing |
| 94 | syn sync minlines=20 maxlines=200 |
| 95 | |
| 96 | " Sync on Make command block region: When searching backwards hits a line that |
| 97 | " can't be a command or a comment, use makeCommands if it looks like a target, |
| 98 | " NONE otherwise. |
| 99 | syn sync match makeCommandSync groupthere NONE "^[^\t#]" |
| 100 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]" |
| 101 | syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$" |
| 102 | |
| 103 | " Define the default highlighting. |
| 104 | " For version 5.7 and earlier: only when not done already |
| 105 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 106 | if version >= 508 || !exists("did_make_syn_inits") |
| 107 | if version < 508 |
| 108 | let did_make_syn_inits = 1 |
| 109 | command -nargs=+ HiLink hi link <args> |
| 110 | else |
| 111 | command -nargs=+ HiLink hi def link <args> |
| 112 | endif |
| 113 | |
| 114 | HiLink makeNextLine makeSpecial |
| 115 | HiLink makeCmdNextLine makeSpecial |
| 116 | HiLink makeSpecTarget Statement |
| 117 | if !exists("make_no_commands") |
| 118 | HiLink makeCommands Number |
| 119 | endif |
| 120 | HiLink makeImplicit Function |
| 121 | HiLink makeTarget Function |
| 122 | HiLink makeInclude Include |
| 123 | HiLink makePreCondit PreCondit |
| 124 | HiLink makeStatement Statement |
| 125 | HiLink makeIdent Identifier |
| 126 | HiLink makeSpecial Special |
| 127 | HiLink makeComment Comment |
| 128 | HiLink makeDString String |
| 129 | HiLink makeSString String |
| 130 | HiLink makeBString Function |
| 131 | HiLink makeError Error |
| 132 | HiLink makeTodo Todo |
| 133 | HiLink makeDefine Define |
| 134 | HiLink makeCommandError Error |
| 135 | HiLink makeConfig PreCondit |
| 136 | delcommand HiLink |
| 137 | endif |
| 138 | |
| 139 | let b:current_syntax = "make" |
| 140 | |
Bram Moolenaar | 0c5fa7d | 2012-10-05 22:26:30 +0200 | [diff] [blame] | 141 | let &cpo = s:cpo_save |
| 142 | unlet s:cpo_save |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | " vim: ts=8 |