caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: jehenrik <jehenrik@yahoo.com>
To: Pietro Abate <abate@discus.anu.edu.au>
Cc: <caml-list@inria.fr>
Subject: Re: [Caml-list] Caml4p... help
Date: Tue, 8 Oct 2002 23:35:08 -0400	[thread overview]
Message-ID: <1BC7BF40-DB38-11D6-8FB2-00039375801A@yahoo.com> (raw)
In-Reply-To: <20021009015023.GA10937@zed>

> I've just started playing with Caml4p today and I'm already at a dead
> end. My goal is to transform this syntax
>
> str pc : [a;b;c]
>
> into a declaration like that.
> let pc_str = `Forall [| `Rule a; `Rule b; `Rule c |]

Your implementation is basically right, but it has a couple of small 
errors.  Superficially, LINDENT should be LIDENT.  Change both of 
those.  You have an extraneous "|" symbol after str: [[.  Fix that.  The 
harder to see mistake is that you accidentally name your entry "str" 
while simultaneously redefining it to be a keyword.  This is bad.  So 
change the name of your entry, for example.  Say "strentry" instead of 
str.  Then it works: (this has some modifications to run in the toplevel)

#load "camlp4o.cma";;
#load "q_MLast.cmo";;
#load "pa_extend.cmo";;

open Pcaml;;

type kind = [
   | `Rule of string
   | `First of kind array
   | `Forall of kind array
] ;;

let strentry = Grammar.Entry.create gram "str" ;;

EXTEND
   expr: AFTER "top"
     [[ "str"; n = LIDENT; ":"; s = strentry ->
         <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]];

   strentry: [[
      n = LIDENT -> <:expr<`Rule $str:n$>>
   |  "["; s = LIST1 strentry SEP ";"; "]" -> <:expr<`Forall 
[|$list:s$|] >>
   |  "{"; s = LIST1 strentry SEP ";"; "}" -> <:expr<`First 
[|$list:s$|] >> ]];

END;;

str pc : [a;b;c];;

# - : _[> `Forall of _[> `Rule of string] array] =
`Forall [|`Rule "a"; `Rule "b"; `Rule "c"|]



Good luck with your project and welcome to the world of camlp4!


Jeff Henrikson




On Tuesday, October 8, 2002, at 09:50 PM, Pietro Abate wrote:

> (*pp camlp4o pa_extend.cmo q_MLast.cmo *)
> open Pcaml;;
>
> type kind = [
>     |`Rule of string
>     |`First of kind array
>     |`Forall of kind array
> ]
>
> let str = Grammar.Entry.create gram "str";;
>
> EXTEND
>   expr: AFTER "top"
>     [[ "str"; n = LINDENT; ":"; s = str ->
>         <:expr< let $lid:n$ = $s$ in $lid:n$ >> ]];
>
>   str: [[
>     | n = LINDENT -> <:expr<`Rule $str:n$>>
>     | "["; s = LIST1 str SEP ";"; "]" -> <:expr<`Forall [|$list:s$|] >>
>     | "{"; s = LIST1 str SEP ";"; "}" -> <:expr<`First 
> [|$list:s$|] >> ]];
>
> END;;

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-10-09  3:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-09  1:50 Pietro Abate
2002-10-09  3:35 ` jehenrik [this message]
2002-10-09  5:46   ` Pietro Abate
2002-10-09 11:53 ` Daniel de Rauglaudre

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=1BC7BF40-DB38-11D6-8FB2-00039375801A@yahoo.com \
    --to=jehenrik@yahoo.com \
    --cc=abate@discus.anu.edu.au \
    --cc=caml-list@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).