zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: quoting question
Date: Tue, 12 Sep 2023 21:07:24 +0100	[thread overview]
Message-ID: <8218b46632e67c16b18187612d0b0d51491cd30b.camel@ntlworld.com> (raw)
In-Reply-To: <CA+rB6GK9_BvEWc7LzO46rTdBx9L4aBP1YPgaCSruP-mG5wQdLA@mail.gmail.com>

On Tue, 2023-09-12 at 13:45 -0500, Jim wrote:
> Hi everyone,
> 
> Zsh quoting at times makes me wonder. Do quoting? Don't do quoting?
> The following case has me scratching my head.  Can someone explain what is
> going on?
> 
> datetimetest ()
> {
>   local     DT
>   DT="${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}"
>   print $DT
>   DT=${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}
>   print $DT
>   print -- "${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}"
>   print -- ${(%):-%D{%Y-%m-%d %H:%M:%S %Z}}
>   print -- "Date and Time:  ${(%):-%D{%Y-%m-%d %H:%M:%S %Z}} Test"
> }
> 
> Output:
> 
> 2023-09-12 13:21:40 CDT}    <--  why "}" when quoted
> 2023-09-12 13:21:40 CDT
> 2023-09-12 13:21:40 CDT}    <--  why "}" when quoted
> 2023-09-12 13:21:40 CDT
> Date and Time:  2023-09-12 13:21:40 CDT} Test    <--  why "}" when quoted

That's a very, very good question and I'm very glad you asked.  Er.

It looks like we're not couting brace pairs within quotes the way we do
outside.  I suppose the reason for that is something along the lines of:
if we encounter a "{" inside quotes itʼs just a reguler character so
doesnʼt have a special syntax associated.  But the inconvenience of
counting braces differently just because youʼve added double quotes surely
outweighs that.

The fix is something like the straightforward tweak at the bottom, though
this causes a failure in Y01completion.ztst that needs tracking down.
The test is

  comptesteval 'comptest-postfunc() {}'
  comptest $': *\t\t\t\t\t\t'
0:_expand shows file types
>line: {: dir1/}{}
>DESCRIPTION:{expansions}
>DI:{dir1}
>DI:{dir2}
>FI:{file1}
>FI:{file2}
>DESCRIPTION:{all expansions}
>NO:{dir1 dir2 file1 file2}
>DESCRIPTION:{original}
>NO:{*}
>line: {: dir2/}{}
>line: {: file1 }{}
>line: {: file2 }{}
>line: {: dir1 dir2 file1 file2 }{}
>line: {: *}{}

and the failure is (even though all braces here are balanced)

--- /tmp/zsh.ztst.38062/ztst.out        2023-09-12 20:52:55.852041189 +0100
+++ /tmp/zsh.ztst.38062/ztst.tout       2023-09-12 20:52:55.988039951 +0100
@@ -1,15 +1,6 @@
-line: {: dir1/}{}
-DESCRIPTION:{expansions}
-DI:{dir1}
-DI:{dir2}
-FI:{file1}
-FI:{file2}
-DESCRIPTION:{all expansions}
-NO:{dir1 dir2 file1 file2}
-DESCRIPTION:{original}
-NO:{*}
-line: {: dir2/}{}
-line: {: file1 }{}
-line: {: file2 }{}
-line: {: dir1 dir2 file1 file2 }{}
+line: {: *}{}
+line: {: *}{}
+line: {: *}{}
+line: {: *}{}
+line: {: *}{}
 line: {: *}{}
Test ./Y01completion.ztst failed: output differs from expected as shown above for:
  comptesteval 'comptest-postfunc() {}'
  comptest $': *\t\t\t\t\t\t'


diff --git a/Src/lex.c b/Src/lex.c
index 2f7937410..30d69a28b 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1584,6 +1584,13 @@ dquote_parse(char endchar, int sub)
 	    } else
 		err = 1;
 	    break;
+	case '{':
+	    if (intick || !bct)
+		break;
+	    c = Inbrace;
+	    bct++;
+	    cmdpush(CS_BRACEPAR);
+	    break;
 	}
 	if (err || lexstop)
 	    break;


pws


  parent reply	other threads:[~2023-09-12 20:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-12 18:45 Jim
2023-09-12 20:06 ` Bart Schaefer
2023-09-13  2:50   ` Jim
2023-09-13  3:41     ` Bart Schaefer
2023-09-13 15:09       ` Debug zsh (was: Re: quoting question) Pier Paolo Grassi
2023-09-13 15:28         ` Mikael Magnusson
2023-09-13 11:28   ` quoting question Jim
2023-09-13 16:11     ` Bart Schaefer
2023-09-12 20:07 ` Peter Stephenson [this message]
2023-09-12 20:23   ` Bart Schaefer
2023-09-12 20:29     ` Bart Schaefer
2023-09-13  1:56       ` Mikael Magnusson
2023-09-13  8:50         ` Peter Stephenson

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=8218b46632e67c16b18187612d0b0d51491cd30b.camel@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@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).