diff --git a/src/shell/shell.test.ts b/src/shell/shell.test.ts index c34e3b9e..dee55735 100644 --- a/src/shell/shell.test.ts +++ b/src/shell/shell.test.ts @@ -279,4 +279,13 @@ testTokenization('shell', [ { startIndex: 4, type: 'string.heredoc.shell' } ] }], + + [{ + line: 'echo $( echo "hi" )', + tokens: [ + { startIndex: 0, type: 'type.identifier.shell' }, + { startIndex: 4, type: 'white.shell' }, + { startIndex: 5, type: 'variable.shell' } + ] + }], ]) diff --git a/src/shell/shell.ts b/src/shell/shell.ts index 03c6197f..7acfd4f1 100644 --- a/src/shell/shell.ts +++ b/src/shell/shell.ts @@ -201,13 +201,30 @@ export const language = { [/\$\d+/, 'variable.predefined'], [/\$\w+/, 'variable'], [/\$[*@#?\-$!0_]/, 'variable'], - [/\$['"{(]/, 'variable', '@parameterBody'] + [/\$'/, 'variable', '@parameterBodyQuote'], + [/\$"/, 'variable', '@parameterBodyDoubleQuote'], + [/\$\(/, 'variable', '@parameterBodyParen'], + [/\$\{/, 'variable', '@parameterBodyCurlyBrace'], ], - - parameterBody: [ + parameterBodyQuote: [ + [/[^#:%*@\-!_']+/, 'variable'], [/[#:%*@\-!_]/, 'delimiter'], - [/['"{(]/, 'variable', '@pop'], - [/./, 'variable'] + [/[']/, 'variable', '@pop'], + ], + parameterBodyDoubleQuote: [ + [/[^#:%*@\-!_"]+/, 'variable'], + [/[#:%*@\-!_]/, 'delimiter'], + [/["]/, 'variable', '@pop'], + ], + parameterBodyParen: [ + [/[^#:%*@\-!_)]+/, 'variable'], + [/[#:%*@\-!_]/, 'delimiter'], + [/[)]/, 'variable', '@pop'], + ], + parameterBodyCurlyBrace: [ + [/[^#:%*@\-!_}]+/, 'variable'], + [/[#:%*@\-!_]/, 'delimiter'], + [/[}]/, 'variable', '@pop'], ], } };