Skip to content

Commit

Permalink
Correctly highlight built-in Bash variables surrounded by ${...}.
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitalquark committed Sep 21, 2023
1 parent 5802bd4 commit 0730c5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lexers/bash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
}
Expand Down

0 comments on commit 0730c5e

Please sign in to comment.