From e1eca65135ccddc7183b5674c8aa549b6f4267c5 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Fri, 6 Nov 2020 10:58:35 +0800 Subject: [PATCH] syntax (glob bracket expression): fix a bug of unsupported POSIX brackets --- lib/core-syntax.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index 9de2f059..dd273ec4 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -1620,8 +1620,14 @@ function ble/syntax:bash/check-glob { ((_ble_syntax_attr[i++]=${force_attr:-CTX_BRAX})) elif [[ ${text:i:1} == '[' ]]; then # Note: 条件コマンド [[ に変換する為に [[ の連なりは一度に読み取る。 - ((_ble_syntax_attr[i++]=${force_attr:-CTX_BRAX})) - [[ ${text:i:1} == '!'* ]] && ((i++)) + if [[ ${text:i+1:1} == [:=.] ]]; then + # Note: glob bracket expression が POSIX 括弧で始まっている時は + # [[ が一まとまりになっていると困るので除外。 + ble/syntax/parse/set-lookahead 2 + else + ((_ble_syntax_attr[i++]=${force_attr:-CTX_BRAX})) + [[ ${text:i:1} == '!'* ]] && ((i++)) + fi fi return 0 @@ -1894,7 +1900,7 @@ function ble/syntax:bash/ctx-bracket-expression { # is-delimiters の時に [... は其処で不完全終端する。 local chars=${_ble_syntax_bash_chars[CTX_ARGI]//'~'} fi - chars="]${chars#']'}" + chars="][${chars#']'}" local ntype; ble/syntax/parse/nest-type -v ntype local force_attr=; [[ $ntype == glob_attr=* ]] && force_attr=${ntype#*=} @@ -1924,6 +1930,13 @@ function ble/syntax:bash/ctx-bracket-expression { fi fi return 0 + elif [[ $tail == '['* ]]; then + rex='^\[@([^'$chars']+(@\]?)?)?' + rex=${rex//@/:}'|'${rex//@/'\.'}'|'${rex//@/=}'|^\[' + [[ $tail =~ $rex ]] + ((_ble_syntax_attr[i]=${force_attr:-ctx}, + i+=${#BASH_REMATCH})) + return 0 elif rex='^([^'$chars']|\\.)+' && [[ $tail =~ $rex ]]; then ((_ble_syntax_attr[i]=${force_attr:-ctx}, i+=${#BASH_REMATCH}))