Skip to content

Commit

Permalink
Support for command substitution for the Bash language
Browse files Browse the repository at this point in the history
Command substitution is a very important part of the Bash
language. Every non trivial script uses it in one way or another.
This patch adds support for it.
  • Loading branch information
zeitgeist87 committed Oct 6, 2015
1 parent e83dcff commit c628ce2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
14 changes: 14 additions & 0 deletions components/prism-bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
punctuation: /\(\(?|\)\)?|,|;/
}
},
// Command Substitution
{
pattern: /\$\([^)]+\)|`[^`]+`/,
inside: {
variable: /^\$\(|^`|\)$|`$/
}
},
/\$(?:[a-z0-9_#\?\*!@]+|\{[^}]+\})/i
],
};
Expand Down Expand Up @@ -61,4 +68,11 @@
'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/,
'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/
};

var inside = insideString.variable[1].inside;
inside['function'] = Prism.languages.bash['function'];
inside.keyword = Prism.languages.bash.keyword;
inside.boolean = Prism.languages.bash.boolean;
inside.operator = Prism.languages.bash.operator;
inside.punctuation = Prism.languages.bash.punctuation;
})(Prism);
2 changes: 1 addition & 1 deletion components/prism-bash.min.js

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

34 changes: 34 additions & 0 deletions tests/languages/bash/command_substitution_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$(echo foo)
`echo foo`
"$(echo foo) bar"

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

[
["variable", [
["variable", "$("],
["keyword", "echo"],
" foo",
["variable", ")"]
]],
["variable", [
["variable", "`"],
["keyword", "echo"],
" foo",
["variable", "`"]
]],
["string", [
"\"",
["variable", [
["variable", "$("],
["keyword", "echo"],
" foo",
["variable", ")"]
]],
" bar\""
]]
]

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

Checks for command substitution.

0 comments on commit c628ce2

Please sign in to comment.