caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: Hendrik Tews <tews@cs.ru.nl>
Cc: Liste de diffusion OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] camlp4: str_item quotations for normal syntax
Date: Tue, 01 Apr 2008 10:23:05 +0200	[thread overview]
Message-ID: <1207037563-sup-4923@ausone.inria.fr> (raw)
In-Reply-To: <18416.51871.133886.196204@tandem.cs.ru.nl>

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

Excerpts from Hendrik Tews's message of Mon Mar 31 13:27:27 +0200 2008:
> Hi,
> 
> I am trying to use (anti-) quotations for the normal ocaml syntax
> and run into the following problems:
> 
> 1. when pattern matching over str_item, what's the antiquotation
>    to use to get the list of all str_item's in a structure or in
>    a compilation unit?
> 
>    One can use Ast.list_of_str_item, for instance
> 
>     | <:str_item@loc< module $uid:mname$ = struct $items$ end >> -> 
>            .... (Ast.list_of_str_item items)
> 
>    but what's the antiquotation for directly getting the list?

One  no  longer  have  it. Indeed the representation is no longer a list but a
tree  using  binary  nodes  like  ';;'.  In  expression  one  can use the list
antiquotation  ($list:...$)  but that's a sugar for calling a function, such a
sugar is not really feasible in patterns.

>    I found str_items in Camlp4OCamlRevisedParser, and tried
> 
>     (match ast with
>        | <:str_items< $list:tops$ >> ->
>          Printf.printf "%s has %d top level decls\n"
>            (opt_string input_file) (List.length tops));
> 
>    but there is no quotation expander for str_items. 
> 
>    Further, str_items appears in module_expr but not in implem or
>    top_phrase. Why not?

Hum  no  need for str_item*s* since str_item do the job with it's ';;' (or ';'
in revised) binary node.

> 2. Ast.list_of_str_item is defined but never used, right? I am
>    guessing that there is a line missing in
>    Camlp4QuotationCommon.ml, similar to the one with
>    Ast.stSem_of_list. Right?

No because one cannot inject code in patterns.

> 3. The str_item quotations for the ocaml syntax seem to produce
>    always Ast.StSem(...,..., Ast.StNil...), for instance
> 
>     | <:str_item@loc< type $lid:name$ = $lid:oname$ >> ->
> 
>    gives
> 
>       | Ast.StSem (loc,
>           (Ast.StTyp (_,
>              (Ast.TyDcl (_, name, [], (Ast.TyId (_, (Ast.IdLid (_, oname)))),
>                 [])))),
>           (Ast.StNil _)) ->
> 
>    What do I have to write in order to get just 
> 
>       | Ast.StTyp (loc,
>           (Ast.TyDcl (_, name, [], (Ast.TyId (_, (Ast.IdLid (_, oname)))),
>              [])))
>           ->
> 
>    as I get with the revised qotations?

That's a bug due to an ambiguity in the original grammar since the ';;' is optional.

> 4. What is the quotation for _just_ getting Ast.StSem(_,_,_) for
>    instance for doing
> 
>    List.iter (function
>                | Ast.StSem(_,_,_) -> assert false
>                | .....
>       ) (Ast.list_of_str_item ....)

It  should  be  <:str_item<  $_$ ;; $_$ >>, but perhaps the bug above insert a
useless nil node :(

> 5. What is Register.OCamlPreCastPrinter good for?

Perhaps  not  that useful... It allows to register an existing printer that is
really  tied  to  the  PreCast  world,  it  doesn't  force you to provide some
abstract functor.

> 6. I would be interested in contributing for a version of
>    http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree
>    for ocaml syntax. 

Great!

>    Nicolas, Matthieu: What would you prefer as best structure? A
>    separate page with lots of duplication or one page for ocaml
>    and revised syntax, possibly differentiating things with
>    color? I tend to the latter.

The latter seems better.

-- 
Nicolas Pouillard aka Ertai

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

      reply	other threads:[~2008-04-01  8:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-31 11:27 Hendrik Tews
2008-04-01  8:23 ` Nicolas Pouillard [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=1207037563-sup-4923@ausone.inria.fr \
    --to=nicolas.pouillard@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=tews@cs.ru.nl \
    /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).