Skip to content

Commit

Permalink
improvements to bash syntax. fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
matubu committed Sep 10, 2024
1 parent d7ecad8 commit bcac4f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion examples/languages/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install speed_highlight_js

TEST=5

NAME="John"
HELLO_WORLD="John"
echo "Hi $NAME" #=> Hi John
cat 'Hi $NAME'#=> TODO Hi $NAME

Expand All @@ -29,4 +29,7 @@ minify_file () {
test=false
out=${ file/${in_dir}/${out_dir} }
exec_minify_cmd $file $out
test-hello &
./a.out test-hello
cat /etc/test
}
25 changes: 16 additions & 9 deletions src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,39 @@ export default [
match: /(["'])((?!\1)[^\r\n\\]|\\[^])*\1?/g,
sub: [ variable ]
},
{
// relative or absolute path
type: "oper",
match: /(?<=\s|^)\.*\/[a-z/_.-]+/gi,
},
{
type: 'kwd',
match: /-[a-zA-Z]+|$<|[&|;]+|\b(unset|readonly|shift|export|if|fi|else|elif|while|do|done|for|until|case|esac|break|continue|exit|return|trap|wait|eval|exec|then|declare|enable|local|select|typeset|time|add|remove|install|update|delete)\b/g
match: /\s-[a-zA-Z]+|$<|[&|;]+|\b(unset|readonly|shift|export|if|fi|else|elif|while|do|done|for|until|case|esac|break|continue|exit|return|trap|wait|eval|exec|then|declare|enable|local|select|typeset|time|add|remove|install|update|delete)(?=\s|$)/g
},
{
expand: 'num'
},
{
// command
type: 'func',
match: /\b(set|alias|bg|bind|builtin|caller|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|set|shift|shopt|source|suspend|test|times|trap|type|ulimit|umask|unalias|unset)\b/g
match: /(?<=(^|\||\&\&|\;)\s*)[a-z_.-]+(?=\s|$)/gmi
},
{
type: 'bool',
match: /\b(true|false)\b/g
},
{
type: 'func',
match: /[a-z_]+(?=\s*\()/g
match: /(?<=\s|^)(true|false)(?=\s|$)/g
},
// {
// // function definition
// type: 'func',
// match: /(?<=\s|^)[a-z_]+(?=\s*\()/g
// },
{
type: 'oper',
match: /[=(){}<>+*/!?~^-]+/g
match: /[=(){}<>!]+/g
},
{
type: 'var',
match: /\w+(?=\s*=)/g
match: /(?<=\s|^)[\w_]+(?=\s*=)/g
},
variable
]
2 changes: 1 addition & 1 deletion src/languages/js_template_literals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default [
if (str[i] == '{') f();
else if (str[i] == '}') return;
};
for (; i < str.length; i++)
for (; i < str.length; ++i)
if (str[i - 1] != '\\' && str[i] == '$' && str[i + 1] == '{') {
j = i++;
f(i);
Expand Down

0 comments on commit bcac4f1

Please sign in to comment.