From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Cross-module data in camlp4
Date: Mon, 28 Apr 2008 01:58:54 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.64.0804280141080.23932@martin.ec.wink.com> (raw)
In-Reply-To: <20080427225207.GA24916@annexia.org>
On Sun, 27 Apr 2008, Richard Jones wrote:
> I'm trying to add named patterns to my bitmatch syntax extension. The
> idea would be you could write (exact syntax isn't nailed down yet):
>
> let p = BITMATCH { a : 4; b : 4 } ;;
>
> bitmatch bs with
> | { p } -> (a, b)
>
> let f a b = BITSTRING p
>
> This is analogous to micmatch's Named regular expressions feature:
>
> http://martin.jambon.free.fr/micmatch-manual.html#htoc5
> eg:
> RE phone = digit{3} '-' digit{4}
>
> Reading the code to micmatch, these are implemented by saving the
> camlp4 AST into a Hashtbl, so the example above would create a hash
> entry ("phone" -> abstract syntax tree of (digit{3} '-' digit{4})).
> At the point of use of the named RE, the AST is substituted.
Yes. It's a global table that ignores everything about module boundaries.
> Of course micmatch's scheme only works if the named RE appears in the
> same compilation unit as the substitution. There is no way that I can
> see to save these named expressions across compilation units. In
> other words this is not allowed:
>
> --- my_regexps_lib.ml -----
> RE phone = digit{3} '-' digit{4}
>
> --- my_regexps_lib.mli -----
> val phone : Micmatch.regexp
>
> --- another file -----
> open My_regexps_lib
> (* ... and use 'phone' *)
>
> I think this limits the usefulness of named expressions, but at the
> same time I don't know how one would go about implementing
> cross-module named expressions. Is it even possible? Presumably if
> it could be done at all, we'd have to save the camlp4 AST
> representation into the output file (*.cmo). It would be easy enough
> to marshal the AST into a string at the point of definition. I don't
> quite see how it can be accessed & unmarshalled at the point of use
> however.
>
> Any insights here gratefully accepted!
I had some ideas on the subject:
http://caml.inria.fr/pub/ml-archives/caml-list/2007/01/6f2e2f9db39543e92806742ddc10fa5f.en.html
Nothing clear comes out of this...
Martin
--
http://wink.com/profile/mjambon
http://mjambon.com
prev parent reply other threads:[~2008-04-28 0:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-27 22:52 Richard Jones
2008-04-27 23:58 ` 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.64.0804280141080.23932@martin.ec.wink.com \
--to=martin.jambon@ens-lyon.org \
--cc=caml-list@inria.fr \
--cc=rich@annexia.org \
/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