Introduce %iboption in the standard library, an inline version of boption.
In one of my projects, using boption
gives me a shift/reduce conflict which is resolved by inlining this definition. Maybe this could be part of standard.mly, similarly to option
and ioption
.
(* [iboption(X)] is identical to [boption(X)], except its definition is
inlined. This has the effect of duplicating the production that
refers to it, possibly eliminating an LR(1) conflict. *)
%public %inline iboption(X):
/* nothing */
{ false }
| X
{ true }
I haven't come across any conflict with loption
yet, but for the sake of uniformity, we could imagine an iloption
version.
By the way, to slightly reduce code duplication between inline and non-inline version of these definitions, I suppose we can use the following pattern:
(* [option(X)] recognizes either nothing or [X]. It produces a value
of type ['a option] if [X] produces a value of type ['a]. *)
%public option(X):
| x = ioption(X) { x }
(* [ioption(X)] is identical to [option(X)], except its definition is
inlined. This has the effect of duplicating the production that
refers to it, possibly eliminating an LR(1) conflict. *)
%public %inline ioption(X):
/* nothing */
{ None }
| x = X
{ Some x }