Skip to content

Commit

Permalink
global: normalize to "_a-zA-Z" [sabbrev: apply sabbrev to right-hand …
Browse files Browse the repository at this point in the history
…sides of variable assignments]
  • Loading branch information
akinomyoga committed Apr 3, 2023
1 parent 2f77171 commit a101fe6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion keymap/vi.sh
Expand Up @@ -102,7 +102,7 @@ function ble/keymap:vi/string#encode-rot13 {
#------------------------------------------------------------------------------
# constants

_ble_keymap_vi_REX_WORD=$'[a-zA-Z0-9_]+|[!-/:-@[-`{-~]+|[^ \t\na-zA-Z0-9!-/:-@[-`{-~]+'
_ble_keymap_vi_REX_WORD=$'[_a-zA-Z0-9]+|[!-/:-@[-`{-~]+|[^ \t\na-zA-Z0-9!-/:-@[-`{-~]+'

#------------------------------------------------------------------------------
# vi_imap/__default__, vi-command/decompose-meta
Expand Down
4 changes: 2 additions & 2 deletions keymap/vi_test.sh
Expand Up @@ -4,10 +4,10 @@
function ble/keymap:vi_test/decompose-state {
local spec=$1
ind=${spec%%:*} str=${spec#*:}
if ((${#ind}==1)) && [[ $ind == [!0-9a-zA-Z] ]]; then
if ((${#ind}==1)) && [[ $ind == [!a-zA-Z0-9] ]]; then
ind=${str%%"$ind"*} ind=${#ind} str=${str::ind}${str:ind+1}
mark=
elif ((${#ind}==2)) && [[ ${ind::1} == [!0-9a-zA-Z] && ${ind:1:1} == [!0-9a-zA-Z] ]]; then
elif ((${#ind}==2)) && [[ ${ind::1} == [!a-zA-Z0-9] && ${ind:1:1} == [!a-zA-Z0-9] ]]; then
local ind1=${ind::1} ind2=${ind:1:1} text
text=${str//"$ind2"} text=${text%%"$ind1"*} ind=${#text}
text=${str//"$ind1"} text=${text%%"$ind2"*} mark=${#text}
Expand Down
4 changes: 2 additions & 2 deletions lib/core-complete.sh
Expand Up @@ -188,7 +188,7 @@ function ble/complete/action/util/quote-insert {
ble/complete/string#escape-for-completion-context "$ins"; ins=$ret

# 直前にパラメータ展開があればエスケープ
if [[ $comps_flags == *p* && $ins == [a-zA-Z_0-9]* ]]; then
if [[ $comps_flags == *p* && $ins == [_a-zA-Z0-9]* ]]; then
case $comps_flags in
(*[DI]*)
if [[ $COMPS =~ $rex_raw_paramx ]]; then
Expand Down Expand Up @@ -2090,7 +2090,7 @@ function ble/complete/candidates/.filter-by-command {
function ble/complete/candidates/.initialize-rex_raw_paramx {
local element=$_ble_syntax_bash_simple_rex_element
local open_dquot=$_ble_syntax_bash_simple_rex_open_dquot
rex_raw_paramx='^('$element'*('$open_dquot')?)\$[a-zA-Z_][a-zA-Z_0-9]*$'
rex_raw_paramx='^('$element'*('$open_dquot')?)\$[_a-zA-Z][_a-zA-Z0-9]*$'
}

## 候補フィルタ (candidate filters) は以下の関数を通して実装される。
Expand Down
28 changes: 14 additions & 14 deletions lib/core-syntax.sh
Expand Up @@ -893,7 +893,7 @@ _ble_syntax_bash_IFS=$' \t\n'
_ble_syntax_bash_RexSpaces=$'[ \t]+'
_ble_syntax_bash_RexIFSs="[$_ble_syntax_bash_IFS]+"
_ble_syntax_bash_RexDelimiter="[$_ble_syntax_bash_IFS;|&<>()]"
_ble_syntax_bash_RexRedirect='((\{[a-zA-Z_][a-zA-Z_0-9]*\}|[0-9]+)?(&?>>?|>[|&]|<[>&]?|<<[-<]?))[ ]*'
_ble_syntax_bash_RexRedirect='((\{[_a-zA-Z][_a-zA-Z0-9]*\}|[0-9]+)?(&?>>?|>[|&]|<[>&]?|<<[-<]?))[ ]*'

## @var _ble_syntax_bash_chars[]
## 特定の役割を持つ文字の集合。Bracket expression [~] に入れて使う為の物。
Expand Down Expand Up @@ -1036,8 +1036,8 @@ function ble/syntax:bash/simple-word/update {
local q="'"

local letter='\[[!^]|[^'${_ble_syntax_bashc_simple}']'
local param1='\$([-*@#?$!0_]|[1-9][0-9]*|[a-zA-Z_][a-zA-Z_0-9]*)'
local param2='\$\{(#?[-*@#?$!0]|[#!]?([1-9][0-9]*|[a-zA-Z_][a-zA-Z_0-9]*))\}' # ${!!} ${!$} はエラーになる。履歴展開の所為?
local param1='\$([-*@#?$!0_]|[1-9][0-9]*|[_a-zA-Z][_a-zA-Z0-9]*)'
local param2='\$\{(#?[-*@#?$!0]|[#!]?([1-9][0-9]*|[_a-zA-Z][_a-zA-Z0-9]*))\}' # ${!!} ${!$} はエラーになる。履歴展開の所為?
local param=$param1'|'$param2
local bquot='\\.'
local squot=$q'[^'$q']*'$q'|\$'$q'([^'$q'\]|\\.)*'$q
Expand Down Expand Up @@ -1408,7 +1408,7 @@ function ble/syntax:bash/check-dollar {
local rex
if [[ $tail == '${'* ]]; then
# ■中で許される物: 決まったパターン + 数式や文字列に途中で切り替わる事も
if rex='^(\$\{[#!]?)([-*@#?$!0]|[1-9][0-9]*|[a-zA-Z_][a-zA-Z_0-9]*)(\[?)' && [[ $tail =~ $rex ]]; then
if rex='^(\$\{[#!]?)([-*@#?$!0]|[1-9][0-9]*|[_a-zA-Z][_a-zA-Z0-9]*)(\[?)' && [[ $tail =~ $rex ]]; then
# <parameter> = [-*@#?-$!0] | [1-9][0-9]* | <varname> | <varname> [ ... ] | <varname> [ <@> ]
# <@> = * | @
# ${<parameter>} ${#<parameter>} ${!<parameter>}
Expand Down Expand Up @@ -1460,7 +1460,7 @@ function ble/syntax:bash/check-dollar {
ble/syntax/parse/nest-push "$CTX_CMDX" '$('
((i+=2))
return 0
elif rex='^\$([-*@#?$!0_]|[1-9][0-9]*|[a-zA-Z_][a-zA-Z_0-9]*)' && [[ $tail =~ $rex ]]; then
elif rex='^\$([-*@#?$!0_]|[1-9][0-9]*|[_a-zA-Z][_a-zA-Z0-9]*)' && [[ $tail =~ $rex ]]; then
((_ble_syntax_attr[i]=CTX_PARAM,
_ble_syntax_attr[i+1]=ATTR_VAR,
i+=${#BASH_REMATCH}))
Expand Down Expand Up @@ -2226,7 +2226,7 @@ function ble/syntax:bash/ctx-expr {
function ble/syntax:bash/check-brace-expansion {
[[ $tail == '{'* ]] || return 1

local rex='^\{[-+0-9a-zA-Z.]*(\}?)'
local rex='^\{[-+a-zA-Z0-9.]*(\}?)'
[[ $tail =~ $rex ]]
local str=$BASH_REMATCH

Expand Down Expand Up @@ -2508,7 +2508,7 @@ function ble/syntax:bash/check-variable-assignment {
else
suffix="$suffix|\["
fi
local rex_assign="^[a-zA-Z_][a-zA-Z_0-9]*($suffix)"
local rex_assign="^[_a-zA-Z][_a-zA-Z0-9]*($suffix)"
[[ $tail =~ $rex_assign ]] || return 1
local rematch1=${BASH_REMATCH[1]} # for bash-3.1 ${#arr[n]} bug
if [[ $rematch1 == '+' ]]; then
Expand Down Expand Up @@ -3878,11 +3878,11 @@ function ble/syntax:bash/find-rhs {

local rex=
if ((wtype==ATTR_VAR)); then
rex='^[a-zA-Z0-9_]+(\+?=|\[)'
rex='^[_a-zA-Z0-9]+(\+?=|\[)'
elif ((wtype==CTX_VALI)); then
if [[ :$opts: == *:element-assignment:* ]]; then
# 配列要素に対しても変数代入の形式を許す
rex='^[a-zA-Z0-9_]+(\+?=|\[)|^(\[)'
rex='^[_a-zA-Z0-9]+(\+?=|\[)|^(\[)'
else
rex='^(\[)'
fi
Expand Down Expand Up @@ -4376,7 +4376,7 @@ function ble/syntax/completion-context/.add {
}

function ble/syntax/completion-context/.check/parameter-expansion {
local rex_paramx='^(\$(\{[!#]?)?)([a-zA-Z_][a-zA-Z_0-9]*)?$'
local rex_paramx='^(\$(\{[!#]?)?)([_a-zA-Z][_a-zA-Z0-9]*)?$'
if [[ ${text:istat:index-istat} =~ $rex_paramx ]]; then
local rematch1=${BASH_REMATCH[1]}
local source=variable
Expand Down Expand Up @@ -4463,7 +4463,7 @@ function ble/syntax/completion-context/.check-prefix/ctx:next-command {
ble/syntax/completion-context/.add command "$istat"

# 変数・代入のチェック
if local rex='^[a-zA-Z_][a-zA-Z_0-9]*(\+?=)?$' && [[ $word =~ $rex ]]; then
if local rex='^[_a-zA-Z][_a-zA-Z0-9]*(\+?=)?$' && [[ $word =~ $rex ]]; then
if [[ $word == *= ]]; then
if ((_ble_bash>=30100)) || [[ $word != *+= ]]; then
# VAR=<argument>: 現在位置から argument 候補を生成する
Expand Down Expand Up @@ -4628,7 +4628,7 @@ _ble_syntax_bash_complete_check_prefix[CTX_VALR]=rhs
function ble/syntax/completion-context/.check-prefix/ctx:rhs {
if ((wlen>=0)); then
local p=$wbeg
local rex='^[a-zA-Z0-9_]+(\+?=|\[)'
local rex='^[_a-zA-Z0-9]+(\+?=|\[)'
((ctx==CTX_VALR)) && rex='^(\[)'
if [[ ${text:p:index-p} =~ $rex ]]; then
if [[ ${BASH_REMATCH[1]} == '[' ]]; then
Expand Down Expand Up @@ -4681,7 +4681,7 @@ function ble/syntax/completion-context/.check-prefix/ctx:param {
## 数式中の変数名を補完する文脈
_ble_syntax_bash_complete_check_prefix[CTX_EXPR]=expr
function ble/syntax/completion-context/.check-prefix/ctx:expr {
local tail=${text:istat:index-istat} rex='[a-zA-Z_]+$'
local tail=${text:istat:index-istat} rex='[_a-zA-Z]+$'
if [[ $tail =~ $rex ]]; then
local p=$((index-${#BASH_REMATCH}))
ble/syntax/completion-context/.add variable:a "$p"
Expand Down Expand Up @@ -4761,7 +4761,7 @@ function ble/syntax/completion-context/.search-last-istat {
## @var[in] index
## @var[out] sources
function ble/syntax/completion-context/.check-prefix {
local rex_param='^[a-zA-Z_][a-zA-Z_0-9]*$'
local rex_param='^[_a-zA-Z][_a-zA-Z0-9]*$'
local from=${1:-$((index-1))}

local ret
Expand Down
2 changes: 1 addition & 1 deletion lib/init-term.sh
Expand Up @@ -52,7 +52,7 @@ function ble/init:term/define-sgr-param {
builtin eval "$name="
fi

if [[ $name =~ ^[a-zA-Z_][a-zA-Z_0-9]*$ ]]; then
if [[ $name =~ ^[_a-zA-Z][_a-zA-Z0-9]*$ ]]; then
ble/init:term/register-varname "$name"
fi
}
Expand Down
2 changes: 1 addition & 1 deletion lib/vim-surround.sh
Expand Up @@ -148,7 +148,7 @@ function ble/lib/vim-surround.sh/load-template {

# read user settings

if [[ ${ins//[0-9]} && ! ${ins//[_0-9a-zA-Z]} ]]; then
if [[ ${ins//[0-9]} && ! ${ins//[_a-zA-Z0-9]} ]]; then
local optname=bleopt_vim_surround_$ins
template=${!optname}
[[ $template ]] && return
Expand Down
8 changes: 4 additions & 4 deletions make_command.sh
Expand Up @@ -130,14 +130,14 @@ function sub:check/bash300bug {
echo "--- $FUNCNAME ---"
# bash-3.0 では local arr=(1 2 3) とすると
# local arr='(1 2 3)' と解釈されてしまう。
grc 'local [a-zA-Z_]+=\(' --exclude=./test --exclude=./make_command.sh
grc 'local [_a-zA-Z]+=\(' --exclude=./test --exclude=./make_command.sh

# bash-3.0 では local -a arr=("$hello") とすると
# クォートしているにも拘らず $hello の中身が単語分割されてしまう。
grc 'local -a [[:alnum:]_]+=\([^)]*[\"'\''`]' --exclude=./{test,ext} --exclude=./make_command.sh

# bash-3.0 では "${scalar[@]/xxxx}" は全て空になる
grc '\$\{[a-zA-Z_0-9]+\[[*@]\]/' --exclude=./{text,ext} --exclude=./make_command.sh --exclude=\*.md --color |
grc '\$\{[_a-zA-Z0-9]+\[[*@]\]/' --exclude=./{text,ext} --exclude=./make_command.sh --exclude=\*.md --color |
grep -v '#D1570'

# bash-3.0 では "..${var-$'hello'}.." は (var が存在しない時) "..'hello'..." になる。
Expand Down Expand Up @@ -172,8 +172,8 @@ function sub:check/bash502-patsub_replacement {
\Z/\$\(\([^()]+\)\)\}Zd
\Z/\$'\''([^\\]|\\.)+'\''\}Zd
\Z\$\{[a-zA-Z0-9_]+//(ARR|DICT|PREFIX|NAME)/\$([a-zA-Z0-9_]+|\{[a-zA-Z0-9_#:-]+\})\}Zd
\Z\$\{[a-zA-Z0-9_]+//'\''%[dlcxy]'\''/\$[a-zA-Z0-9_]+\}Zd # src/canvas.sh
\Z\$\{[_a-zA-Z0-9]+//(ARR|DICT|PREFIX|NAME)/\$([_a-zA-Z0-9]+|\{[_a-zA-Z0-9#:-]+\})\}Zd
\Z\$\{[_a-zA-Z0-9]+//'\''%[dlcxy]'\''/\$[_a-zA-Z0-9]+\}Zd # src/canvas.sh
\Z#D1738Zd
\Z\$\{_ble_edit_str//\$'\''\\n'\''/\$'\''\\n'\''"\$comment_begin"\}Zd # edit.sh
Expand Down
2 changes: 1 addition & 1 deletion src/color.sh
Expand Up @@ -492,7 +492,7 @@ fi
## 関数 ble/color/setface/.check-argument
## @var[out] ext
function ble/color/setface/.check-argument {
local rex='^[a-zA-Z0-9_]+$'
local rex='^[_a-zA-Z0-9]+$'
[[ $# == 2 && $1 =~ $rex && $2 ]] && return 0

local name=${FUNCNAME[1]}
Expand Down
4 changes: 2 additions & 2 deletions src/decode.sh
Expand Up @@ -167,7 +167,7 @@ function ble-decode-kbd/generate-keycode {
local keyname=$1
if ((${#keyname}==1)); then
ble/util/s2c "$1"
elif [[ $keyname && ! ${keyname//[a-zA-Z_0-9]} ]]; then
elif [[ $keyname && ! ${keyname//[_a-zA-Z0-9]} ]]; then
ble-decode-kbd/.get-keycode "$keyname"
if [[ ! $ret ]]; then
((ret=_ble_decode_FunctionKeyBase+_ble_decode_kbd__n++))
Expand Down Expand Up @@ -319,7 +319,7 @@ function ble-decode-kbd {
if [[ $kspec == ? ]]; then
ble/util/s2c "$kspec" 0
((code|=ret))
elif [[ $kspec && ! ${kspec//[_0-9a-zA-Z]} ]]; then
elif [[ $kspec && ! ${kspec//[_a-zA-Z0-9]} ]]; then
ble-decode-kbd/.get-keycode "$kspec"
[[ $ret ]] || ble-decode-kbd/generate-keycode "$kspec"
((code|=ret))
Expand Down

0 comments on commit a101fe6

Please sign in to comment.