While reading the menhir manual, I came across an example which uses semicolon in the argument of a parameterized non-terminal symbol application:
list ( e = expression; SEMICOLON { e } )
Notice the ;
character in the argument of the parameterized non-terminal list
.
According to the syntax of grammar specifications (figure 1), a semicolon is not allowed in production rules with the old syntax. It seems to be allowed only with the new syntax for rules.
I have tried something similar with menhir (version 20181113):
%token X COMMA
%start <unit> s
%%
s: list(X; COMMA) {}
It fails with the messages:
$ menhir test1.mly
File "test1.mly", line 7, characters 16-17:
Error: syntax error after 'COMMA' and before ')'.
Ill-formed production.
A production is a sequence of producers, followed with a semantic action.
Examples of well-formed producers:
expr
option(COMMA)
separated_list(COMMA, expr)
e = expr
ds = declaration*
es = list(terminated(expr, SEMI))
es = list(e = expr SEMI { e })
xs = list(x = var { Some x } | WILDCARD { None })
expr [@cost 0]
Is the example found in the menhir documentation really invalid?
Even when the semicolon is removed, the error persists.
How would it be fixed, so that one can use a sequence of producers as an argument of a parameterized non-terminal, with the old syntax?