Skip to content

Commit

Permalink
syntax: fix unrecognized asignment "echo arr[i]+=rhs" [sabbrev: apply…
Browse files Browse the repository at this point in the history
… sabbrev to right-hand sides of variable assignments]

* complete (source:argument): fallback to rhs completion also for "name+=rhs"
* syntax: fix unrecognized variable assignment of the form "echo arr[i]+=rhs"
  • Loading branch information
akinomyoga committed Apr 3, 2023
1 parent a101fe6 commit 948f50f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/core-complete.sh
Expand Up @@ -1702,7 +1702,7 @@ function ble/complete/source:argument {
fi

if ((cand_count<=old_cand_count)); then
if local rex='^/?[-_a-zA-Z0-9.]+[:=]|^-[^-/=:]'; [[ $COMPV =~ $rex ]]; then
if local rex='^/?[-_a-zA-Z0-9.]+\+?[:=]|^-[^-/=:]'; [[ $COMPV =~ $rex ]]; then
# var=filename --option=filename /I:filename など。
local prefix=$BASH_REMATCH value=${COMPV:${#BASH_REMATCH}}
local COMP_PREFIX=$prefix
Expand Down
7 changes: 6 additions & 1 deletion lib/core-syntax.sh
Expand Up @@ -1925,7 +1925,7 @@ function ble/syntax:bash/ctx-bracket-expression {
((_ble_syntax_attr[i++]=ctx,is_assign=1))
elif [[ $tail == ']+'* ]]; then
ble/syntax/parse/set-lookahead 2
[[ $tail == ']+=' ]] && ((_ble_syntax_attr[i]=ctx,i+=2,is_assign=1))
[[ $tail == ']+='* ]] && ((_ble_syntax_attr[i]=ctx,i+=2,is_assign=1))
fi

if [[ $is_assign ]]; then
Expand Down Expand Up @@ -3864,6 +3864,8 @@ function ble/syntax:bash/find-end-of-array-index {
## @param[in] opts
## element-assignment
## 配列要素の場合にも変数代入の形式を許します。
## long-option
## --long-option= の形式にも強制的に対応します。
## @var[out] ret
## 右辺の開始位置を返します。
## 変数代入の形式でない時には単語の開始位置を返します。
Expand All @@ -3887,6 +3889,9 @@ function ble/syntax:bash/find-rhs {
rex='^(\[)'
fi
fi
if [[ :$opts: == *:long-option:* ]]; then
rex=${rex:+$rex'|'}'^--[-_a-zA-Z0-9]+='
fi

if [[ $rex && $word =~ $rex ]]; then
local last_char=${BASH_REMATCH:${#BASH_REMATCH}-1}
Expand Down

0 comments on commit 948f50f

Please sign in to comment.