Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: parsing empty alternatives: case foo|) :;;



On Mon, Aug 7, 2017 at 7:26 AM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Mon, 7 Aug 2017 13:55:59 +0000
> Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>> % case '' in (foo|) echo yes;; esac
>> yes
>> % case '' in foo|) echo yes;; esac
>> zsh: parse error near `)'
>>
>> Why does the second case fail to parse?  We (IRC) don't see any ambiguity
>> in it.
>
> I haven't checked, but I think it looks like a pipe --- at that point we
> haven't gone further down the case-specific code so that it parses the
> line specially.

Several things are going on here.
(1) The "case" syntax with no open paren and only a close paren is
from older Bourne shell
(2) The use of "|" to separate alternatives in a pattern is
zsh-specific globbing syntax, which is only active when parsing
patterns that contain a parenthesized grouping
(3) Because of both of the foregoing, when parsing the pattern in the
older syntax, recognition of "|' as a separator is not enabled -- it's
read as a simple pattern with no grouping
(4) When the newer "case" syntax with a fully parenthesized pattern
was added, the presence of the open paren gave us the parsing hook
needed to activate the grouping syntax

To put it another way, "in foo|)" is rejected for the same reason that
"in |foo)" is.



Messages sorted by: Reverse Date, Date, Thread, Author