From 0482bf64e713dbe023b4de996f922cd161f643e7 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 30 Jan 2021 15:25:37 +0800 Subject: [PATCH] syntax: fix broken AST with "[[" keyword --- lib/core-syntax.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/core-syntax.sh b/lib/core-syntax.sh index 6d12b74b..a87fefe0 100644 --- a/lib/core-syntax.sh +++ b/lib/core-syntax.sh @@ -699,9 +699,10 @@ function ble-syntax/parse/word-pop { function ble-syntax/parse/word-cancel { local -a word ble/string#split-words word "${_ble_syntax_tree[i-1]}" - local tclen=${word[3]} - tchild=$((tclen<0?tclen:i-tclen)) - _ble_syntax_tree[i-1]="${word[*]:BLE_SYNTAX_TREE_WIDTH}" + local wlen=${word[1]} tplen=${word[3]} + local wbegin=$((i-wlen)) + tchild=$((tplen<0?tplen:i-tplen)) + ble/dense-array#fill-range _ble_syntax_tree "$wbegin" "$i" '' } # 入れ子構造の管理 @@ -2479,10 +2480,11 @@ function ble-syntax:bash/ctx-command/check-word-end { ((_ble_syntax_attr[wbeg]=ATTR_DEL, ctx=CTX_ARGX0)) - # "[[" は一度角括弧式として読み取られるので、その情報を削除する。 - ble-syntax/parse/word-cancel # 単語 "[[" を削除 - ble-syntax/parse/word-cancel # 角括弧式の nest を削除 - _ble_syntax_attr[wbeg+1]= # 角括弧式として着色されているのを消去 + ble-syntax/parse/word-cancel # 単語 "[[" (とその内部のノード全て) を削除 + if [[ $word == '[[' ]]; then + # "[[" は一度角括弧式として読み取られるので、その情報を削除する。 + _ble_syntax_attr[wbeg+1]= # 角括弧式として着色されているのを消去 + fi i=$wbeg ble-syntax/parse/nest-push "$CTX_CONDX"