caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Additional exports from ocamlyacc-generated module?
@ 2008-04-22 13:56 Richard Cobbe
  2008-04-22 14:03 ` [Caml-list] " Mathias Kende
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Cobbe @ 2008-04-22 13:56 UTC (permalink / raw)
  To: caml-list

Is it possible to mark definitions in an .mly file as "public," so that
they're listed in the generated .mli file?

My parser.mly file has some nontrivial function definitions in its header.
While these functions are used only by the parser, I'd like to write some
unit tests for them.  I've defined the test suite in parser.mly's trailer
(after the final %%), but the generated parser.mli file includes only the
token definition and the functions corresponding to my grammar's start
symbols.  Since nobody else can see the test suite, I can't actually run
these tests from outside the module.

The ocamlyacc manual doesn't describe any way to accomplish this, either
with annotations in parser.mly or with command-line args to ocamlyacc.
I've thought of various possible work-arounds, none of which are all that
pleasant:

  - parser.mly's trailer defines the test cases and then runs them itself.
    Not good; this will run the tests every time I load the module.

  - Have the Makefile append
        val tests : OUnit.test
    to the end of parser.mli after calling ocamlyacc.

  - Move the functions out of parser.mly's header into a separate module,
    and put the tests cases for those functions there.  This is probably
    the cleanest solution, but I don't like making these functions visible
    to the rest of the program.

Is there a better way to do this?

If it matters, I'm using OCaml 3.10.2, packaged by Fink; Mac OS 10.5.2
Intel.  I'm using the OUnit test framework, but in the unlikely event that
a different testing framework doesn't suffer from these problems, I'm open
to alternatives.

Thanks,

Richard


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Additional exports from ocamlyacc-generated module?
  2008-04-22 13:56 Additional exports from ocamlyacc-generated module? Richard Cobbe
@ 2008-04-22 14:03 ` Mathias Kende
  0 siblings, 0 replies; 2+ messages in thread
From: Mathias Kende @ 2008-04-22 14:03 UTC (permalink / raw)
  To: Richard Cobbe; +Cc: caml-list


Richard Cobbe a écrit :
> Is it possible to mark definitions in an .mly file as "public," so that
> they're listed in the generated .mli file?

I usually have a rule in my makefiles that destroys the .mli files created by ocamlyacc 
and creates a new one with "ocamlc -i" which include the function definition of the header 
(and then there is an automatic filtering to expose only some functions).
But there is no way to instruct ocamlyacc to do so to my knowledge, because it is a C 
program which does not understand the Caml part of the header.

Mathias


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-04-22 14:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-22 13:56 Additional exports from ocamlyacc-generated module? Richard Cobbe
2008-04-22 14:03 ` [Caml-list] " Mathias Kende

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).