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

PATCH Re: [doogie@xxxxxxxxxxxxx: Bug#163237: zsh barfs on valid shell]



On Oct 3,  4:43pm, Clint Adams wrote:
} Subject: [doogie@xxxxxxxxxxxxx: Bug#163237: zsh barfs on valid shell]
}
} This happens under emulate -R sh as well.
} 
} ----- Forwarded message from Adam Heath <doogie@xxxxxxxxxxxxx> -----
} 
} case foo in (foo)echo foo;;(bar)echo bar;;esac
} zsh:zsh: parse error near `foo'

This is because "(foo)echo" is being parsed as a file pattern [equivalent
to "(foo|foo)echo" for those who don't immediately see why it's being
parsed that way].  The syntax error thus is that there is no close paren
after the pattern -- e.g. zsh is trying to parse one of

  case_item_ns     :     pattern ')' compound_list linebreak
  case_item        :     pattern ')' compound_list DSEMI linebreak

and therefore fails.

This is an inherent ambiguity in using parens for pattern grouping and is
going to have to stay the way it is when not in emulation mode.

Fortunately the emulation fix is not as difficult as I feared it would be.

Index: Src/lex.c
===================================================================
diff -c -r1.7 lex.c
--- Src/lex.c	1 Sep 2002 16:47:38 -0000	1.7
+++ Src/lex.c	4 Oct 2002 03:45:30 -0000
@@ -993,8 +993,12 @@
 	    c = Outbrack;
 	    break;
 	case LX2_INPAR:
-	    if ((sub || in_brace_param) && isset(SHGLOB))
-		break;
+	    if (isset(SHGLOB)) {
+		if (sub || in_brace_param)
+		    break;
+		if (incasepat && !len)
+		    return INPAR;
+	    }
 	    if (!in_brace_param) {
 		if (!sub) {
 		    e = hgetc();
Index: Src/parse.c
===================================================================
diff -c -r1.14 parse.c
--- Src/parse.c	12 Sep 2002 07:59:07 -0000	1.14
+++ Src/parse.c	4 Oct 2002 03:53:08 -0000
@@ -1042,6 +1042,8 @@
 	    yylex();
 	if (tok == OUTBRACE)
 	    break;
+	if (tok == INPAR)
+	    yylex();
 	if (tok != STRING)
 	    YYERRORV(oecused);
 	if (!strcmp(tokstr, "esac"))

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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