caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 module dependencies
@ 2008-09-21 18:05 Harrison, John R
  2008-10-09 18:36 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 2+ messages in thread
From: Harrison, John R @ 2008-09-21 18:05 UTC (permalink / raw)
  To: OCaml; +Cc: Harrison, John R

I'm trying once again to make some code work under the new camlp4. I
don't want to make any real syntax modifications, but just enable
quotations performing a simple string transformation on the body of
the quotation, e.g. turning

 <<hello /\ world>>

into

 default_parser "hello /\\ world"

About a year ago, Nicolas Pouillard gave me a recipe, which I've now
put in the following form for my actual requirements:

  open Camlp4.PreCast;;

  module Caml =
    Camlp4OCamlParser.Make
      (Camlp4OCamlRevisedParser.Make
        (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;

  let quotexpander s =
    if String.sub s 0 1 = "|" & String.sub s (String.length s - 1) 1 = "|" then
      "secondary_parser \""^
      (String.escaped (String.sub s 1 (String.length s - 2)))^"\""
    else "default_parser \""^(String.escaped s)^"\"";;

  let patt_quotexpander loc _loc_name_opt str =
    Gram.parse_string Caml.patt loc (quotexpander str);;

  let expr_quotexpander loc _loc_name_opt str =
    Gram.parse_string Caml.expr loc (quotexpander str);;

  let str_item_quotexpander loc loc_name_opt str =
    <:str_item@loc< $exp: expr_quotexpander loc loc_name_opt str$ >>;;

  let () =
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.expr_tag expr_quotexpander;
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.str_item_tag
  str_item_quotexpander;
    Syntax.Quotation.add "" Syntax.Quotation.DynAst.patt_tag patt_quotexpander;;

I can directly compile this file (say "Quotexpander.ml") with

  ocamlc -pp camlp4of -I +camlp4 -I +camlp4/Camlp4Parsers -a -o Quotexpander.cma Quotexpander.ml

and then use it inside the toplevel without problems:

  /home/johnh/temp/OCaml$ ocaml
          Objective Caml version 3.10.0

  # #load "camlp4o.cma";;
          Camlp4 Parsing version 3.10.0

  # #load "Quotexpander.cma";;
  # let default_parser s = s;;
  val default_parser : 'a -> 'a = <fun>
  # <<hello /\ world>>;;
  - : string = "hello /\\ world"

However, to keep the build process as trivial as possible, I'd like
simply to copy the ML code directly into the toplevel (i.e. #use
"Quotexpander.ml"). Doing this seems to hit some module dependencies,
e.g.

  $ ocaml
          Objective Caml version 3.10.0

  #  #load "camlp4o.cma";;
          Camlp4 Parsing version 3.10.0

  #   open Camlp4.PreCast;;
  # module Caml =
        Camlp4OCamlParser.Make
          (Camlp4OCamlRevisedParser.Make
            (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;
  Unbound module Camlp4OCamlParser.Make
  ...

Can anyone tell me what else I should be loading/opening?

John.


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

* Re: [Caml-list] camlp4 module dependencies
  2008-09-21 18:05 camlp4 module dependencies Harrison, John R
@ 2008-10-09 18:36 ` Nicolas Pouillard
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2008-10-09 18:36 UTC (permalink / raw)
  To: John Harrison; +Cc: Caml_mailing list

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

Excerpts from John Harrison's message of Sun Sep 21 20:05:36 +0200 2008:
> I'm trying once again to make some code work under the new camlp4. I
> don't want to make any real syntax modifications, but just enable
> quotations performing a simple string transformation on the body of
> the quotation, e.g. turning
> 

[...]

> Can anyone tell me what else I should be loading/opening?

You have to add the include directories:

$ ocaml camlp4of.cma -I +camlp4 -I +camlp4/Camlp4Parsers

Regards,

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

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

end of thread, other threads:[~2008-10-09 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-21 18:05 camlp4 module dependencies Harrison, John R
2008-10-09 18:36 ` [Caml-list] " Nicolas Pouillard

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