zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: PATCH Re: 5.0.8 regression regarding $() in arithmetic for-loops
Date: Wed, 29 Jul 2015 22:19:50 -0700	[thread overview]
Message-ID: <150729221950.ZM6401@torch.brasslantern.com> (raw)
In-Reply-To: <2541320.9goV5iBpxM@kdudka.brq.redhat.com>

This turns out to be a recursive-descent parsing error, we weren't saving
enough state when entering command substitution from inside math parsing.

I'm not sure whether the "infor" stuff is actually necessary but it seemed
to make sense.  The real meat is dbparens = 0 when leaving math context.


diff --git a/Src/lex.c b/Src/lex.c
index b0cd963..70f3d14 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1388,7 +1388,7 @@ dquote_parse(char endchar, int sub)
 {
     int pct = 0, brct = 0, bct = 0, intick = 0, err = 0;
     int c;
-    int math = endchar == ')' || endchar == ']';
+    int math = endchar == ')' || endchar == ']' || infor;
     int zlemath = math && zlemetacs > zlemetall + addedx - inbufct;
 
     while (((c = hgetc()) != endchar || bct ||
@@ -1995,8 +1995,10 @@ skipcomm(void)
 #else
     char *new_tokstr;
     int new_lexstop, new_lex_add_raw;
+    int save_infor = infor;
     struct lexbufstate new_lexbuf;
 
+    infor = 0;
     cmdpush(CS_CMDSUBST);
     SETPARBEGIN
     add(Inpar);
@@ -2065,6 +2067,7 @@ skipcomm(void)
      * the recursive parsing.
      */
     lexflags &= ~LEXFLAGS_ZLE;
+    dbparens = 0;	/* restored by zcontext_restore_partial() */
 
     if (!parse_event(OUTPAR) || tok != OUTPAR)
 	lexstop = 1;
@@ -2111,6 +2114,7 @@ skipcomm(void)
     if (!lexstop)
 	SETPAREND
     cmdpop();
+    infor = save_infor;
 
     return lexstop;
 #endif
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 59f87fa..7eedfa6 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -182,6 +182,12 @@
 >1
 >2
 
+  for (( $(true); ; )); do break; done
+  for (( ; $(true); )); do break; done
+  for (( ; ; $(true) )); do break; done
+  for (( ; $((1)); )); do break; done
+0:regression test, nested cmdsubst in arithmetic `for' loop
+
   for keyvar valvar in key1 val1 key2 val2; do
      print key=$keyvar val=$valvar
   done


  reply	other threads:[~2015-07-30  5:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 13:48 Christian Neukirchen
2015-07-27 15:34 ` Bart Schaefer
2015-07-28  8:35   ` Kamil Dudka
2015-07-30  5:19     ` Bart Schaefer [this message]
2015-07-30 16:06       ` PATCH " Kamil Dudka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150729221950.ZM6401@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).