caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Cobbe <cobbe@ccs.neu.edu>
To: caml-list@yquem.inria.fr
Subject: Additional exports from ocamlyacc-generated module?
Date: Tue, 22 Apr 2008 09:56:12 -0400	[thread overview]
Message-ID: <20080422135612.GC405@perdita.local> (raw)

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


             reply	other threads:[~2008-04-22 13:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-22 13:56 Richard Cobbe [this message]
2008-04-22 14:03 ` [Caml-list] " Mathias Kende

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080422135612.GC405@perdita.local \
    --to=cobbe@ccs.neu.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).