speed up parsing

pull/436/head
romkatv 5 years ago
parent 07ee25a147
commit c4f68bd609

@ -1,51 +1,3 @@
function _p9k_skip_until() {
[[ -z $1 ]] && return
while _p9k_next_token 0; do
[[ $token == $~1 ]] && return
done
}
function _p9k_next_token() {
if (( $#tokens == aln[-1] )); then
aln[-1]=()
alp[-1]=()
fi
if (( $#tokens == alf[-1] )); then
alf[-1]=()
1=1
fi
while (( $#tokens )); do
token=$tokens[1]
shift 1 tokens
if (( $+galiases[$token] )); then
(( aln[(eI)p$token] )) && return
local n=p$token s=$galiases[$token]
elif (( ! $1 )); then
return
elif (( $+aliases[$token] )); then
(( aln[(eI)p$token] )) && return
local n=p$token s=$aliases[$token]
elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then
(( aln[(eI)s$match[1]] )) && return
local n=s$match[1] s=${saliases[$match[1]]%% #}
else
return 0
fi
aln+=$n
alp+=$#tokens
[[ $s == *' ' ]] && alf+=$#tokens
[[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
done
token=
return 1
}
typeset -gA _p9k_skip_token=( typeset -gA _p9k_skip_token=(
'}' '' '}' ''
'|' '' '|' ''
@ -117,35 +69,85 @@ function _p9k_extract_commands() {
emulate -L zsh -o extended_glob -o no_nomatch $rcquotes emulate -L zsh -o extended_glob -o no_nomatch $rcquotes
typeset -ga _p9k_commands=() typeset -ga _p9k_commands=()
local -a aln alp alf match mbegin mend
local -i e
local id='$(<->|[[:alpha:]_][[:IDENT:]]#)'
local skip n s r var="\$$id|\${$id}|\"\$$id\"|\"\${$id}\""
local -a aln alp alf v match mbegin mend
[[ -o interactive_comments ]] && local tokens=(${(Z+C+)1}) || local tokens=(${(z)1}) [[ -o interactive_comments ]] && local tokens=(${(Z+C+)1}) || local tokens=(${(z)1})
while _p9k_next_token 1; do while (( $#tokens )); do
local r=${token#<0-255>} if (( $#tokens == aln[-1] )); then
aln[-1]=()
alp[-1]=()
if (( $#tokens == alf[-1] )); then
alf[-1]=()
e=0
else
e=$#skip
fi
else
e=$#skip
fi
while (( $#tokens )) || break; do
token=$tokens[1]
shift 1 tokens
if (( $+galiases[$token] )); then
(( $aln[(eI)p$token] )) && break
n=p$token
s=$galiases[$token]
elif (( e )); then
break
elif (( $+aliases[$token] )); then
(( $aln[(eI)p$token] )) && break
n=p$token
s=$aliases[$token]
elif [[ $token == (#b)?*.(?*) ]] && (( $+saliases[$match[1]] )); then
(( $aln[(eI)s$match[1]] )) && break
n=s$match[1]
s=${saliases[$match[1]]%% #}
else
break
fi
aln+=$n
alp+=$#tokens
[[ $s == *' ' ]] && alf+=$#tokens
[[ -o interactive_comments ]] && tokens[1,0]=(${(Z+C+)s}) || tokens[1,0]=(${(z)s})
done
if [[ -n $skip ]]; then
if [[ $token == $~skip ]]; then
[[ $token == ';'[';&|'] ]] && skip='\)|esac' || skip=
fi
continue
fi
r=${token#<0-255>}
if (( $+_p9k_skip_token[$r] )); then if (( $+_p9k_skip_token[$r] )); then
if (( $+_p9k_skip_token[$token] )); then if (( $+_p9k_skip_token[$token] )); then
_p9k_skip_until $_p9k_skip_token[$token] skip=$_p9k_skip_token[$token]
continue continue
fi fi
if (( $+_p9k_redirect[$r] )); then if (( $+_p9k_redirect[$r] )); then
_p9k_next_token 0 skip='*'
continue continue
fi fi
fi fi
if [[ $token == *=* ]]; then if [[ $token == *=* ]]; then
local v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=} v=${(S)token/#(<->|([[:alpha:]_][[:IDENT:]]#(|'['*[^\\](\\\\)#']')))(|'+')=}
if (( $#v < $#token )); then if (( $#v < $#token )); then
[[ $v == '(' ]] && _p9k_skip_until '\)' [[ $v == '(' ]] && skip='\)'
continue continue
fi fi
fi fi
if [[ $token == *'$'* ]]; then if [[ $token == *'$'* ]]; then
local p='<->|[[:alpha:]_][[:IDENT:]]#' if [[ $token == $~id ]]; then
if [[ $token == ('$'$~p|'${'$~p'}'|'"$'$~p'"'|'"${'$~p'}"') ]]; then n=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]}
local name=${${token##[^[:IDENT:]]}%%[^[:IDENT:]]} [[ $token == *'"' ]] && v=("${(@P)n}") || v=(${(P)name})
[[ $token == *'"' ]] && local v=("${(@P)name}") || local v=(${(P)name})
tokens[1,0]=(${(qq)v}) tokens[1,0]=(${(qq)v})
continue continue
fi fi
@ -154,8 +156,6 @@ function _p9k_extract_commands() {
_p9k_commands+=${token::=${(Q)${~token}}} _p9k_commands+=${token::=${(Q)${~token}}}
# '|' '||' ';' '&' '&&' '|&' '&!' '&|' ';;' ';&' ';|' ')' # '|' '||' ';' '&' '&&' '|&' '&!' '&|' ';;' ';&' ';|' ')'
_p9k_skip_until '\||\|\||;|&|&&|\|&|&!|&\||;;|;&|;\||\)|}' skip='\||\|\||;|&|&&|\|&|&!|&\||;;|;&|;\||\)|}'
[[ $token == ';'(';'|'&'|'|') ]] && _p9k_skip_until '\)|esac'
done done
true
} }

Loading…
Cancel
Save