Skip to content

Commit

Permalink
fix: shellscript escape, fix shikijs/shiki#591
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 23, 2024
1 parent 7d3b513 commit abaa1fe
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/tm-grammars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ import { grammars } from 'tm-grammars'
| `scheme` | | [sjhuangx/vscode-scheme](https://github.com/sjhuangx/vscode-scheme/blob/4e21683666e1e2edfa21d040ecd427f628e7b5ff/syntaxes/scheme.tmLanguage) | [MIT](https://raw.githubusercontent.com/sjhuangx/vscode-scheme/master/LICENSE.md) | | 8.35 kB |
| `scss` | | [microsoft/vscode](https://github.com/microsoft/vscode/blob/cf8d61ebd2f022f4ce8280171f0360d1fe0a206d/extensions/scss/syntaxes/scss.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | `css` | 26.21 kB |
| `shaderlab` | `shader` | [microsoft/vscode](https://github.com/microsoft/vscode/blob/8fdf170a0850c1cc027382f31650aaf300d3ae2a/extensions/shaderlab/syntaxes/shaderlab.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | `hlsl` | 5.83 kB |
| `shellscript` | `bash` `sh` `shell` `zsh` | [microsoft/vscode](https://github.com/microsoft/vscode/blob/a16d8d0a3e2062678c599134e78f8aa7b124363b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | | 32.83 kB |
| `shellscript` | `bash` `sh` `shell` `zsh` | [microsoft/vscode](https://github.com/microsoft/vscode/blob/a16d8d0a3e2062678c599134e78f8aa7b124363b/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | | 32.86 kB |
| `shellsession` | `console` | [hronro/sublime-linguist-syntax](https://github.com/hronro/sublime-linguist-syntax/blob/9c84f1d69dbe89bc23292f129cf2d408a9c7afe1/syntaxes/ShellSession.tmLanguage) | [MIT](https://raw.githubusercontent.com/hronro/sublime-linguist-syntax/master/LICENSE) | `shellscript` | 567.00 B |
| `smalltalk` | | [leocamello/vscode-smalltalk](https://github.com/leocamello/vscode-smalltalk/blob/bc888519a21740b4dbd4edcf2f884c61855dc58b/syntaxes/smalltalk.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/leocamello/vscode-smalltalk/master/LICENSE) | | 3.91 kB |
| `solidity` | | [juanfranblanco/vscode-solidity](https://github.com/juanfranblanco/vscode-solidity/blob/75531be0beda99b7293d778eb0b1c63f70d8ac59/syntaxes/solidity.json) | [MIT](https://raw.githubusercontent.com/juanfranblanco/vscode-solidity/master/License.txt) | | 15.15 kB |
Expand Down
6 changes: 3 additions & 3 deletions packages/tm-grammars/grammars/shellscript.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
]
}
},
"match": "[ \\t]*+([^\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>))"
"match": "[ \\t]*+([^ \\t\\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>))"
},
{
"include": "#normal_statement_context"
Expand Down Expand Up @@ -1755,7 +1755,7 @@
]
}
},
"match": "(?!(?:!|&|\\||\\(|\\)|\\{|\\[|<|>|#|\\n|$|;|[ \\t]))(?:[ \\t]*+([^\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>)))?(?:(?:\\$\")|\")",
"match": "(?!(?:!|&|\\||\\(|\\)|\\{|\\[|<|>|#|\\n|$|;|[ \\t]))(?:[ \\t]*+([^ \\t\\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>)))?(?:(?:\\$\")|\")",
"name": "meta.statement.command.name.quoted.shell string.quoted.double.shell punctuation.definition.string.begin.shell entity.name.function.call.shell entity.name.command.shell"
},
"start_of_single_quoted_command_name": {
Expand Down Expand Up @@ -1784,7 +1784,7 @@
]
}
},
"match": "(?!(?:!|&|\\||\\(|\\)|\\{|\\[|<|>|#|\\n|$|;|[ \\t]))(?:[ \\t]*+([^\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>)))?(?:(?:\\$')|')",
"match": "(?!(?:!|&|\\||\\(|\\)|\\{|\\[|<|>|#|\\n|$|;|[ \\t]))(?:[ \\t]*+([^ \\t\\n'&;<>\\(\\)\\$`\\\\\"\\|]+(?!>)))?(?:(?:\\$')|')",
"name": "meta.statement.command.name.quoted.shell string.quoted.single.shell punctuation.definition.string.begin.shell entity.name.function.call.shell entity.name.command.shell"
},
"string": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tm-grammars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ export const grammars = [
'shell',
'zsh',
],
byteSize: 33623,
byteSize: 33650,
categories: [
'scripting',
],
Expand Down
11 changes: 9 additions & 2 deletions scripts/grammars/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,19 @@ export function cleanupGrammar(lang: any) {
// (_, key, value) => console.log('lang key removal', key, '|', value),
)

const reGrammarComment = /\s#.*$/
function cleanupMatch(match: string) {
const lines = match.split(/\n/g)
// https://github.com/shikijs/shiki/issues/591#issuecomment-1961637557
// It seems the `shellscript` grammars has a selector that missing the backslash escape, we patched them here
if (lang.name === 'shellscript')
match = match.replace(/\[\^ \t\n/g, '[^ \\t\\n')

const lines = match
.split(/\n/g)
if (lines.length === 1)
return match
return lines
.map(i => i.replace(/\s#.*$/, '').trim())
.map(i => i.replace(reGrammarComment, '').trim())
.join('\n')
}
function cleanupPattern(a: any) {
Expand Down

0 comments on commit abaa1fe

Please sign in to comment.