Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: Error parsing $(...)



On Thu, 26 Feb 2009 09:45:07 +0100
TomÃÅ Smetana <t.smetana@xxxxxxxxx> 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@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



Messages sorted by: Reverse Date, Date, Thread, Author