diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/text.c | 21 | ||||
-rw-r--r-- | Test/A01grammar.ztst | 24 |
3 files changed, 40 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog index f20af3669..19b72edb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-07-04 Peter Stephenson <p.w.stephenson@ntlworld.com> + + * 35682: Src/text.c, plus Test/A01grammar.ztst: turning case + statements parsed as multiple alternatives back into text. + 2015-07-03 Oliver Kiddle <opk@zsh.org> * 35681: Src/Modules/datetime.c: fix day of month initialisation diff --git a/Src/text.c b/Src/text.c index 3287c54ac..d63141b20 100644 --- a/Src/text.c +++ b/Src/text.c @@ -681,7 +681,7 @@ gettext2(Estate state) case WC_CASE: if (!s) { Wordcode end = state->pc + WC_CASE_SKIP(code); - wordcode nalts; + wordcode nalts, ialts; taddstr("case "); taddstr(ecgetstr(state, EC_NODUP, NULL)); @@ -702,21 +702,22 @@ gettext2(Estate state) taddchr(' '); taddstr("("); code = *state->pc++; - nalts = *state->pc++; - while (nalts--) { + nalts = ialts = *state->pc++; + while (ialts--) { taddstr(ecgetstr(state, EC_NODUP, NULL)); state->pc++; - if (nalts) + if (ialts) taddstr(" | "); } taddstr(") "); tindent++; n = tpush(code, 0); n->u._case.end = end; - n->pop = (state->pc - 2 + WC_CASE_SKIP(code) >= end); + n->pop = (state->pc - 2 - nalts + WC_CASE_SKIP(code) + >= end); } } else if (state->pc < s->u._case.end) { - wordcode nalts; + wordcode nalts, ialts; dec_tindent(); switch (WC_CASE_TYPE(code)) { case WC_CASE_OR: @@ -737,17 +738,17 @@ gettext2(Estate state) taddchr(' '); taddstr("("); code = *state->pc++; - nalts = *state->pc++; - while (nalts--) { + nalts = ialts = *state->pc++; + while (ialts--) { taddstr(ecgetstr(state, EC_NODUP, NULL)); state->pc++; - if (nalts) + if (ialts) taddstr(" | "); } taddstr(") "); tindent++; s->code = code; - s->pop = ((state->pc - 2 + WC_CASE_SKIP(code)) >= + s->pop = ((state->pc - 2 - nalts + WC_CASE_SKIP(code)) >= s->u._case.end); } else { dec_tindent(); diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index 50058e25d..8221735b6 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -695,3 +695,27 @@ 0:Balanced parentheses and spaces with zsh pattern >It worked >That worked, too + + fn() { + typeset ac_file="the else branch" + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; + *.* ) break;; + *) + ;; + esac + print Stuff here + } + which fn + fn +0:Long case with parsed alternatives turned back into text +>fn () { +> typeset ac_file="the else branch" +> case $ac_file in +> (*.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj) ;; +> (*.*) break ;; +> (*) ;; +> esac +> print Stuff here +>} +>Stuff here |