Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: grammar triviality with '&&'
- X-seq: zsh-users 19936
- From: ZyX <kp-pav@xxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>, zsh Users <zsh-users@xxxxxxx>
- Subject: Re: grammar triviality with '&&'
- Date: Sun, 01 Mar 2015 19:43:53 +0300
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1425228234; bh=NTIjNWO3ZKhqFQUswF0/N2Rwht9otOhmJi2Y71pQyfE=; h=From:To:In-Reply-To:References:Subject:Date; b=XtFs1NLF1slPWWjhdENl62T0xJt+oqug1XfBlJvHYhZDet6lrJ8uiwf63xFo8dN/e 8XCM0Lc+9sz8zjkiwLPTK1qccMyaZ8rPZO/ULRM4TBa0GT89a8leLIadxg6+Qi4j+9 68yyXRHyLqQb6gIo13U0B00vDacBv9A5wPzCZpn0=
- In-reply-to: <54F33934.2070607@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <54F33934.2070607@eastlink.ca>
01.03.2015, 19:09, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> I notice that zsh is quite tolerant as far as most
> line wrap situations go, except for this:
>
> [ -e file1 ] &&
> [ -e file2 ] &&
> echo 'both files exist'
>
> ... good
>
> [ -e file1 ]
> && [ -e file2 ]
> && echo 'both files exist'
>
> ... syntax error, but we can fix it like this:
>
> [ -e file1 ]\
> && [ -e file2 ]\
> && echo 'both files exist'
>
> I'm wondering why the line continuation is strictly necessary.
> IOW, why doesn't the parser permit the '&&' on a new line?
> I've been trying to come up with something that would
> cause an ambiguity if it were permitted, but can't find anything,
> but I doubt the rule would be there otherwise.
Each of the lines is a sequence of `zle self-insert` followed by `zle accept-line`. In first and third cases it is possible to, based on parser state, determine that more input is required. In the second it is a complete command on the first line.
Note that zsh is a shell. Its main purpose is parsing user input, *not* scripts. What you ask will require special-casing script parsing (note: things like aliases or BANGHIST are processed prior to the time string is feed to the parser).
Note 2:
( echo "echo foo" ; sleep 5 ; echo "echo bar" ; sleep 5 ; echo "echo baz" ) | zsh -
outputs foo, bar, baz with 5 second intervals in between. Waiting for EOF or next line would not be very logical here, especially since shells may be and sometimes are used in non-interactive mode by the user and not by the script piping to stdin, and this is what special-casing is against (user input is already very special due to zle).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author