From 0730c5ebd9261dfc4273b4501acfbab730999322 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Thu, 21 Sep 2023 14:41:30 -0400 Subject: [PATCH] Correctly highlight built-in Bash variables surrounded by ${...}. --- lexers/bash.lua | 4 ++-- tests.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lexers/bash.lua b/lexers/bash.lua index 5c03000..c76a006 100644 --- a/lexers/bash.lua +++ b/lexers/bash.lua @@ -43,8 +43,8 @@ lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number)) -- Variables. -local builtin_var = lex:tag(lexer.OPERATOR, '$') * lex:tag(lexer.VARIABLE_BUILTIN, lex:word_match( - lexer.VARIABLE_BUILTIN) + S('!#?*@$-') + lexer.digit^1) +local builtin_var = lex:tag(lexer.OPERATOR, '$' * P('{')^-1) * lex:tag(lexer.VARIABLE_BUILTIN, + lex:word_match(lexer.VARIABLE_BUILTIN) + S('!#?*@$-') * -lexer.alnum + lexer.digit^1) local var_ref = lex:tag(lexer.OPERATOR, '$' * ('{' * S('!#')^-1)^-1) * lex:tag(lexer.VARIABLE, lexer.word) local patt_expansion = lex:tag(lexer.DEFAULT, '/#' + '#' * P('#')^-1) diff --git a/tests.lua b/tests.lua index 2e937a6..a66a18e 100644 --- a/tests.lua +++ b/tests.lua @@ -1156,7 +1156,7 @@ function test_bash() if [ ! -z "foo" -a 0 -ne 1 ]; then quux=$((1 - 2 / 0x3)) elif [[ -d /foo/bar-baz.quux ]]; then - foo=$? + foo=${?} fi s=<<-"END" foobar @@ -1193,7 +1193,7 @@ function test_bash() DEFAULT, '/', -- IDENTIFIER, 'bar', DEFAULT, '-baz', DEFAULT, '.', IDENTIFIER, 'quux', -- OPERATOR, ']', OPERATOR, ']', OPERATOR, ';', KEYWORD, 'then', -- - VARIABLE, 'foo', OPERATOR, '=', OPERATOR, '$', VARIABLE_BUILTIN, '?', -- + VARIABLE, 'foo', OPERATOR, '=', OPERATOR, '${', VARIABLE_BUILTIN, '?', OPERATOR, '}', -- KEYWORD, 'fi', -- VARIABLE, 's', OPERATOR, '=', STRING, '<<-"END"\n foobar\n END' }