xref: /vim-8.2.3635/runtime/syntax/make.vim (revision 6938e27a)
1" Vim syntax file
2" Language:	Makefile
3" Maintainer:	Roland Hieber <[email protected]>, <https://github.com/rohieb>
4" Previous Maintainer:	Claudio Fleiner <[email protected]>
5" URL:		https://github.com/vim/vim/blob/master/runtime/syntax/make.vim
6" Last Change:	2020 May 03
7
8" quit when a syntax file was already loaded
9if exists("b:current_syntax")
10  finish
11endif
12
13let s:cpo_save = &cpo
14set cpo&vim
15
16" some special characters
17syn match makeSpecial	"^\s*[@+-]\+"
18syn match makeNextLine	"\\\n\s*"
19
20" catch unmatched define/endef keywords.  endef only matches it is by itself on a line, possibly followed by a commend
21syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$"
22	\ contains=makeStatement,makeIdent,makePreCondit,makeDefine
23
24" Microsoft Makefile specials
25syn case ignore
26syn match makeInclude	"^!\s*include\s.*$"
27syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s*if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
28syn case match
29
30" identifiers
31syn region makeIdent	start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
32syn region makeIdent	start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
33syn match makeIdent	"\$\$\w*"
34syn match makeIdent	"\$[^({]"
35syn match makeIdent	"^ *[^:#= \t]*\s*[:+?!*]="me=e-2
36syn match makeIdent	"^ *[^:#= \t]*\s*::="me=e-3
37syn match makeIdent	"^ *[^:#= \t]*\s*="me=e-1
38syn match makeIdent	"%"
39
40" Makefile.in variables
41syn match makeConfig "@[A-Za-z0-9_]\+@"
42
43" make targets
44syn match makeImplicit		"^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1
45syn match makeImplicit		"^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2
46
47syn 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
55
56syn 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
63
64syn match makeCommandError "^\s\+\S.*" contained
65syn 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
69syn match makeCmdNextLine	"\\\n."he=e-1 contained
70
71" 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\)\>"
76syn match makeOverride	"^ *override\>"
77" Statements / Functions (GNU make)
78syn 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
79
80" Comment
81if exists("make_microsoft")
82   syn match  makeComment "#.*" contains=@Spell,makeTodo
83elseif !exists("make_no_comments")
84   syn region  makeComment	start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
85   syn match   makeComment	"#$" contains=@Spell
86endif
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
97syn region  makeDString start=+\(\\\)\@<!"+  skip=+\\.+  end=+"+  contained contains=makeIdent
98syn region  makeSString start=+\(\\\)\@<!'+  skip=+\\.+  end=+'+  contained contains=makeIdent
99syn 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.
112" Only when an item doesn't have highlighting yet
113
114hi def link makeNextLine	makeSpecial
115hi def link makeCmdNextLine	makeSpecial
116hi link     makeOverride        makeStatement
117hi link     makeExport          makeStatement
118
119hi def link makeSpecTarget	Statement
120if !exists("make_no_commands")
121hi def link makeCommands	Number
122endif
123hi def link makeImplicit	Function
124hi def link makeTarget		Function
125hi def link makeInclude		Include
126hi def link makePreCondit	PreCondit
127hi def link makeStatement	Statement
128hi 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
139
140let b:current_syntax = "make"
141
142let &cpo = s:cpo_save
143unlet s:cpo_save
144" vim: ts=8
145