From 01cfc62ead7006c228e5c91408f6705e2fc40b51 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 12 Apr 2022 16:49:52 +0200 Subject: [PATCH] Update shellscript grammar and add new test --- extensions/shellscript/cgmanifest.json | 4 +- .../syntaxes/shell-unix-bash.tmLanguage.json | 66 +++++++++- .../test/colorize-fixtures/test.sh | 5 + .../test/colorize-results/test_sh.json | 120 ++++++++++++++++++ 4 files changed, 190 insertions(+), 5 deletions(-) diff --git a/extensions/shellscript/cgmanifest.json b/extensions/shellscript/cgmanifest.json index fcf7f676fa7..6f0ae3a254e 100644 --- a/extensions/shellscript/cgmanifest.json +++ b/extensions/shellscript/cgmanifest.json @@ -6,12 +6,12 @@ "git": { "name": "atom/language-shellscript", "repositoryUrl": "https://github.com/atom/language-shellscript", - "commitHash": "4c3711edbe8eac6f501976893976b1ac6a043d50" + "commitHash": "4f8d7bb5cc4d1643674551683df10fe552dd5a6f" } }, "license": "MIT", "description": "The file syntaxes/shell-unix-bash.tmLanguage.json was derived from the Atom package https://github.com/atom/language-shellscript which was originally converted from the TextMate bundle https://github.com/textmate/shellscript.tmbundle.", - "version": "0.26.0" + "version": "0.28.2" } ], "version": 1 diff --git a/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json index 0089e5aa5c4..bfbb5f135d0 100644 --- a/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json +++ b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json @@ -4,7 +4,7 @@ "If you want to provide a fix or improvement, please create a pull request against the original repository.", "Once accepted there, we are happy to receive an update request." ], - "version": "https://github.com/atom/language-shellscript/commit/4c3711edbe8eac6f501976893976b1ac6a043d50", + "version": "https://github.com/atom/language-shellscript/commit/4f8d7bb5cc4d1643674551683df10fe552dd5a6f", "name": "Shell Script", "scopeName": "source.shell", "patterns": [ @@ -624,7 +624,7 @@ ] }, { - "begin": "(<<)-\\s*(\"|'|)\\s*\\\\?([^;&<\\s]+)\\2", + "begin": "(<<)-\\s*(\"|')\\s*\\\\?([^;&<\\s]+)\\2", "beginCaptures": { "1": { "name": "keyword.operator.heredoc.shell" @@ -642,7 +642,7 @@ "name": "string.unquoted.heredoc.no-indent.shell" }, { - "begin": "(<<)\\s*(\"|'|)\\s*\\\\?([^;&<\\s]+)\\2", + "begin": "(<<)\\s*(\"|')\\s*\\\\?([^;&<\\s]+)\\2", "beginCaptures": { "1": { "name": "keyword.operator.heredoc.shell" @@ -658,6 +658,66 @@ } }, "name": "string.unquoted.heredoc.shell" + }, + { + "begin": "(<<)-\\s*\\\\?([^;&<\\s]+)", + "beginCaptures": { + "1": { + "name": "keyword.operator.heredoc.shell" + }, + "2": { + "name": "keyword.control.heredoc-token.shell" + } + }, + "end": "^\\t*(\\2)(?=\\s|;|&|$)", + "endCaptures": { + "1": { + "name": "keyword.control.heredoc-token.shell" + } + }, + "name": "string.unquoted.heredoc.expanded.no-indent.shell", + "patterns": [ + { + "match": "\\\\[\\$`\\\\\\n]", + "name": "constant.character.escape.shell" + }, + { + "include": "#variable" + }, + { + "include": "#interpolation" + } + ] + }, + { + "begin": "(<<)\\s*\\\\?([^;&<\\s]+)", + "beginCaptures": { + "1": { + "name": "keyword.operator.heredoc.shell" + }, + "2": { + "name": "keyword.control.heredoc-token.shell" + } + }, + "end": "^(\\2)(?=\\s|;|&|$)", + "endCaptures": { + "1": { + "name": "keyword.control.heredoc-token.shell" + } + }, + "name": "string.unquoted.heredoc.expanded.shell", + "patterns": [ + { + "match": "\\\\[\\$`\\\\\\n]", + "name": "constant.character.escape.shell" + }, + { + "include": "#variable" + }, + { + "include": "#interpolation" + } + ] } ] }, diff --git a/extensions/vscode-colorize-tests/test/colorize-fixtures/test.sh b/extensions/vscode-colorize-tests/test/colorize-fixtures/test.sh index 4c5bf8f7eab..50751c1e4a7 100644 --- a/extensions/vscode-colorize-tests/test/colorize-fixtures/test.sh +++ b/extensions/vscode-colorize-tests/test/colorize-fixtures/test.sh @@ -10,6 +10,11 @@ fi DEVELOPER=$(xcode-select -print-path) LIPO=$(xcrun -sdk iphoneos -find lipo) +cat <<-EOF > /path/file + # A heredoc with a variable $DEVELOPER + some more file +EOF + function code() { cd $ROOT diff --git a/extensions/vscode-colorize-tests/test/colorize-results/test_sh.json b/extensions/vscode-colorize-tests/test/colorize-results/test_sh.json index a755f73ee61..9fd6ba74f7e 100644 --- a/extensions/vscode-colorize-tests/test/colorize-results/test_sh.json +++ b/extensions/vscode-colorize-tests/test/colorize-results/test_sh.json @@ -1223,6 +1223,126 @@ "hc_light": "string: #A31515" } }, + { + "c": "cat ", + "t": "source.shell", + "r": { + "dark_plus": "default: #D4D4D4", + "light_plus": "default: #000000", + "dark_vs": "default: #D4D4D4", + "light_vs": "default: #000000", + "hc_black": "default: #FFFFFF", + "hc_light": "default: #292929" + } + }, + { + "c": "<<", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell keyword.operator.heredoc.shell", + "r": { + "dark_plus": "keyword.operator: #D4D4D4", + "light_plus": "keyword.operator: #000000", + "dark_vs": "keyword.operator: #D4D4D4", + "light_vs": "keyword.operator: #000000", + "hc_black": "keyword.operator: #D4D4D4", + "hc_light": "keyword.operator: #000000" + } + }, + { + "c": "-", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell", + "r": { + "dark_plus": "string: #CE9178", + "light_plus": "string: #A31515", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "string: #CE9178", + "hc_light": "string: #A31515" + } + }, + { + "c": "EOF", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell keyword.control.heredoc-token.shell", + "r": { + "dark_plus": "keyword.control: #C586C0", + "light_plus": "keyword.control: #AF00DB", + "dark_vs": "keyword.control: #569CD6", + "light_vs": "keyword.control: #0000FF", + "hc_black": "keyword.control: #C586C0", + "hc_light": "keyword.control: #AF00DB" + } + }, + { + "c": " > /path/file", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell", + "r": { + "dark_plus": "string: #CE9178", + "light_plus": "string: #A31515", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "string: #CE9178", + "hc_light": "string: #A31515" + } + }, + { + "c": "\t# A heredoc with a variable ", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell", + "r": { + "dark_plus": "string: #CE9178", + "light_plus": "string: #A31515", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "string: #CE9178", + "hc_light": "string: #A31515" + } + }, + { + "c": "$", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell variable.other.normal.shell punctuation.definition.variable.shell", + "r": { + "dark_plus": "variable: #9CDCFE", + "light_plus": "variable: #001080", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "variable: #9CDCFE", + "hc_light": "variable: #001080" + } + }, + { + "c": "DEVELOPER", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell variable.other.normal.shell", + "r": { + "dark_plus": "variable: #9CDCFE", + "light_plus": "variable: #001080", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "variable: #9CDCFE", + "hc_light": "variable: #001080" + } + }, + { + "c": "\tsome more file", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell", + "r": { + "dark_plus": "string: #CE9178", + "light_plus": "string: #A31515", + "dark_vs": "string: #CE9178", + "light_vs": "string: #A31515", + "hc_black": "string: #CE9178", + "hc_light": "string: #A31515" + } + }, + { + "c": "EOF", + "t": "source.shell string.unquoted.heredoc.expanded.no-indent.shell keyword.control.heredoc-token.shell", + "r": { + "dark_plus": "keyword.control: #C586C0", + "light_plus": "keyword.control: #AF00DB", + "dark_vs": "keyword.control: #569CD6", + "light_vs": "keyword.control: #0000FF", + "hc_black": "keyword.control: #C586C0", + "hc_light": "keyword.control: #AF00DB" + } + }, { "c": "function", "t": "source.shell meta.function.shell storage.type.function.shell",