zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Tomáš Smetana" <t.smetana@gmail.com>, zsh-workers@sunsite.dk
Subject: Re: PATCH: Error parsing $(...)
Date: Thu, 26 Feb 2009 22:57:43 +0000	[thread overview]
Message-ID: <20090226225743.1b707d46@pws-pc> (raw)
In-Reply-To: <20090226094507.43cf3c16@gmail.com>

On Thu, 26 Feb 2009 09:45:07 +0100
Tomáš Smetana <t.smetana@gmail.com> wrote:
> # Comment containing '
> VAR=$(
> echo a
> # Comment containing '
> )
> echo $VAR
> 
> This is syntactically correct but zsh would throw an error parsing it:
> parse error near `VAR=$('
>
> I have written a patch (attached) which seems to fix the problem.
> Could you please review the patch and consider applying it?

Thanks for reporting this.

It's not quite that simple, since "#" is only a comment character
at the start of a word.  The following is better, I hope I haven't
missed any cases...

(We could do with some tests for this... and plenty of other things.
Anyone can write tests, they're just ordinary shell code comparing
against output and status.)

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.49
diff -u -r1.49 lex.c
--- Src/lex.c	25 Feb 2009 10:24:01 -0000	1.49
+++ Src/lex.c	26 Feb 2009 22:49:04 -0000
@@ -1802,16 +1802,18 @@
 static int
 skipcomm(void)
 {
-    int pct = 1, c;
+    int pct = 1, c, start = 1;
 
     cmdpush(CS_CMDSUBST);
     SETPARBEGIN
     c = Inpar;
     do {
+	int iswhite;
 	add(c);
 	c = hgetc();
 	if (itok(c) || lexstop)
 	    break;
+	iswhite = isep(c);
 	switch (c) {
 	case '(':
 	    pct++;
@@ -1854,7 +1856,15 @@
 		else
 		    add(c);
 	    break;
+	case '#':
+	    if (start) {
+		add(c);
+		while ((c = hgetc()) != '\n' && !lexstop)
+		    add(c);
+	    }
+	    break;
 	}
+	start = iswhite;
     }
     while (pct);
     if (!lexstop)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2009-02-26 22:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-26  8:45 Tomáš Smetana
2009-02-26 22:57 ` Peter Stephenson [this message]
2009-02-27 10:19   ` Peter Stephenson
2009-02-27 16:33     ` Bart Schaefer
2009-03-02 10:06       ` Peter Stephenson

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=20090226225743.1b707d46@pws-pc \
    --to=p.w.stephenson@ntlworld.com \
    --cc=t.smetana@gmail.com \
    --cc=zsh-workers@sunsite.dk \
    /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).