zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Parser issues and and [[ $var ]]
Date: Sun, 11 May 2014 11:12:00 -0700	[thread overview]
Message-ID: <140511111200.ZM20625@torch.brasslantern.com> (raw)
In-Reply-To: <20140511180148.3b614054@pws-pc.ntlworld.com>

On May 11,  6:01pm, Peter Stephenson wrote:
} Subject: Re: Parser issues and and [[ $var ]]
}
} On Sat, 10 May 2014 18:01:44 -0700
} Bart Schaefer <schaefer@brasslantern.com> wrote:
} > I've found a couple of other bugs with 32604, so it's probably just as
} > well that I didn't commit/push it.  Does anyone know why the lexer
} > sometimes sets (tok = DOUTBRACK, tokstr = "\220\220") and other times
} > (tok = DOUTBRACK, tokstr = NULL) ?
} 
} It must surely be an oversight. I think a long time ago the lexer
} didn't bother setting tokstr when there was a unique token, since the
} string could in principle be deduced; however, it proverd much more
} convenient just to be able to use tokstr in any case.

In this instance it's actually easier for the caller if tokstr = NULL
consistently, rather than the other way around ...

} > Thus it would seem that the parser does need a way to explicitly test
} > for module-defined operators to also support non-operator non-empty
} > strings evaluating as true.  Or, we can decree that any string that
} > starts with a "-" is treated as an operator, since all module-defined
} > operators must start with "-", which would differ from ksh93 but not
} > from previous zsh.  (foo=-m; [[ $foo ]]) would still test as a string.
} 
} I think the latter is probably acceptable, but maybe there should be an
} interface saying a condition code defined by a module has been called with
} zero arguments (which might on failure alternatively confirm that there
} was no such condition code, allowing a different interpretation).

Hmm.

It turns out that because you can define a function that uses an operator
before you have loaded the module ...

zsh% foo() { [[ -m 1 2 3 ]] && echo OK }
zsh% foo
zsh: unknown condition: -m
zsh% zmodload zsh/example
The example module has now been set up.
zsh% foo
OK

... that it also won't work to cause a parse error on unknown operators.

I'm beginning to suspect that from a syntax perspective prefix operators
that accept multiple arguments are already a problem.  Suppose you have
defined an operator that takes 0 to 4 arguments, call it "-uptofour".
Isn't the following an intractable syntax problem?

  [[ -uptofour -a -n $foo ]]

Or do the "arguments" have to be things that don't look like operators?
What if another module defines an infix operator "-both" and you write

  [[ -uptofour -both -n $foo ]]

?  Is -both an operator or an argument?  Before the module is loaded, how
do you tell?

Incidentally, even before any of my patching attempts:

zsh% [[ -n 1 2 3 ]]
zsh: unknown condition: -n

Not parse error, not "wrong number of arguments", but "uknown condition".
Whereas:

$ [[ -n 1 2 3 ]]
ksh: syntax error: `2' unexpected


  reply	other threads:[~2014-05-11 18:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAH_OBicpVKS-URnd-Gq=gj+qc6OhDCqf0mgDfVcda27mEEfUKg@mail.gmail.com>
     [not found] ` <140416102727.ZM19090@torch.brasslantern.com>
     [not found]   ` <CAH_OBic7sX1Oc4VWn2KvX40smbRB6A7w8QGXLvPfZLD=CHMddQ@mail.gmail.com>
     [not found]     ` <534FE710.3020601@eastlink.ca>
     [not found]       ` <140417123722.ZM22179@torch.brasslantern.com>
     [not found]         ` <20140423165024.1480528a@pws-pc.ntlworld.com>
     [not found]           ` <lj984r$6uo$1@ger.gmane.org>
     [not found]             ` <CAHYJk3QOZTnicq+Nqg4BXNANa_c6_j5mhyQNK1f8YNtDhxixgA@mail.gmail.com>
     [not found]               ` <slrnlll0kq.v0i.martin@lounge.imp.fu-berlin.de>
     [not found]                 ` <20140425172112.7bf50606@pwslap01u.europe.root.pri>
     [not found]                   ` <slrnlln1bj.a9l.martin@epidot.math.uni-rostock.de>
2014-04-26 20:30                     ` Bart Schaefer
2014-05-10 21:09                       ` Bart Schaefer
2014-05-11  1:01                         ` Bart Schaefer
2014-05-11 17:01                           ` Peter Stephenson
2014-05-11 18:12                             ` Bart Schaefer [this message]
2014-05-13  5:01                               ` [PATCH] " Bart Schaefer
2014-05-13  9:10                                 ` Peter Stephenson
2014-05-13 15:03                                   ` Bart Schaefer
     [not found]                     ` <20140426212126.58b0ff26@pws-pc.ntlworld.com>
2014-04-26 21:23                       ` More [[ $var ]] (Re: zsh-newuser-install) 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=140511111200.ZM20625@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).