Skip to content

Commit

Permalink
Makefile: Use standard token names correctly (#3227)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 7, 2021
1 parent b58cd72 commit 21a3c2d
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 112 deletions.
26 changes: 13 additions & 13 deletions components/prism-makefile.js
Expand Up @@ -8,27 +8,27 @@ Prism.languages.makefile = {
greedy: true
},

// Built-in target names
'builtin': /\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,
'builtin-target': {
pattern: /\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,
alias: 'builtin'
},

// Targets
'symbol': {
'target': {
pattern: /^(?:[^:=\s]|[ \t]+(?![\s:]))+(?=\s*:(?!=))/m,
alias: 'symbol',
inside: {
'variable': /\$+(?:(?!\$)[^(){}:#=\s]+|(?=[({]))/
}
},
'variable': /\$+(?:(?!\$)[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,

'keyword': [
// Directives
/-include\b|\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|include|override|private|sinclude|undefine|unexport|vpath)\b/,
// Functions
{
pattern: /(\()(?:abspath|addsuffix|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:list|s)?)(?=[ \t])/,
lookbehind: true
}
],
// Directives
'keyword': /-include\b|\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|include|override|private|sinclude|undefine|unexport|vpath)\b/,

'function': {
pattern: /(\()(?:abspath|addsuffix|and|basename|call|dir|error|eval|file|filter(?:-out)?|findstring|firstword|flavor|foreach|guile|if|info|join|lastword|load|notdir|or|origin|patsubst|realpath|shell|sort|strip|subst|suffix|value|warning|wildcard|word(?:list|s)?)(?=[ \t])/,
lookbehind: true
},
'operator': /(?:::|[?:+!])?=|[|@]/,
'punctuation': /[:;(){}]/
};
2 changes: 1 addition & 1 deletion components/prism-makefile.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/languages/makefile/builtin-target_feature.test
@@ -0,0 +1,15 @@
.PHONY:
.DELETE_ON_ERROR:
.SECONDEXPANSION:

----------------------------------------------------

[
["builtin-target", ".PHONY"], ["punctuation", ":"],
["builtin-target", ".DELETE_ON_ERROR"], ["punctuation", ":"],
["builtin-target", ".SECONDEXPANSION"], ["punctuation", ":"]
]

----------------------------------------------------

Checks for built-in target names.
15 changes: 0 additions & 15 deletions tests/languages/makefile/builtin_feature.test

This file was deleted.

226 changes: 226 additions & 0 deletions tests/languages/makefile/function_feature.test
@@ -0,0 +1,226 @@
(abspath foo)
(addsuffix foo)
(and foo)
(basename foo)
(call foo)
(dir foo)
(error foo)
(eval foo)
(file foo)
(filter foo)
(filter-out foo)
(findstring foo)
(firstword foo)
(flavor foo)
(foreach foo)
(guile foo)
(if foo)
(info foo)
(join foo)
(lastword foo)
(load foo)
(notdir foo)
(or foo)
(origin foo)
(patsubst foo)
(realpath foo)
(shell foo)
(sort foo)
(strip foo)
(subst foo)
(suffix foo)
(value foo)
(warning foo)
(wildcard foo)
(word foo)
(wordlist foo)
(words foo)

----------------------------------------------------

[
["punctuation", "("],
["function", "abspath"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "addsuffix"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "and"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "basename"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "call"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "dir"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "error"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "eval"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "file"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "filter"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "filter-out"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "findstring"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "firstword"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "flavor"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "foreach"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "guile"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "if"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "info"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "join"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "lastword"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "load"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "notdir"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "or"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "origin"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "patsubst"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "realpath"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "shell"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "sort"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "strip"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "subst"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "suffix"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "value"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "warning"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "wildcard"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "word"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "wordlist"],
" foo",
["punctuation", ")"],

["punctuation", "("],
["function", "words"],
" foo",
["punctuation", ")"]
]

0 comments on commit 21a3c2d

Please sign in to comment.