zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: globbing in the repeat-count word gives "illegal character"
Date: Mon, 23 Mar 2020 05:31:55 +0000	[thread overview]
Message-ID: <20200323053155.6644a1d6@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <CAHYJk3RdF4bRq+rbEeox4PNeWjBEZ1pcuGSJAj3q5xEwxj5riQ@mail.gmail.com>

Mikael Magnusson wrote on Tue, 17 Mar 2020 19:37 +0100:
> On 3/17/20, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> > [[[
> > $ Src/zsh -f
> > % cd "$(mktemp -d)"
> > % repeat ? true
> > zsh: bad math expression: illegal character: \M-W
> > %
> > ]]]
> >
> > [[[
> > frame #1: 0x0000000000487eac zsh`matheval(s="\x97") at math.c:1479
> >    1476     x = mathevall(s, MPREC_TOP, &junk);
> >    1477     mtok = xmtok;
> >    1478     if (*junk)  
> > -> 1479         zerr("bad math expression: illegal character: %c", *junk);  
> >    1480     return x;
> >    1481 }
> >    1482
> > (lldb) p *junk
> > (char) $0 = '\x97'
> > ]]]
> >
> > [[[
> > % ag 0x97 | cat
> > Src/zsh.h:191:#define Quest             ((char) 0x97)
> > %
> > ]]]  
> 
> Not limited to globbing characters,
> 
> % repeat { false
> zsh: bad math expression: illegal character: \M-O

And what about this one? —
.
    % repeat 2*2 pwd
    zsh: bad math expression: illegal character: \M-G

What's the expected behaviour on this one?  Should it report a different
error, or perform globbing, or take «2*2» as a valid arithmetic
expression and run 4 iterations of the loop body?

Code-wise, execrepeat() calls singsub() when the "has tokens" flag is set:

   487	int
   487	execrepeat(Estate state, UNUSED(int do_exec))
   488	{
   ⋮
   500	    lastval = 0;
   501	    tmp = ecgetstr(state, EC_DUPTOK, &htok);
   502	    if (htok)
   503		singsub(&tmp);
   504	    count = mathevali(tmp);
   505	    if (errflag)
   506		return 1;

When singsub() returns, there are still tokens in the string (Quest,
Inbrace, or Star, respectively).  Is that expected, or should singsub()
have converted those tokens to their ASCII equivalents?

Is the fix just to call untokenize() after singsub()?  Some singsub()
callers do this, but some don't, and I haven't figured out the rule (if
there is one).  I tried this and it seemed to work, but…

Cheers,

Daniel

  reply	other threads:[~2020-03-23  5:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17  3:29 Daniel Shahaf
2020-03-17 18:37 ` Mikael Magnusson
2020-03-23  5:31   ` Daniel Shahaf [this message]
2020-03-23  6:53     ` Mikael Magnusson
2020-03-25 21:09       ` Peter Stephenson
     [not found]         ` <20200325234655.786e8a88@tarpaulin.shahaf.local2>
2020-03-26 20:58           ` 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=20200323053155.6644a1d6@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).