caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin_jambon@emailuser.net>
To: Markus Mottl <markus.mottl@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Camlp4: extending syntax of record definitions
Date: Tue, 19 Apr 2005 14:51:56 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.44.0504191423300.2885-100000@localhost> (raw)
In-Reply-To: <f8560b805041908135fe4c084@mail.gmail.com>

On Tue, 19 Apr 2005, Markus Mottl wrote:

> On 4/18/05, Martin Jambon <martin_jambon@emailuser.net> wrote:
> > My experience in that field tells me that the more you try to extend
> > existing syntaxic constructs, the more difficult it is.
> >
> > You have to look at pa_o.ml from the Camlp4 distribution first, and see if
> > the rule corresponding to record definitions is public (belongs to
> > a "GLOBAL" entry) or not.
>
> I had already copied half of the grammar to add my extension, but then
> I thought that this is insane. I couldn't believe that there is no
> simpler way of doing that, but obviously there really isn't.
>
> > If the entry that contains this rule is public, then you can delete the
> > rule and rewrite it, and everything is fine.
> > Otherwise, you have to improvise. Which is the case here: the type_kind
> > entry is not visible from outside.
>
> Right. I had to essentially copy everything from "type_declaration"
> downwards, which is quite a lot.

Besides from redistributing a modified pa_o.ml or a program that patches
pa_o.ml and makes every entry public, I don't see any solution.

There would probably be problems for syntax extensions that are supposed
to work for both the regular and the revised syntax (I don't use the
revised syntax myself so it's only a problem if I want to please the
users of the revised syntax...).

Also, the minor grammar entries in pa_o.ml happen to change from one
version of OCaml/Camlp4 to another, so it would be (even more) difficult
to maintain compatibility across various versions of OCaml if a syntax
extension had to rely on them.

I would love to know the point of view of the developers of Camlp4...

> > One reasonable solution, in general, if you have a limited time or budget,
> > is to extend str_item (items of a module implementation) with
> > a whole new syntax. Something like:
>
> I don't think that this is necessary, because it's only the type
> declaration I want to change, not the syntax for record expressions.
> The user must call the validation functions manually on his values.

I see.

> > You can look at this example (uncommented), which is very similar:
> >   http://martin.jambon.free.fr/extend-ocaml-syntax.html#types
>
> Thanks, that's a very nice tutorial on Camlp4. Maybe it could be added
> to the documentation index for OCaml at INRIA?

Thanks. I thought I should fill the gaps first (mainly English
sentences).

Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr



      reply	other threads:[~2005-04-19 21:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 19:07 Markus Mottl
2005-04-18 20:19 ` [Caml-list] " Martin Jambon
2005-04-19  7:25   ` too few public grammar entry points Stefano Zacchiroli
2005-04-19 15:16     ` [Caml-list] " Markus Mottl
2005-04-19 15:13   ` [Caml-list] Camlp4: extending syntax of record definitions Markus Mottl
2005-04-19 21:51     ` Martin Jambon [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=Pine.LNX.4.44.0504191423300.2885-100000@localhost \
    --to=martin_jambon@emailuser.net \
    --cc=caml-list@inria.fr \
    --cc=markus.mottl@gmail.com \
    /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).