incorporate latest parser fixes

pull/436/head
romkatv 5 years ago
parent bc0429f3bb
commit 02a5d21f12

@ -5269,6 +5269,7 @@ _p9k_init_params() {
typeset -grA __p9k_pb_cmd_skip=( typeset -grA __p9k_pb_cmd_skip=(
'}' '' '}' ''
'{' ''
'|' '' '|' ''
'||' '' '||' ''
'&' '' '&' ''
@ -5278,7 +5279,6 @@ typeset -grA __p9k_pb_cmd_skip=(
'&|' '' '&|' ''
')' '' ')' ''
'(' '' '(' ''
'{' ''
'()' '' '()' ''
'!' '' '!' ''
';' '' ';' ''
@ -5353,34 +5353,30 @@ typeset -grA __p9k_pb_term=(
';|' '' ';|' ''
'(' '' '(' ''
')' '' ')' ''
'{' ''
'}' ''
'()' '' '()' ''
'}' ''
) )
typeset -grA __p9k_pb_term_skip=( typeset -grA __p9k_pb_term_skip=(
'()' ''
'(' '\)' '(' '\)'
';;' '\)|esac' ';;' '\)|esac'
';&' '\)|esac' ';&' '\)|esac'
';|' '\)|esac' ';|' '\)|esac'
) )
# False positives: # Usage: _p9k_parse_buffer <buffer> [token-limit]
# #
# {} always {} # Parses the specified command line buffer and pupulates array P9K_COMMANDS
# with commands from it. Terminates early and returns 1 if there are more
# tokens than the specified limit.
# #
# False negatives: # Broken:
# #
# --------------- # ---------------
# : $(x) # : $(x)
# --------------- # ---------------
# : `x` # : `x`
# --------------- # ---------------
#
# Broken:
#
# ---------------
# ${x/} # ${x/}
# --------------- # ---------------
# - -- x # - -- x
@ -5391,6 +5387,8 @@ typeset -grA __p9k_pb_term_skip=(
# --------------- # ---------------
# x=$y; $x # x=$y; $x
# --------------- # ---------------
# alias x=y; y
# ---------------
# x <<END # x <<END
# ; END # ; END
# END # END
@ -5404,33 +5402,40 @@ typeset -grA __p9k_pb_term_skip=(
# #
# More brokenness with non-standard options (ignore_braces, ignore_close_braces, etc.). # More brokenness with non-standard options (ignore_braces, ignore_close_braces, etc.).
function _p9k_parse_buffer() { function _p9k_parse_buffer() {
[[ ${2:-0} == <-> ]] || return 2
local rcquotes local rcquotes
[[ -o rcquotes ]] && rcquotes=(-o rcquotes) [[ -o rcquotes ]] && rcquotes=(-o rcquotes)
emulate -L zsh -o extended_glob -o no_nomatch $rcquotes emulate -L zsh -o extended_glob -o no_nomatch $rcquotes
typeset -ga P9K_COMMANDS=()
local -r id='(<->|[[:alpha:]_][[:IDENT:]]#)' local -r id='(<->|[[:alpha:]_][[:IDENT:]]#)'
local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\"" local -r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\""
local -i e c=32 local -i e ic c=${2:-'1 << 62'}
local skip n s r state local skip n s r state
local -a aln alp alf v commands match mbegin mend local -a aln alp alf v commands
[[ -o interactive_comments ]] && local tokens=(${(Z+C+)1}) || local tokens=(${(z)1}) if [[ -o interactive_comments ]]; then
ic=1
local tokens=(${(Z+C+)1})
else
local tokens=(${(z)1})
fi
() { {
while (( $#tokens )); do while (( $#tokens )); do
if (( $#tokens == alp[-1] )); then (( e = $#state ))
if (( $#alp && $#tokens == alp[-1] )); then
aln[-1]=() aln[-1]=()
alp[-1]=() alp[-1]=()
if (( $#tokens == alf[-1] )); then if (( $#tokens == alf[-1] )); then
alf[-1]=() alf[-1]=()
(( e = 0 )) (( e = 0 ))
else
(( e = $#state ))
fi fi
else
(( e = $#state ))
fi fi
while (( c-- > 0 )) || return; do while (( c-- > 0 )) || return; do
@ -5438,56 +5443,96 @@ function _p9k_parse_buffer() {
tokens[1]=() tokens[1]=()
if (( $+galiases[$token] )); then if (( $+galiases[$token] )); then
(( $aln[(eI)p$token] )) && break (( $aln[(eI)p$token] )) && break
n=p$token
s=$galiases[$token] s=$galiases[$token]
n=p$token
elif (( e )); then elif (( e )); then
break break
elif (( $+aliases[$token] )); then elif (( $+aliases[$token] )); then
(( $aln[(eI)p$token] )) && break (( $aln[(eI)p$token] )) && break
n=p$token
s=$aliases[$token] s=$aliases[$token]
elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then n=p$token
(( $aln[(eI)s$match[1]] )) && break elif [[ $token == ?*.?* ]] && (( $+saliases[${token##*.}] )); then
n=s$match[1] r=${token##*.}
s=${saliases[$match[1]]%% #} (( $aln[(eI)s$r] )) && break
s=${saliases[$r]%% #}
n=s$r
else else
break break
fi fi
aln+=$n aln+=$n
alp+=$#tokens alp+=$#tokens
[[ $s == *' ' ]] && alf+=$#tokens [[ $s == *' ' ]] && alf+=$#tokens
[[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s}) (( ic )) && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
done done
if [[ $token == '<<'(|-) ]]; then
state=h
continue
fi
case $state in case $state in
a)
if [[ $token == $skip ]]; then
if [[ $token == '{' ]]; then
P9K_COMMANDS+=($commands)
commands=()
state=
else
skip='{'
fi
continue
else
state=t
fi
;& # fall through
t|p*) t|p*)
if (( $+__p9k_pb_term[$token] )); then if (( $+__p9k_pb_term[$token] )); then
if [[ $token == '()' ]]; then
state=
else
P9K_COMMANDS+=($commands)
if [[ $token == '}' ]]; then
state=a
skip=always
else
skip=$__p9k_pb_term_skip[$token] skip=$__p9k_pb_term_skip[$token]
state=${skip:+s} state=${skip:+s}
[[ $token == '()' ]] || P9K_COMMANDS+=($commands) fi
fi
commands=() commands=()
continue continue
elif [[ $state == t ]]; then elif [[ $state == t ]]; then
continue continue
fi;; fi
;;
s) s)
if [[ $token == $~skip ]]; then if [[ $token == $~skip ]]; then
state= state=
fi fi
continue;; continue
;;
*r) *r)
state[1]= state[1]=
continue;;
h)
skip=${(b)token}
state=s
continue;;
esac
if [[ $token == '<<'(|-) ]]; then
state=h
continue continue
;;
h)
while (( $#tokens )); do
(( e = ${tokens[(i)$token]} ))
if [[ $tokens[e-1] == ';' && $tokens[e+1] == ';' ]]; then
tokens[1,e]=()
break
else
tokens[1,e]=()
fi fi
done
while (( $#alp && alp[-1] >= $#tokens )); do
aln[-1]=()
alp[-1]=()
done
state=t
continue
;;
esac
if (( $+__p9k_pb_redirect[${token#<0-255>}] )); then if (( $+__p9k_pb_redirect[${token#<0-255>}] )); then
state+=r state+=r
@ -5520,7 +5565,8 @@ function _p9k_parse_buffer() {
continue continue
fi fi
fi fi
: ${token::=${(Q)${~token}}};; : ${token::=${(Q)${~token}}}
;;
p) p)
: ${token::=${(Q)${~token}}} : ${token::=${(Q)${~token}}}
case $token in case $token in
@ -5528,11 +5574,12 @@ function _p9k_parse_buffer() {
--) state=p1; continue;; --) state=p1; continue;;
$~skip) state=p2; continue;; $~skip) state=p2; continue;;
*) continue;; *) continue;;
esac;; esac
p1) ;; ;;
p2) p2)
state=p state=p
continue;; continue
;;
esac esac
commands+=$token commands+=$token
@ -5543,11 +5590,12 @@ function _p9k_parse_buffer() {
state=t state=t
fi fi
done done
} } always {
P9K_COMMANDS+=($commands) P9K_COMMANDS+=($commands)
P9K_COMMANDS=(${(u)P9K_COMMANDS:#('(('*'))'|'`'*'`'|'$'*)}) P9K_COMMANDS=(${(u)P9K_COMMANDS:#('(('*'))'|'`'*'`'|'$'*)})
} }
}
function _p9k_on_widget_zle-keymap-select() { __p9k_reset_state=2; } function _p9k_on_widget_zle-keymap-select() { __p9k_reset_state=2; }
function _p9k_on_widget_overwrite-mode() { __p9k_reset_state=2; } function _p9k_on_widget_overwrite-mode() { __p9k_reset_state=2; }
@ -5616,7 +5664,7 @@ function _p9k_widget_hook() {
P9K_COMMANDS=($_p9k__last_commands) P9K_COMMANDS=($_p9k__last_commands)
else else
_p9k__last_buffer=$PREBUFFER$BUFFER _p9k__last_buffer=$PREBUFFER$BUFFER
_p9k_parse_buffer $_p9k__last_buffer # 2>/dev/null _p9k_parse_buffer $_p9k__last_buffer 32
_p9k__last_commands=($P9K_COMMANDS) _p9k__last_commands=($P9K_COMMANDS)
fi fi
(( $+functions[p10k-on-post-widget] )) && p10k-on-post-widget "${@:2}" (( $+functions[p10k-on-post-widget] )) && p10k-on-post-widget "${@:2}"

Loading…
Cancel
Save