Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: grammar triviality with '&&'
- X-seq: zsh-workers 34641
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh Hackers' List <zsh-workers@xxxxxxx>
- Subject: Re: grammar triviality with '&&'
- Date: Wed, 04 Mar 2015 15:18:30 +0000
- In-reply-to: <20150304144756.GA27231@ypig.lip.ens-lyon.fr>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <54F33934.2070607@eastlink.ca> <13666281425228233@web7o.yandex.ru> <54F345D3.9010204@eastlink.ca> <D0509295-7DA9-4F18-9E3D-D50C0A756998@larryv.me> <20150302022754.GA7449@xvii.vinc17.org> <CABx2=D8efL3X2tfB+_+VweY2yye6EhaMNbJa3b3jJeVMp=7gaQ@mail.gmail.com> <20150302104619.GC6869@xvii.vinc17.org> <20150302110610.2e2c7e86@pwslap01u.europe.root.pri> <CAH+w=7YoHjN85hqOZVywOfYGZqvU74vZrbE84Ln+V2HQi-6nSA@mail.gmail.com> <20150304144756.GA27231@ypig.lip.ens-lyon.fr>
On Wed, 4 Mar 2015 15:47:56 +0100
Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> I've found a bug:
>
> % alias '&&=(){ return $? } && '
> % && echo OK
> zsh: parse error near `&&'
(Moved to zsh-workers)
I was keeping very quiet about this, but it looks like it's not as hairy
as I thought it might be and the new code is actually slightly cleaner...
Now waiting for obscure failures elsewhere...
pws
diff --git a/Src/lex.c b/Src/lex.c
index 307b6e9..a076614 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1728,13 +1728,48 @@ gotword(void)
}
}
+/* Check if current lex text matches an alias: 1 if so, else 0 */
+
+static int
+checkalias(void)
+{
+ Alias an;
+
+ if (!noaliases && isset(ALIASESOPT) &&
+ (!isset(POSIXALIASES) ||
+ !reswdtab->getnode(reswdtab, zshlextext))) {
+ char *suf;
+
+ an = (Alias) aliastab->getnode(aliastab, zshlextext);
+ if (an && !an->inuse &&
+ ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) {
+ inpush(an->text, INP_ALIAS, an);
+ if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL))
+ aliasspaceflag = 1;
+ lexstop = 0;
+ return 1;
+ }
+ if ((suf = strrchr(zshlextext, '.')) && suf[1] &&
+ suf > zshlextext && suf[-1] != Meta &&
+ (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) &&
+ !an->inuse && incmdpos) {
+ inpush(dupstring(zshlextext), INP_ALIAS, NULL);
+ inpush(" ", INP_ALIAS, NULL);
+ inpush(an->text, INP_ALIAS, an);
+ lexstop = 0;
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/* expand aliases and reserved words */
/**/
int
exalias(void)
{
- Alias an;
Reswd rw;
hwend();
@@ -1746,7 +1781,7 @@ exalias(void)
if (!tokstr) {
zshlextext = tokstrings[tok];
- return 0;
+ return checkalias();
} else {
VARARR(char, copy, (strlen(tokstr) + 1));
@@ -1772,34 +1807,10 @@ exalias(void)
if (tok == STRING) {
/* Check for an alias */
- if (!noaliases && isset(ALIASESOPT) &&
- (!isset(POSIXALIASES) ||
- !reswdtab->getnode(reswdtab, zshlextext))) {
- char *suf;
-
- an = (Alias) aliastab->getnode(aliastab, zshlextext);
- if (an && !an->inuse &&
- ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) {
- inpush(an->text, INP_ALIAS, an);
- if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL))
- aliasspaceflag = 1;
- lexstop = 0;
- if (zshlextext == copy)
- zshlextext = tokstr;
- return 1;
- }
- if ((suf = strrchr(zshlextext, '.')) && suf[1] &&
- suf > zshlextext && suf[-1] != Meta &&
- (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) &&
- !an->inuse && incmdpos) {
- inpush(dupstring(zshlextext), INP_ALIAS, NULL);
- inpush(" ", INP_ALIAS, NULL);
- inpush(an->text, INP_ALIAS, an);
- lexstop = 0;
- if (zshlextext == copy)
- zshlextext = tokstr;
- return 1;
- }
+ if (checkalias()) {
+ if (zshlextext == copy)
+ zshlextext = tokstr;
+ return 1;
}
/* Then check for a reserved word */
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index 7121c50..36dfa24 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -42,3 +42,18 @@
cat <(echo foo | cat)
0:Alias expansion works at the end of parsed strings
>foo
+
+ alias '&&=(){ return $?; } && '
+ alias not_the_print_command=print
+ eval 'print This is output
+ && print And so is this
+ && { print And this too; false; }
+ && print But not this
+ && print Nor this
+ true
+ && not_the_print_command And aliases are expanded'
+0:We can now alias special tokens. Woo hoo.
+>This is output
+>And so is this
+>And this too
+>And aliases are expanded
Messages sorted by:
Reverse Date,
Date,
Thread,
Author