Zsh Mailing List Archive
Messages sorted by:
Re: grammar triviality with '&&'
On 03/06/2015 09:43 AM, Bart Schaefer wrote:
} I don't think that the grammar would become more complex.
What you're both missing or at least glossing over is the interaction
between the grammar and the interactive interpreter.
There goals are: (1) the grammar for scripts is identical to the grammer
for interactive use, (2) the execution order is identical both in scripts
and in interactive use, and (3) when used interactively, the input can be
interpreted [commands executed] as soon as a complete syntactic structure
has been recognized.
Under the current grammar, the interpreter always "knows," at the point
where a line break occurs, whether or not it has a complete syntactic
element that it can execute. If you allow the and_or producion to put
a linebreak before AND_IF / OR_IF, then until it encounters an explicit
";" or "&" (or some other lookahead token that can't appar at that
position in the pipeline production) the interpreter doesn't "know"
whether it has actually reached the end of the "and_or" production.
Therefore it would either violate (2) to speculatively execute what has
been seen so far, or it would violate (3) to wait for the next token to
complete the lookahead. Sure, we could either discard goal (1) to
make this an interactively-only feature [there's at least precedent for
that with setopts], or we can discard goal (2); we can do whatever
we want. I assume you'd find it way too annoying to discard (3).
Don't blame me! I'm just riding along with Vincent's logic, he can
argue this with
real knowledge, I'm just seeing what's at the bottom of this.
When I type at the prompt, it clearly knows when I'm not
finished, but If I type ' [ -e file1 ] ENTER', it goes to the next
prompt, because it has no
way of knowing that I intended to add an '&&' after it on the next
line. Quite so.
But surely that's not the issue. The issue is whether
can know to implicity grab the already existing return value from the
whatever it may have been. Yup, the previous line is executed and
finished and gone,
but it has set the errorlevel, and that does persist, so it is
legitimately there. Why
can't it be used? I see it as violating none of your three rules. It
would be the same
interactively or in scripts, and it would execute at syntactic
completion. All that would
change is that an obviously incomplete AND_IF would default to grabbing
return value (which is still there). Anyway, the parser would be making a
concession, and why should it? No really good reason. I'm satisfied,
concessions are made routinely elsewhere. Nope, it ain't broken, don't
But this is in a sense analogous to suggesting that
one | two | three
could wait to see what happens to "one" before deciding whether to send
the output along to "two".
Yes. Exactly. The question was why that's not permitted, but I think I
just so that you can decide later whether you're interested in adding
yet another stage to the pipeline. Or at least I hope you would not
suggest that, though if you look through the list archives people have
in fact asked how to capture output so they can re-use it later. See
Functions/Misc/keeper for an example.
Nope. I don't want to break things more broken than they already are.
Amen! It was quite innocent at the time ;-) But it has been deeply
In any case, I'm done trying to explain this. We've already put the lie
to the word "triviality" in the subject of this thread.
Messages sorted by: