[Omake] omake support for Menhir?

Jason Hickey jyh at cs.caltech.edu
Tue Jun 13 18:07:34 PDT 2006


Francois Pottier wrote:
> but I wonder: might it not
> be more productive to add support for Menhir directly to omake's standard rule
> library? Is this something that the omake team would be interested in? If so,
> I could help by providing more details about Menhir's operation.

I've added support for Menhir on the omake 0.9.8.ocamldep branch.  Once 
we are satisfied that the configuration is stable, we'll move it to the 
trunk.

To use it, you add this line to your OMakefile, the rest is automatic.

    MENHIR_ENABLED = true

    # Also define extra Menhir options if you like
    MENHIR_FLAGS += ...

This relies on computing accurate dependencies, using the ocamldep 
method Aleksey suggested.  The nice thing is that it all works 
transparently, you can have a.mly depend on b.mly which depends on 
c.mly, etc. and scanning is done correctly.  The unfortunate thing is 
that it relies on a custom ocamldep.

Some questions.

It seems that menhir looks at the output of ocamldep (I assume to fix it).
    - When I use --ocamldep "ocamldep -I ../foo" I get this error.
      Error: failed to make sense of ocamldep's output.

      Is it legal to depend on files in other directories?

    - With the new dependency model, ocamldep -modules does not print
      make-style output.  For accuracy, it would be nice to use
      the new ocamldep with Menhir, but this will cause an error.

      Would it be reasonable to have something like --rawocamldep,
      so that Menhir prints the output from ocamldep verbatim?

-------

For clarity, I'm also attaching the relevant section from OCaml.om

#
# You can choose to use ocamlyacc or menhir for a parser
# generator.  The default is ocamlyacc.  Define the
# MENHIR_ENABLED as true if you would rather use menhir.
#
MENHIR = menhir
MENHIR_FLAGS =
MENHIR_ENABLED = false
static. =
     MENHIR_AVAILABLE = $(CheckProg $(MENHIR))

# Compute the correct ocamlc and ocamldep options for Menhir.
MenhirCommandOptions() =
     if $(not $(MENHIR_AVAILABLE))
        eprintln($"""!!! You are asking to use Menhir, but it is not 
installed.""")
        eprintln($"""!!! See the Menhir home page for instructions on 
downloading""")
        eprintln($"""!!!    http://cristal.inria.fr/~fpottier/menhir/""")
        exit(1)
     ocamlc[] =\
        $(OCAMLFIND) $(OCAMLC) $(LAZY_OCAMLFINDFLAGS) 
$(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS)\
        $(OCAMLCFLAGS) $(OCAMLPPFLAGS) $(PREFIXED_OCAMLINCLUDES)
     ocamldep[] = ocamldep $(PREFIXED_OCAMLINCLUDES)
     value --ocamlc $"$(ocamlc)" --ocamldep $"$(ocamldep)"

# Compute the Mendir dependency scanner command
MenhirScannerCommand(src) =
     if $(MENHIR_ENABLED)
         value $(MENHIR) $(MENHIR_FLAGS) $(MenhirCommandOptions) 
--depend $(src)

# Use Menhir if MENHIR_ENABLED, ocamlyacc otherwise
OCamlYaccCommand(src) =
     if $(MENHIR_ENABLED)
         value $(MENHIR) $(MENHIR_FLAGS) $(MenhirCommandOptions) $(src)
     else
         value $(OCAMLYACC) $(OCAMLYACCFLAGS) $(src)

.SCANNER: scan-menhir-%.mly: %.mly
     $(MenhirScannerCommand $<)

%.ml %.mli: %.mly :scanner: scan-menhir-%.mly
     $(OCamlYaccCommand $<)

Jason

-- 
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257


More information about the Omake mailing list