Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pietro Abate <Pietro.Abate@anu.edu.au>
To: ocaml ml <caml-list@inria.fr>
Subject: camlp4 help
Date: Fri, 15 Jul 2005 18:39:01 +1000	[thread overview]
Message-ID: <20050715083901.GA24763@pulp.anu.edu.au> (raw)

Hi all,
I'm having problems (once again) with camlp4...

I'd like to parse and produce a bit of ocaml code out of the
following description :

---------------------
CONNECTIVES
    "_&_",AssocLeft,And ;
    "_v_",AssocLeft,Or
END

TABLEAU

    RULE "And"
    { A & B }
    ----------
      A ; B
    END

END
---------------

The first time around I used quotes around the "{A & B}" and parsed the
expression with a adhoc parser outside camlp4 (and it's all good and
working).  Now I want to remove the quotes tut-cur and do everything
using the pre-processor (quotes make my code quote un-readable).  I've
started writing this code below, but I don't know how to proceed...

The main problem is of course that I've to parse an expression (in rule),
with a generic parser built on the top of the connectives that I've just
declared. Is there a way to tell campl4 : pass everything in between 
RULE and END to a function my_parser ?

I was looking for inspiration in M. Jambon excellent tutorial, but 
without much luck... 

thanks,
p

-----------------------(not tested)
let rule = Grammar.Entry.create Pcaml.gram "rule";;
let connective = Grammar.Entry.create Pcaml.gram "connective";;

type assoc = |AssocLeft |AssocRight |AssocNone ;;

let conntable = Hashtbl.create 15;;

EXTEND
  Pcaml.str_item: [
    "CONNECTIVES"; clist = LIST1 connective SEP ";"; "END" ->
      List.iter Hashtbl.add conntable clist;
      <:str_item< value version = "connectives declared" >>
    |"TABLEAU"; LIST1 rule; "END" ->
        <:str_item< value version = "tableau declared" >>
  ];

  connective: [
    s = STRING; ","; a = UIDENT; ","; r = UIDENT -> (s,a,r)
  ];

  (* how can I write a quotation outside the EXTEND syntax ? *)
  (* how does this quotation looks like ? *)
  (* Quotation.add my_parser ??? *)
  rule: [
    "RULE"; r = my_parser ??? "END" -> do_something r
  ];
  
END
------------------------

-- 
++ Blog: http://blog.rsise.anu.edu.au/?q=pietro
++ 
++ "All great truths begin as blasphemies." -George Bernard Shaw
++ Please avoid sending me Word or PowerPoint attachments.
   See http://www.fsf.org/philosophy/no-word-attachments.html


             reply	other threads:[~2005-07-15  8:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-15  8:39 Pietro Abate [this message]
2005-07-15 20:24 ` [Caml-list] " Martin Jambon
2005-07-18 10:12 ` Hendrik Tews
2005-07-19  5:23   ` Pietro Abate
2005-07-20  7:37     ` Hendrik Tews
2005-07-20  9:57       ` Gerd Stolpmann
2009-03-21  3:41 Camlp4 help Andre Nathan
2009-04-13  0:05 Andre Nathan

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=20050715083901.GA24763@pulp.anu.edu.au \
    --to=pietro.abate@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