diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2016-01-20 07:47:53 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2016-01-29 09:14:53 +0000 |
commit | bced1beb8cc530ea28aa994808707043dd156fb8 (patch) | |
tree | 30b7dca6a24e5a11f6b9b4dd4fd34c73a9f2f098 | |
parent | a090acab63c02900e86bd268fc9194fccf459d08 (diff) | |
download | zsh-bced1beb8cc530ea28aa994808707043dd156fb8.tar.gz zsh-bced1beb8cc530ea28aa994808707043dd156fb8.tar.xz zsh-bced1beb8cc530ea28aa994808707043dd156fb8.zip |
37700: Teach ${(z)} the 'repeat WORD SUBLIST' syntax.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Src/lex.c | 9 | ||||
-rw-r--r-- | Src/parse.c | 10 | ||||
-rw-r--r-- | Src/zsh.h | 1 | ||||
-rw-r--r-- | Test/D04parameter.ztst | 16 |
5 files changed, 38 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog index eaf8f838c..b843f5d71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/Src/lex.c b/Src/lex.c index 23b0a1cd9..d4132fe76 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -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, "]]")) { diff --git a/Src/parse.c b/Src/parse.c index 4829e3a6d..628a9aa2d 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -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); diff --git a/Src/zsh.h b/Src/zsh.h index b83b8bdbb..eee31dad1 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2921,6 +2921,7 @@ struct parse_stack { int incasepat; int isnewlin; int infor; + int inrepeat_; int intypeset; int eclen, ecused, ecnpats; diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index a6817fe22..458c5bbe1 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -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' |