Browse thread
Camlp4: extending syntax of record definitions
-
Markus Mottl
-
Martin Jambon
- Stefano Zacchiroli
- Markus Mottl
-
Martin Jambon
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Markus Mottl <markus.mottl@g...> |
| Subject: | Re: [Caml-list] Camlp4: extending syntax of record definitions |
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. > 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. > 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? Best regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com