On 19/02/2021 17:56, Robert Elz wrote:
     Date:        Fri, 19 Feb 2021 15:11:58 +0000
     From:        "Harald van Dijk via austin-group-l at The Open Group" 
<austin-group-l@opengroup.org>
     Message-ID:  <4b4f2cbf-2a2e-f0bf-34ca-a7357f99c...@gigawatt.nl>

   | Observe that rule 4 is applied for the first word in a pattern even if
   | that pattern follows an opening parenthesis.

Yes.

   | Because of that, in my
   | example, the esac in parentheses is interpreted as the esac keyword
   | token, not a regular WORD token that makes for a valid pattern.

Yes.

   | Your change would make it so that since the esac keyword is not
   | acceptable at that point in the grammar,

Is it not?   Why not?

The statement "case foo in (esac" is valid according to the grammar,
just as "case foo in esac" is.

The grammar only allows the '(' in a case_item or case_item_ns. In your example, you don't have one and there is no other relevant part of the grammar that allows '(' to appear.

When the '(' was added, it was added (in shells) as a throw away token,
which changes nothing about the parse state, and is permitted merely to
match the ')' required after the pattern (both for user style reasons,
and to handle this common usage of a lone ')' for shells that used
parentheses counting to find the end of a $() cmdsub ... the latter doesn't
work anyway, and is largely gone everywhere now, but the optional (and
supposedly meaningless) '(' remains.

That is neither what the standard says nor what shells do, though.

  case x in ( (x) echo match ;; esac

is rejected because that first '(' does change the parse state, making the second '(' invalid.

(I inserted a space to account for shells that treat '((' as a special token.)

The issue here is that you seem to be expecting the shell to convert
"esac" to Esac only when the complete statement would then be valid.

No, that's not neither what I'm expecting nor what I believe POSIX says. I agree that that would be absurd.

What I believe POSIX currently specifies is that "esac" is treated as an Esac token even when it follows '(', resulting in a syntax error.

What I believe shells should do is what Geoff believes POSIX already requires, which is treat "esac" as a WORD token when it follows "(".

Even if my interpretation of the spec is correct and this is currently a syntax error, shells are already permitted to do the right thing, and many do.

Cheers,
Harald van Dijk

Reply via email to