Harald van Dijk wrote, on 21 Feb 2021:
>
> On 19/02/2021 16:21, Geoff Clare via austin-group-l at The Open Group wrote:
> > It may be prudent to clarify matters by rearranging things in the
> > grammar so that it ends up saying "Do not apply rule 4" when a '('
> > has just been seen, like it does when a '|' has just been seen.
>
> That sounds good. I think that can be done by moving '(' and ')' from the
> case_item[_ns] rules into the pattern rule, as follows:
>
> case_item_ns : pattern linebreak
> | pattern compound_list
> ;
> case_item : pattern linebreak DSEMI linebreak
> | pattern compound_list DSEMI linebreak
> ;
> pattern : pattern_head ')'
> ;
> pattern_head : WORD /* Apply rule 4 */
> | '(' WORD /* Do not apply rule 4 */
> | pattern_head '|' WORD /* Do not apply rule 4 */
> ;
>
> It is a bit odd to have '(' and ')' part of the pattern rule like this,
> since they are not part of any pattern as far as the semantics of the case
> statement are concerned, but neither is '|' and that is already part of the
> pattern rule too.
I think your suggestion works, but having a separate production to
add the ')' seems unnecessary. I'd also rename "pattern" since it is
really just WORD that constitutes a pattern to be matched. So how
about this:
case_item_ns : pattern_list ')' linebreak
| pattern_list ')' compound_list
;
case_item : pattern_list ')' linebreak DSEMI linebreak
| pattern_list ')' compound_list DSEMI linebreak
;
pattern_list : WORD /* Apply rule 4 */
| '(' WORD /* Do not apply rule 4 */
| pattern_list '|' WORD /* Do not apply rule 4 */
;
--
Geoff Clare <[email protected]>
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England