From 5b3e0e68bfaae282faff6697d6a490567fa9d44b Mon Sep 17 00:00:00 2001 From: Joel Porquet Date: Thu, 6 Apr 2017 16:24:21 -0700 Subject: [PATCH] makefile: improve support 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 --- src/languages/makefile.js | 101 ++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 32 deletions(-) diff --git a/src/languages/makefile.js b/src/languages/makefile.js index 76e8018a78..bf7b27e7f9 100644 --- a/src/languages/makefile.js +++ b/src/languages/makefile.js @@ -1,50 +1,87 @@ /* Language: Makefile Author: Ivan Sagalaev +Contributors: Joël Porquet 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: /\$[@%