-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for makefile syntax: - simple variables (eg `$(var)`) and special variables (eg `$@`) - variable inside strings (eg `"blabla $(var) blabla"`) - functions (eg `$(patsubst arg,arg,$(var))`) - variable assignement (eg `var=toto`, `var+=toto`, `var:=toto`) - targets (eg `all: dependency $(var)`) - language keywords (`define`, `endef`, `ifeq`, etc.) Signed-off-by: Joel Porquet <joel@porquet.org>
- Loading branch information
1 parent
d3219c5
commit 5b3e0e6
Showing
1 changed file
with
69 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
/* | ||
Language: Makefile | ||
Author: Ivan Sagalaev <maniac@softwaremaniacs.org> | ||
Contributors: Joël Porquet <joel@porquet.org> | ||
Category: common | ||
*/ | ||
|
||
function(hljs) { | ||
/* Variables: simple (eg $(var)) and special (eg $@) */ | ||
var VARIABLE = { | ||
className: 'variable', | ||
begin: /\$\(/, end: /\)/, | ||
contains: [hljs.BACKSLASH_ESCAPE] | ||
}; | ||
return { | ||
aliases: ['mk', 'mak'], | ||
contains: [ | ||
hljs.HASH_COMMENT_MODE, | ||
{ | ||
begin: /^\w+\s*\W*=/, returnBegin: true, | ||
relevance: 0, | ||
starts: { | ||
end: /\s*\W*=/, excludeEnd: true, | ||
starts: { | ||
end: /$/, | ||
relevance: 0, | ||
contains: [ | ||
VARIABLE | ||
] | ||
} | ||
} | ||
}, | ||
variants: [ | ||
{ | ||
className: 'section', | ||
begin: /^[\w]+:\s*$/ | ||
begin: '\\$\\(' + hljs.UNDERSCORE_IDENT_RE + '\\)', | ||
contains: [hljs.BACKSLASH_ESCAPE], | ||
}, | ||
{ | ||
className: 'meta', | ||
begin: /^\.PHONY:/, end: /$/, | ||
keywords: {'meta-keyword': '.PHONY'}, lexemes: /[\.\w]+/ | ||
begin: /\$[@%<?\^\+\*]/ | ||
}, | ||
] | ||
}; | ||
/* Quoted string with variables inside */ | ||
var QUOTE_STRING = { | ||
className: 'string', | ||
begin: /"/, end: /"/, | ||
contains: [ | ||
hljs.BACKSLASH_ESCAPE, | ||
VARIABLE, | ||
] | ||
}; | ||
/* Function: $(func arg,...) */ | ||
var FUNC = { | ||
className: 'variable', | ||
begin: /\$\([\w-]+\s/, end: /\)/, | ||
keywords: { | ||
built_in: | ||
'subst patsubst strip findstring filter filter-out sort ' + | ||
'word wordlist firstword lastword dir notdir suffix basename ' + | ||
'addsuffix addprefix join wildcard realpath abspath error warning ' + | ||
'shell origin flavor foreach if or and call eval file value', | ||
}, | ||
contains: [ | ||
VARIABLE, | ||
] | ||
}; | ||
/* Variable assignment */ | ||
var VAR_ASSIG = { | ||
begin: '^' + hljs.UNDERSCORE_IDENT_RE + '\\s*[:+?]?=', | ||
illegal: '\\n', | ||
returnBegin: true, | ||
contains: [ | ||
{ | ||
begin: /^\t+/, end: /$/, | ||
relevance: 0, | ||
contains: [ | ||
hljs.QUOTE_STRING_MODE, | ||
VARIABLE | ||
] | ||
begin: '^' + hljs.UNDERSCORE_IDENT_RE, end: '[:+?]?=', | ||
excludeEnd: true, | ||
} | ||
] | ||
}; | ||
/* Meta targets (.PHONY) */ | ||
var META = { | ||
className: 'meta', | ||
begin: /^\.PHONY:/, end: /$/, | ||
keywords: {'meta-keyword': '.PHONY'}, | ||
lexemes: /[\.\w]+/ | ||
}; | ||
/* Targets */ | ||
var TARGET = { | ||
className: 'section', | ||
begin: /^[^\s]+:/, end: /$/, | ||
contains: [VARIABLE,] | ||
}; | ||
return { | ||
aliases: ['mk', 'mak'], | ||
keywords: | ||
'define endef undefine ifdef ifndef ifeq ifneq else endif ' + | ||
'include -include sinclude override export unexport private vpath', | ||
lexemes: /[\w-]+/, | ||
contains: [ | ||
hljs.HASH_COMMENT_MODE, | ||
VARIABLE, | ||
QUOTE_STRING, | ||
FUNC, | ||
VAR_ASSIG, | ||
META, | ||
TARGET, | ||
] | ||
}; | ||
} |