37700: Teach ${(z)} the 'repeat WORD SUBLIST' syntax.

mikachu/badarrays
Daniel Shahaf 8 years ago
parent a090acab63
commit bced1beb8c

@ -1,5 +1,9 @@
2016-01-29 Daniel Shahaf <d.s@daniel.shahaf.name>
* 37700: Src/lex.c, Src/parse.c, Src/zsh.h,
Test/D04parameter.ztst: Teach ${(z)} the 'repeat WORD SUBLIST'
syntax.
* unposted: Completion/Unix/Command/_init_d: _init_d: Report
failure to caller.

@ -267,9 +267,13 @@ zshlex(void)
{
if (tok == LEXERR)
return;
do
do {
if (inrepeat_)
++inrepeat_;
if (inrepeat_ == 3 && isset(SHORTLOOPS))
incmdpos = 1;
tok = gettok();
while (tok != ENDINPUT && exalias());
} while (tok != ENDINPUT && exalias());
nocorrect &= 1;
if (tok == NEWLIN || tok == ENDINPUT) {
while (hdocs) {
@ -1899,6 +1903,7 @@ exalias(void)
zshlextext[0] == '}' && !zshlextext[1])) &&
(rw = (Reswd) reswdtab->getnode(reswdtab, zshlextext))) {
tok = rw->token;
inrepeat_ = (tok == REPEAT);
if (tok == DINBRACK)
incond = 1;
} else if (incond && !strcmp(zshlextext, "]]")) {

@ -63,6 +63,12 @@ int isnewlin;
/**/
int infor;
/* != 0 if we are after a repeat keyword; if it's nonzero it's a 1-based index
* of the current token from the last-seen command position */
/**/
int inrepeat_; /* trailing underscore because of name clash with Zle/zle_vi.c */
/* != 0 if parsing arguments of typeset etc. */
/**/
@ -271,6 +277,7 @@ parse_context_save(struct parse_stack *ps, int toplevel)
ps->incasepat = incasepat;
ps->isnewlin = isnewlin;
ps->infor = infor;
ps->inrepeat_ = inrepeat_;
ps->intypeset = intypeset;
ps->hdocs = hdocs;
@ -305,6 +312,7 @@ parse_context_restore(const struct parse_stack *ps, int toplevel)
incasepat = ps->incasepat;
isnewlin = ps->isnewlin;
infor = ps->infor;
inrepeat_ = ps->inrepeat_;
intypeset = ps->intypeset;
hdocs = ps->hdocs;
@ -447,6 +455,7 @@ init_parse_status(void)
* using the lexical analyser for strings as well as here.
*/
incasepat = incond = inredir = infor = intypeset = 0;
inrepeat_ = 0;
incmdpos = 1;
}
@ -1482,6 +1491,7 @@ par_while(int *cmplx)
static void
par_repeat(int *cmplx)
{
/* ### what to do about inrepeat_ here? */
int oecused = ecused, p;
p = ecadd(0);

@ -2921,6 +2921,7 @@ struct parse_stack {
int incasepat;
int isnewlin;
int infor;
int inrepeat_;
int intypeset;
int eclen, ecused, ecnpats;

@ -479,6 +479,8 @@
'(( 3 + 1 == 8 / 2 ))'
'for (( i = 1 ; i < 10 ; i++ ))'
'((0.25542 * 60) - 15)*60'
'repeat 3 (x)'
'repeat 3 (echo foo; echo bar)'
)
for string in $strings; do
array=(${(z)string})
@ -514,6 +516,20 @@
>8:15:
>9:):
>10:*60:
>1:repeat:
>2:3:
>3:(:
>4:x:
>5:):
>1:repeat:
>2:3:
>3:(:
>4:echo:
>5:foo:
>6:;:
>7:echo:
>8:bar:
>9:):
line=$'A line with # someone\'s comment\nanother line # (1 more\nanother one'

Loading…
Cancel
Save