caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Caml4p... help
Date: Wed, 9 Oct 2002 13:53:15 +0200	[thread overview]
Message-ID: <20021009135315.E1703@verdot.inria.fr> (raw)
In-Reply-To: <20021009015023.GA10937@zed>; from abate@discus.anu.edu.au on Wed, Oct 09, 2002 at 11:50:23AM +1000

Hi,

On Wed, Oct 09, 2002 at 11:50:23AM +1000, Pietro Abate wrote:

> 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 |] 

According to your 2nd message, you need a "let" at toplevel, not
a "let..in". In this case, it is not "expr" that you must extend
but "str_item": indeed, the "let" at toplevel is a structure item,
not an expression.

> ocamlc -c -pp "camlp4o pa_extend.cmo q_MLast.cmo" -I /usr/lib/ocaml/camlp4 str.ml
> File "str.ml", line 18, characters 2-10:
> This expression has type unit but is here used with type MLast.expr

Like Jeff Henrikson said, it is due to the extraneous "|" in the first
rule of "str": you must not put one. It is interpreted as an empty rule,
returning "()". I recognize that it is a pitfall of the syntax of EXTEND.

A remark: the definition of your type "kind" is unuseful in this file.
It will be useful only in the files using this syntax extension.

For the LINDENT, instead of LIDENT, this is not detected at compile
time, but when you use your syntax expander by "camlp4o ./str.cmo"
it displays:

   Lexer initialization error:
   - the constructor "LINDENT" is not recognized by Plexer
   Uncaught exception: Failure("Grammar.extend")

In Jeff's answer the #load "camlp4o.cma";; at the beginning of the file
is unuseful: Camlp4 knows that it is camlp4. On the other hand, the
other loads "q_MLast.cmo" and "pa_extend.cmo" are good and useful, since
they allow you to compile your file just with "-pp camlp4o".

Here is my version of your file (tested):

----------------------------------------
#load "pa_extend.cmo";;
#load "q_MLast.cmo";;

open Pcaml;;

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

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

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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


      parent reply	other threads:[~2002-10-09 11:53 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
2002-10-09  5:46   ` Pietro Abate
2002-10-09 11:53 ` Daniel de Rauglaudre [this message]

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=20021009135315.E1703@verdot.inria.fr \
    --to=daniel.de_rauglaudre@inria.fr \
    --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).