about summary refs log tree commit diff
path: root/Src/lex.c
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2001-04-20 06:13:35 +0000
committerBart Schaefer <barts@users.sourceforge.net>2001-04-20 06:13:35 +0000
commit220ad9aa2310047d88c06e59fc70e649f33d8396 (patch)
tree15eaf6cd4c48bfe8c2e831db6ce9437cd901a17c /Src/lex.c
parent585c21a3935fc7dd8b8ace4d81c1bff98dec2658 (diff)
downloadzsh-220ad9aa2310047d88c06e59fc70e649f33d8396.tar.gz
zsh-220ad9aa2310047d88c06e59fc70e649f33d8396.tar.xz
zsh-220ad9aa2310047d88c06e59fc70e649f33d8396.zip
Parameter repairs, mostly for subscripting.
Diffstat (limited to 'Src/lex.c')
-rw-r--r--Src/lex.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/Src/lex.c b/Src/lex.c
index de58ade7a..46d83cb21 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1302,10 +1302,13 @@ dquote_parse(char endchar, int sub)
 	    c = hgetc();
 	    if (c != '\n') {
 		if (c == '$' || c == '\\' || (c == '}' && !intick && bct) ||
-		    c == endchar || c == '`')
+		    c == endchar || c == '`' ||
+		    (math && (c == '[' || c == ']' ||
+			      c == '(' || c == ')' ||
+			      c == '{' || c == '}')))
 		    add(Bnull);
 		else {
-		    /* lexstop is implicitely handled here */
+		    /* lexstop is implicitly handled here */
 		    add('\\');
 		    goto cont;
 		}
@@ -1458,6 +1461,38 @@ parsestrnoerr(char *s)
     return err;
 }
 
+/**/
+mod_export char *
+parse_subscript(char *s)
+{
+    int l = strlen(s), err;
+    char *t;
+
+    if (!*s || *s == ']')
+	return 0;
+    lexsave();
+    untokenize(t = dupstring(s));
+    inpush(t, 0, NULL);
+    strinbeg(0);
+    len = 0;
+    bptr = tokstr = s;
+    bsiz = l + 1;
+    err = dquote_parse(']', 1);
+    if (err) {
+	err = *bptr;
+	*bptr = 0;
+	untokenize(s);
+	*bptr = err;
+	s = 0;
+    } else
+	s = bptr;
+    strinend();
+    inpop();
+    DPUTS(cmdsp, "BUG: parse_subscript: cmdstack not empty.");
+    lexrestore();
+    return s;
+}
+
 /* Tokenize a string given in s. Parsing is done as if s were a normal *
  * command-line argument but it may contain separators.  This is used  *
  * to parse the right-hand side of ${...%...} substitutions.           */