zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Re: Another ${(z)param} buglet
Date: Mon, 13 Dec 2010 10:15:06 +0000	[thread overview]
Message-ID: <20101213101506.64c737ed@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20101209201913.43a94f54@pws-pc.ntlworld.com>

On Thu, 9 Dec 2010 20:19:13 +0000
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Thu, 9 Dec 2010 18:16:32 +0000
> Peter Stephenson <Peter.Stephenson@csr.com> wrote:
> > The best I can think of is extending the syntax to append options,
> > a bit like (q) can have the q multiple or a - added, but maybe less
> > gross e.g. explicit option flags like z+c+ to turn on comment
> > handling (and possibly z+C+ to strip comments). '+' appears not to
> > be taken so would work without complications and there's a mnemonic
> > that there's more to come (compared with "(q-)").
> 
> Here it is implemented and tested, so you can tell me it's not good
> enough.

One tweak to this version of the patch: if you stripped comments and
there was one right at the end of the string, the end of line was
treated as a newline so you got a ';', which is inconsistent with what
you get without the comment, and indeed with the comment retained as a
string.

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.58
diff -p -u -r1.58 lex.c
--- Src/lex.c	12 Dec 2010 22:44:51 -0000	1.58
+++ Src/lex.c	13 Dec 2010 10:12:40 -0000
@@ -800,7 +800,15 @@ gettok(void)
 		hwbegin(0);
 		hwaddc('\n');
 		addtoline('\n');
-		peek = NEWLIN;
+		/*
+		 * If splitting a line and removing comments,
+		 * we don't want a newline token since it's
+		 * treated specially.
+		 */
+		if (zleparse == 3 && lexstop)
+		    peek = ENDINPUT;
+		else
+		    peek = NEWLIN;
 	    }
 	}
 	return peek;
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.48
diff -p -u -r1.48 D04parameter.ztst
--- Test/D04parameter.ztst	12 Dec 2010 22:44:51 -0000	1.48
+++ Test/D04parameter.ztst	13 Dec 2010 10:12:40 -0000
@@ -456,6 +456,12 @@
 >another
 >one
 
+  line='with comment # at the end'
+  print -l ${(z+C+)line}
+0:Test we don't get an additional newline token
+>with
+>comment
+
   psvar=(dog)
   setopt promptsubst
   foo='It shouldn'\''t $(happen) to a %1v.'

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  parent reply	other threads:[~2010-12-13 10:15 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
2010-12-13  5:16           ` Bart Schaefer
2010-12-13 10:15         ` Peter Stephenson [this message]
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=20101213101506.64c737ed@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.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).