caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* types of ocamlyacc's entry points
@ 2004-11-03 13:06 Virgile Prevosto
  0 siblings, 0 replies; only message in thread
From: Virgile Prevosto @ 2004-11-03 13:06 UTC (permalink / raw)
  To: Caml list

Hello list,

I just ran into a problem while trying to parameterize an
ocamlyacc-generated parser by a custom parsing function. The 
.mly file looked like:
-----------------------------
%token <string> SPECIAL
%start main
%type <(string -> 'a) -> 'a> main
%%
main:
SPECIAL { fun specialized_parser -> specialized_parser $1 }
%%
------------------------------
ocamlyacc complains: "e - the start symbol main has a polymorphic type".
It seems to me that this in contradiction with the manual, which says
that "The type part [of a %type directive] is an arbitrary Caml type
expression, except that all type constructor names must be fully
qualified". So, my first question is: Who is right, the documentation or
the implementation?
I suspect that this behavior is due to the bug #1583, which showed that
such types may lead to unsafe code, but I think that one or two line(s)
in the manual would be useful.

As a workaround, I've tried to wrap the parser in a functor (this was my
first intention in fact, as the custom parsing function should come
from a module):
-----------------------------
%{
module type Foo = sig type t val from_string: string -> t end
module ParseFormula = 
  functor (A: Foo) ->
    struct
%}
%token <string> SPECIAL
%start main
%type <A.t> main
%%
main:
SPECIAL { A.from_string $1 }
%%
end
------------------------------
While looking like an ugly hack, this seems to work, except that the
generated .mli file is not correct (see feature wish #1703 and not a bug
#1886). I can ask make to remove it, but is there a cleaner way to
proceed (apart from using camlp4 or Stream) ?

Many thanks in advance,
-- 
E tutto per oggi, a la prossima volta
Virgile


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-11-03 13:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-03 13:06 types of ocamlyacc's entry points Virgile Prevosto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).