Various changes to Cmly / MenhirSdk
This PR tries to solve shortcomings of MenhirSdk:
-
Cmly can only be loaded from disk: there is no separation between un-marshalling the raw representation and the construction of the module that exposes a convenient interface to manipulate the grammar. Sometimes it is convenient to embed a grammar value (this is the case of LRgrep interpreter for OCaml grammar).
-
Lr1.reductions
has typeLr1.t -> (Terminal.t * Production.t list) list
, even though the production list is always a singleton.Lr1.t -> (Terminal.t * Production.t) list
.
The list was originally intended as a way to expose the raw list of productions before conflict resolution.
However it always represented the reductions after conflict resolution, therefore there is only a single possible reduction per terminal.
If it is indeed useful, the conflict information should be exposed separately.
This change might be controversial though: it is only brings a minor convenience and it breaks programs that were using the previous API. -
Expose
Lr1.default_reduction : Lr1.t -> production option
. I used to think that whether the default_reduction optimizations triggered could be directly deduced from the list of transitions and reductions. However this is not the case because of %nonassoc: the conflict resolution might have removed some transitions that would erroneously cause a default_reduction to apply. Menhir handles that correctly, but the information is lost in the cmly.