From 21a3c2d75555d16a4107722e6aec016ce44a461f Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Tue, 7 Dec 2021 12:48:48 +0100 Subject: [PATCH] Makefile: Use standard token names correctly (#3227) --- components/prism-makefile.js | 26 +- components/prism-makefile.min.js | 2 +- .../makefile/builtin-target_feature.test | 15 ++ tests/languages/makefile/builtin_feature.test | 15 -- .../languages/makefile/function_feature.test | 226 ++++++++++++++++++ tests/languages/makefile/keyword_feature.test | 100 +++----- tests/languages/makefile/symbol_feature.test | 18 -- tests/languages/makefile/target_feature.test | 23 ++ 8 files changed, 313 insertions(+), 112 deletions(-) create mode 100644 tests/languages/makefile/builtin-target_feature.test delete mode 100644 tests/languages/makefile/builtin_feature.test create mode 100644 tests/languages/makefile/function_feature.test delete mode 100644 tests/languages/makefile/symbol_feature.test create mode 100644 tests/languages/makefile/target_feature.test diff --git a/components/prism-makefile.js b/components/prism-makefile.js index 1decd0d1a4..64a1dee6ee 100644 --- a/components/prism-makefile.js +++ b/components/prism-makefile.js @@ -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': /[:;(){}]/ }; diff --git a/components/prism-makefile.min.js b/components/prism-makefile.min.js index 2f98141450..43f317782f 100644 --- a/components/prism-makefile.min.js +++ b/components/prism-makefile.min.js @@ -1 +1 @@ -Prism.languages.makefile={comment:{pattern:/(^|[^\\])#(?:\\(?:\r\n|[\s\S])|[^\\\r\n])*/,lookbehind:!0},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},builtin:/\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,symbol:{pattern:/^(?:[^:=\s]|[ \t]+(?![\s:]))+(?=\s*:(?!=))/m,inside:{variable:/\$+(?:(?!\$)[^(){}:#=\s]+|(?=[({]))/}},variable:/\$+(?:(?!\$)[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,keyword:[/-include\b|\b(?:define|else|endef|endif|export|ifn?def|ifn?eq|include|override|private|sinclude|undefine|unexport|vpath)\b/,{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:!0}],operator:/(?:::|[?:+!])?=|[|@]/,punctuation:/[:;(){}]/}; \ No newline at end of file +Prism.languages.makefile={comment:{pattern:/(^|[^\\])#(?:\\(?:\r\n|[\s\S])|[^\\\r\n])*/,lookbehind:!0},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"builtin-target":{pattern:/\.[A-Z][^:#=\s]+(?=\s*:(?!=))/,alias:"builtin"},target:{pattern:/^(?:[^:=\s]|[ \t]+(?![\s:]))+(?=\s*:(?!=))/m,alias:"symbol",inside:{variable:/\$+(?:(?!\$)[^(){}:#=\s]+|(?=[({]))/}},variable:/\$+(?:(?!\$)[^(){}:#=\s]+|\([@*%<^+?][DF]\)|(?=[({]))/,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:!0},operator:/(?:::|[?:+!])?=|[|@]/,punctuation:/[:;(){}]/}; \ No newline at end of file diff --git a/tests/languages/makefile/builtin-target_feature.test b/tests/languages/makefile/builtin-target_feature.test new file mode 100644 index 0000000000..d1eeffe5d6 --- /dev/null +++ b/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. diff --git a/tests/languages/makefile/builtin_feature.test b/tests/languages/makefile/builtin_feature.test deleted file mode 100644 index 6f6a1a30e4..0000000000 --- a/tests/languages/makefile/builtin_feature.test +++ /dev/null @@ -1,15 +0,0 @@ -.PHONY: -.DELETE_ON_ERROR: -.SECONDEXPANSION: - ----------------------------------------------------- - -[ - ["builtin", ".PHONY"], ["punctuation", ":"], - ["builtin", ".DELETE_ON_ERROR"], ["punctuation", ":"], - ["builtin", ".SECONDEXPANSION"], ["punctuation", ":"] -] - ----------------------------------------------------- - -Checks for built-in target names. \ No newline at end of file diff --git a/tests/languages/makefile/function_feature.test b/tests/languages/makefile/function_feature.test new file mode 100644 index 0000000000..f45fd8134d --- /dev/null +++ b/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", ")"] +] diff --git a/tests/languages/makefile/keyword_feature.test b/tests/languages/makefile/keyword_feature.test index dcbbcc895a..06bf2dc109 100644 --- a/tests/languages/makefile/keyword_feature.test +++ b/tests/languages/makefile/keyword_feature.test @@ -1,73 +1,43 @@ -define else endef endif -export ifdef ifndef ifeq -ifneq -include include -override private sinclude -undefine unexport vpath - -(addsuffix foo) (abspath 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) (words foo) (wordlist foo) +-include +define +else +endef +endif +export +ifdef +ifeq +ifndef +ifneq +include +override +private +sinclude +undefine +unexport +vpath ---------------------------------------------------- [ - ["keyword", "define"], ["keyword", "else"], ["keyword", "endef"], ["keyword", "endif"], - ["keyword", "export"], ["keyword", "ifdef"], ["keyword", "ifndef"], ["keyword", "ifeq"], - ["keyword", "ifneq"], ["keyword", "-include"], ["keyword", "include"], - ["keyword", "override"], ["keyword", "private"], ["keyword", "sinclude"], - ["keyword", "undefine"], ["keyword", "unexport"], ["keyword", "vpath"], - - ["punctuation", "("], ["keyword", "addsuffix"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "abspath"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "and"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "basename"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "call"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "dir"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "error"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "eval"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "file"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "filter"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "filter-out"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "findstring"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "firstword"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "flavor"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "foreach"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "guile"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "if"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "info"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "join"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "lastword"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "load"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "notdir"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "or"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "origin"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "patsubst"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "realpath"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "shell"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "sort"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "strip"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "subst"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "suffix"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "value"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "warning"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "wildcard"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "word"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "words"], " foo", ["punctuation", ")"], - ["punctuation", "("], ["keyword", "wordlist"], " foo", ["punctuation", ")"] + ["keyword", "-include"], + ["keyword", "define"], + ["keyword", "else"], + ["keyword", "endef"], + ["keyword", "endif"], + ["keyword", "export"], + ["keyword", "ifdef"], + ["keyword", "ifeq"], + ["keyword", "ifndef"], + ["keyword", "ifneq"], + ["keyword", "include"], + ["keyword", "override"], + ["keyword", "private"], + ["keyword", "sinclude"], + ["keyword", "undefine"], + ["keyword", "unexport"], + ["keyword", "vpath"] ] ---------------------------------------------------- -Checks for keywords and functions. \ No newline at end of file +Checks for keywords. diff --git a/tests/languages/makefile/symbol_feature.test b/tests/languages/makefile/symbol_feature.test deleted file mode 100644 index fdc454f177..0000000000 --- a/tests/languages/makefile/symbol_feature.test +++ /dev/null @@ -1,18 +0,0 @@ -edit : -%oo: -$(foo): - ----------------------------------------------------- - -[ - ["symbol", ["edit"]], ["punctuation", ":"], - ["symbol", ["%oo"]], ["punctuation", ":"], - ["symbol", [ - ["variable", "$"], - "(foo)" - ]], ["punctuation", ":"] -] - ----------------------------------------------------- - -Checks for targets, optionally containing interpolation. \ No newline at end of file diff --git a/tests/languages/makefile/target_feature.test b/tests/languages/makefile/target_feature.test new file mode 100644 index 0000000000..bfbdfe99ca --- /dev/null +++ b/tests/languages/makefile/target_feature.test @@ -0,0 +1,23 @@ +edit : +%oo: +$(foo): + +---------------------------------------------------- + +[ + ["target", ["edit"]], + ["punctuation", ":"], + + ["target", ["%oo"]], + ["punctuation", ":"], + + ["target", [ + ["variable", "$"], + "(foo)" + ]], + ["punctuation", ":"] +] + +---------------------------------------------------- + +Checks for targets, optionally containing interpolation.