caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] camlp4: a silly question about quoting Ocaml terms
@ 2013-11-02 19:57 Matej Kosik
  2013-11-02 21:27 ` Jeremy Yallop
  0 siblings, 1 reply; 2+ messages in thread
From: Matej Kosik @ 2013-11-02 19:57 UTC (permalink / raw)
  To: Caml

Hello,

According to various sources, Ocaml provides convenient means for generating Ocaml AST.
Yesterday I decided to look into the matter.

Now I am trying to generate a record type.

To certain point, things make sense. This:

  <:ctyp<{foo1:bar1; foo2:bar2}>>

is expanded to

    Ast.TyRec (_loc,
      (Ast.TySem (_loc,
         (Ast.TyCol (_loc,
                     (Ast.TyId (_loc, (Ast.IdLid (_loc, "foo1")))),
                     (Ast.TyId (_loc, (Ast.IdLid (_loc, "bar1")))))),
         (Ast.TyCol (_loc,
                     (Ast.TyId (_loc, (Ast.IdLid (_loc, "foo2")))),
                     (Ast.TyId (_loc, (Ast.IdLid (_loc, "bar2")))))))))

By looking at:

  http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree#Types

there is a line:

     <:ctyp< t : t >>	....... Field declaration ........ TyCol of Loc.t and ctyp and ctyp

so it seems that it should also be somehow posible to get a quote for "field declaration", i.e.:

  <:ctyp<foo1:bar1>>

However, if I try that, I get an error:

  While expanding quotation "ctyp" in a position of "expr":
    Parse error: "->" expected after [ctyp level star] (in [ctyp]

I do not quite understand why that quotation was rejected by camlp4.

Of course, it is perfectly possible to write:

  Ast.TyCol (_loc,
             (Ast.TyId (_loc, (Ast.IdLid (_loc, field_name)))),
             field_type

but I am wondering whether there is a more intelligent way to do that
(e.g. <:ctyp<foo1:bar1>> or something like that).

---

As always, thank you in advance for your kind help.

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

* Re: [Caml-list] camlp4: a silly question about quoting Ocaml terms
  2013-11-02 19:57 [Caml-list] camlp4: a silly question about quoting Ocaml terms Matej Kosik
@ 2013-11-02 21:27 ` Jeremy Yallop
  0 siblings, 0 replies; 2+ messages in thread
From: Jeremy Yallop @ 2013-11-02 21:27 UTC (permalink / raw)
  To: Matej Kosik; +Cc: Caml

On 2 November 2013 19:57, Matej Kosik
<5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> By looking at:
>
>   http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree#Types
>
> there is a line:
>
>      <:ctyp< t : t >>   ....... Field declaration ........ TyCol of Loc.t and ctyp and ctyp
>
> so it seems that it should also be somehow posible to get a quote for "field declaration", i.e.:
>
>   <:ctyp<foo1:bar1>>

Yes.

> However, if I try that, I get an error:
>
>   While expanding quotation "ctyp" in a position of "expr":
>     Parse error: "->" expected after [ctyp level star] (in [ctyp]
>
> I do not quite understand why that quotation was rejected by camlp4.

I think it's a bug in camlp4, which appears to be parsing "foo1:bar1"
as part of a function type with a labelled argument (such as
"foo1:bar1 -> int").  It'd be worth submitting a report on Mantis
(http://caml.inria.fr/mantis) about the problem.  In the meantime you
can work around the issue either by writing the AST by hand or by
switching to the revised syntax, which doesn't have this ambiguity.

Jeremy.

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

end of thread, other threads:[~2013-11-02 21:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-02 19:57 [Caml-list] camlp4: a silly question about quoting Ocaml terms Matej Kosik
2013-11-02 21:27 ` Jeremy Yallop

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