zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: <zsh-workers@zsh.org>
Subject: Re: Another ${(z)param} buglet
Date: Tue, 14 Dec 2010 08:57:18 -0800	[thread overview]
Message-ID: <101214085720.ZM19259@torch.brasslantern.com> (raw)
In-Reply-To: <20101213181203.5a5ba7d5@pwslap01u.europe.root.pri>

On Dec 13,  6:12pm, Peter Stephenson wrote:
} Subject: Re: Another ${(z)param} buglet
}
} On Mon, 13 Dec 2010 09:35:12 -0800
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > Let's go ahead and use up Z for this so as not to tangle up z with a
} > new more restricted delimiter syntax.  Further let's immediately
} > reserve a character (maybe "+") to have no meaning of its own, but
} > instead to always introduce a delimited string into which we can put 
} > new options.
} 
} Can't see why that shouldn't work.

Here's a patch (using underscore rather than plus for the reserved
meta-flag).

Index: Doc/Zsh/expn.yo
--- zsh-forge/current/Doc/Zsh/expn.yo	2010-12-14 08:13:59.000000000 -0800
+++ Doc/Zsh/expn.yo	2010-12-14 08:54:56.000000000 -0800
@@ -1009,18 +1009,6 @@
 Comments are not treated specially but as ordinary strings, similar
 to interactive shells with the tt(INTERACTIVE_COMMENTS) option unset.
 
-The flag can take a combination of option letters between a following
-pair of `tt(PLUS())' characters.  tt(LPAR()z+PLUS()c+PLUS()RPAR())
-causes comments to be parsed as a string and retained; any field in the
-resulting array beginning with an unquoted comment character is a
-comment.  tt(LPAR()z+PLUS()C+PLUS()RPAR()) causes comments to be parsed
-and removed.  The rule for comments is standard: anything between a word
-starting with the third charcter of tt($HISTCHARS), default tt(#), up to
-the next newline is a comment.  tt(LPAR()z+PLUS()n+PLUS()RPAR()) causes
-unquoted newlines to be treated as ordinary whitespace, else they are
-treated as if they are shell code delimiters and converted to
-semicolons.
-
 Note that this is done very late, as for the `tt((s))' flag. So to
 access single words in the result, one has to use nested expansions as 
 in `tt(${${(z)foo}[2]})'. Likewise, to remove the quotes in the
@@ -1129,6 +1117,25 @@
 empty field.  To override this behaviour, supply the "(@)" flag as well,
 i.e.  tt("${(@s.:.)line}").
 )
+item(tt(Z:)var(opts)tt(:))(
+As tt(z) but takes a combination of option letters between a following
+pair of delimiter characters.  tt(LPAR()Z+PLUS()c+PLUS()RPAR())
+causes comments to be parsed as a string and retained; any field in the
+resulting array beginning with an unquoted comment character is a
+comment.  tt(LPAR()Z+PLUS()C+PLUS()RPAR()) causes comments to be parsed
+and removed.  The rule for comments is standard: anything between a word
+starting with the third charcter of tt($HISTCHARS), default tt(#), up to
+the next newline is a comment.  tt(LPAR()Z+PLUS()n+PLUS()RPAR()) causes
+unquoted newlines to be treated as ordinary whitespace, else they are
+treated as if they are shell code delimiters and converted to
+semicolons.
+)
+item(tt(_:)var(flags)tt(:))(
+The underscore (tt(_)) flag is reserved for future use.  As of this
+revision of zsh, there are no valid var(flags); anything following an
+underscore, other than an empty pair of delimiters, is treated as an
+error, and the flag itself has no effect.
+)
 enditem()
 
 The following flags are meaningful with the tt(${)...tt(#)...tt(}) or
Index: Src/subst.c
--- zsh-forge/current/Src/subst.c	2010-12-14 08:13:59.000000000 -0800
+++ Src/subst.c	2010-12-14 08:28:56.000000000 -0800
@@ -1936,10 +1936,15 @@
 
 		case 'z':
 		    shsplit = LEXFLAGS_ACTIVE;
-		    if (s[1] == '+') {
-			s += 2;
-			while (*s && *s != '+' && *s != ')' && *s != Outpar) {
-			    switch (*s++) {
+		    break;
+
+		case 'Z':
+		    t = get_strarg(++s, &arglen);
+		    if (*t) {
+			sav = *t;
+			*t = 0;
+			while (*++s) {
+			    switch (*s) {
 			    case 'c':
 				/* Parse and keep comments */
 				shsplit |= LEXFLAGS_COMMENTS_KEEP;
@@ -1956,12 +1961,14 @@
 				break;
 
 			    default:
-				goto flagerr;
+				*t = sav;
+ 				goto flagerr;
 			    }
 			}
-			if (*s != '+')
-			    goto flagerr;
-		    }
+			*t = sav;
+			s = t + arglen - 1;
+		    } else
+			goto flagerr;
 		    break;
 
 		case 'u':
@@ -1973,6 +1980,25 @@
 		    evalchar = 1;
 		    break;
 
+		case '_':
+		    t = get_strarg(++s, &arglen);
+		    if (*t) {
+			sav = *t;
+			*t = 0;
+			while (*++s) {
+			    /* Reserved for future use */
+			    switch (*s) {
+			    default:
+				*t = sav;
+				goto flagerr;
+			    }
+			}
+			*t = sav;
+			s = t + arglen - 1;
+		    } else
+			goto flagerr;
+		    break;
+
 		default:
 		  flagerr:
 		    zerr("error in flags");

Index: Test/D04parameter.ztst
--- zsh-forge/current/Test/D04parameter.ztst	2010-12-14 08:14:00.000000000 -0800
+++ Test/D04parameter.ztst	2010-12-14 08:29:28.000000000 -0800
@@ -421,9 +421,9 @@
   print "*** Normal ***"
   print -l ${(z)line}
   print "*** Kept ***"
-  print -l ${(z+c+)line}
+  print -l ${(Z+c+)line}
   print "*** Removed ***"
-  print -l ${(z+C+)line}
+  print -l ${(Z+C+)line}
 0:Comments with (z)
 >*** Normal ***
 >A
@@ -457,13 +457,13 @@
 >one
 
   line='with comment # at the end'
-  print -l ${(z+C+)line}
+  print -l ${(Z+C+)line}
 0:Test we don't get an additional newline token
 >with
 >comment
 
   line=$'echo one\necho two # with a comment\necho three'
-  print -l ${(z+nc+)line}
+  print -l ${(Z+nc+)line}
 0:Treating zplit newlines as ordinary whitespace
 >echo
 >one

-- 


  parent reply	other threads:[~2010-12-14 16:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-08  4:34 Bart Schaefer
2010-12-08 17:51 ` Peter Stephenson
2010-12-09 15:42   ` Bart Schaefer
2010-12-09 18:16     ` Peter Stephenson
2010-12-09 20:19       ` Peter Stephenson
2010-12-12 22:45         ` Peter Stephenson
2010-12-13  1:26           ` Bart Schaefer
2010-12-13  9:47             ` Peter Stephenson
2010-12-13 17:35               ` Bart Schaefer
2010-12-13 18:12                 ` Peter Stephenson
2010-12-14 10:20                   ` Peter Stephenson
2010-12-14 16:57                   ` Bart Schaefer [this message]
2010-12-13  5:16           ` Bart Schaefer
2010-12-13 10:15         ` Peter Stephenson
2010-12-09 20:25       ` Bart Schaefer

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=101214085720.ZM19259@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).