From bcac4f1cbd1995fd65124d443fa27cb97ba6015b Mon Sep 17 00:00:00 2001 From: Matubu Date: Tue, 10 Sep 2024 03:28:00 +0200 Subject: [PATCH] improvements to bash syntax. fix #43 --- examples/languages/test.bash | 5 ++++- src/languages/bash.js | 25 ++++++++++++++++--------- src/languages/js_template_literals.js | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/languages/test.bash b/examples/languages/test.bash index bbedad4..766a8d7 100644 --- a/examples/languages/test.bash +++ b/examples/languages/test.bash @@ -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 @@ -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 } diff --git a/src/languages/bash.js b/src/languages/bash.js index e1eea04..173bf90 100644 --- a/src/languages/bash.js +++ b/src/languages/bash.js @@ -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 ] diff --git a/src/languages/js_template_literals.js b/src/languages/js_template_literals.js index 646ef44..62675b4 100644 --- a/src/languages/js_template_literals.js +++ b/src/languages/js_template_literals.js @@ -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);