caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] camlp4: generating keyword on the fly
@ 2002-01-13  1:28 Jeff Henrikson
  2002-01-13  1:41 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Henrikson @ 2002-01-13  1:28 UTC (permalink / raw)
  To: caml-list

I want to be able to cook up keywords on the fly using camlp4, and it seems like I should be able to do it.  But this is as far as
I get.  This function compiles:


let make_one_item_entry entrysym (keyword : string) =
  let tmp = (Grammar.Entry.create Pcaml.gram entrysym) in
  EXTEND
    tmp: [ [ "birthday" ] ]
    ;
  END;
  tmp;;

Grammar.Entry.print (make_one_item_entry "happy" "birthday");;

# [ LEFTA
  [ "birthday" ] ]
- : unit = ()


But this one does not:


let make_one_item_entry entrysym (keyword : string) =
  let tmp = (Grammar.Entry.create Pcaml.gram entrysym) in
  EXTEND
    tmp: [ [ keyword ] ]
    ;
  END;
  tmp;;

Grammar.Entry.print (make_one_item_entry "happy" "birthday");;


Note that this looks right but isn't:


let make_one_item_entry entrysym (keyword : string) =
  let tmp = (Grammar.Entry.create Pcaml.gram entrysym) in
  let tmp2 = (Grammar.Entry.create Pcaml.gram keyword) in
  EXTEND
    tmp: [ [ tmp2 ] ]
    ;
  END;
  tmp;;

Grammar.Entry.print (make_one_item_entry "happy" "birthday");;

# [ LEFTA
  [ birthday ] ]
- : unit = ()


(The quotes are missing)  I'm new at camlp4, so I don't know if my jargon for explaining this is right, but:

I can get an empty entry with Grammar.Entry.create, but the only way to extend it seems to be with EXTEND which so far as I can see
only takes string constants.  Does this make sense?


Jeff Henrikson


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] camlp4: generating keyword on the fly
  2002-01-13  1:28 [Caml-list] camlp4: generating keyword on the fly Jeff Henrikson
@ 2002-01-13  1:41 ` Daniel de Rauglaudre
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel de Rauglaudre @ 2002-01-13  1:41 UTC (permalink / raw)
  To: caml-list

Hi,

On Sat, Jan 12, 2002 at 08:28:49PM -0500, Jeff Henrikson wrote:

> I want to be able to cook up keywords on the fly using camlp4, and
> it seems like I should be able to do it.

I am not sure what "cook up" means in English, but if you want to give
a string variable as keyword, write it between dollars in the EXTEND
statement:

  let make_one_item_entry entrysym (keyword : string) =
    let tmp = (Grammar.Entry.create Pcaml.gram entrysym) in
    EXTEND
      tmp: [ [ $keyword$ ] ]
      ;
    END;
    tmp;;

  Grammar.Entry.print (make_one_item_entry "happy" "birthday");;

This is an undocumented feature.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2002-01-13  1:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-13  1:28 [Caml-list] camlp4: generating keyword on the fly Jeff Henrikson
2002-01-13  1:41 ` Daniel de Rauglaudre

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