caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Wojciech Meyer <wojciech.meyer@googlemail.com>
Cc: bob zhang <bobzhang1988@gmail.com>,
	Alain Frisch <alain@frisch.fr>,
	 caml-list@inria.fr
Subject: Re: [Caml-list] Re: Syntax extensions without Camlp4
Date: Thu, 31 May 2012 20:32:44 +0200	[thread overview]
Message-ID: <1338489164.17140.135.camel@thinkpad> (raw)
In-Reply-To: <wfobp41b4s.fsf@gmail.com>

Am Donnerstag, den 31.05.2012, 19:03 +0100 schrieb Wojciech Meyer:
> Gerd Stolpmann <info@gerd-stolpmann.de> writes:
> 
> > Am Donnerstag, den 31.05.2012, 12:01 -0400 schrieb bob zhang:
> > I guess you are missing Alain's point here. He suggests to use normal
> > pattern matching directly on parsetrees, as in
> >
> > match expr with
> >  | Pexp_ident id -> Pexp_ident (tranform id)
> >  | Pexp_contant c -> Pexp_constant c
> >  | ...
> >
> > instead of using camlp4 syntax quotations (no <<...>> stuff for syntax
> > manipulation anymore).
> 
> I admit quotations are *way* better to construct the code, they are
> syntax aware but also reassemble string manipulation at the same
> time. If somebody has generated some more serious program using
> quotations then she can't stand using normal way by constructing via the
> data constructors. I can compare, because I have used both ways for the
> same project. Of course normal ASTs have it's wide applications, what is
> shown above is a transform, and not strictly a code generation - usually
> I have intermediate AST on the left hand side pattern match and on the
> right hand side quotations. So I can't say quotations are not useful,
> they are quite much. If the quotations could be as lightweight as
> brackets-escape notations of MetaOCaml it would be brilliant. (I'm
> really talking about code generation - and not extending the syntax).
> 
> Please see [1].
> 
> I'd support the idea of having quotations for the parse trees.

I'm wondering whether you could run the normal ocaml parser in a special
mode for constructing code. In this mode, all non-keyword identifiers
(and possibly other placeholders) can also be given in antiquotation
form $name$, and the values for such injected names are taken from a
table you have to supply when calling the parser in this mode. This
would then look like

let antiquot_map =
  StrMap.add "var" "x" StrMap.empty

let ast =
  parse_struct_item antiquot_map "let $var$ = x+1"

And, given quotations are available in a renovated parser, one could
even write <:struct_item< let $var$ = x+1 >>, which already looks very
camlp4-ish (but would not use camlp4 at all), and would just be a thin
layer on top of the standard parser.

I mean the whole point is that we can do a lot without camlp4 by just
pimping the normal parser a bit. Actually, we need camlp4 only for
extensible grammars and the revised syntax, and Alain is probably right
that this is not worth the effort.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------


  reply	other threads:[~2012-05-31 18:32 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-27 15:06 [Caml-list] " Alexandre Pilkiewicz
2012-05-27 16:53 ` [Caml-list] " Hongbo Zhang
2012-05-27 18:04   ` Daniel Bünzli
2012-05-27 18:18     ` Hongbo Zhang
2012-05-27 19:01       ` Daniel Bünzli
2012-05-27 22:43         ` Wojciech Meyer
2012-05-28  9:35           ` Daniel Bünzli
2012-05-28  9:59             ` Gabriel Scherer
2012-05-30 14:45               ` Hongbo Zhang
2012-05-28 11:17             ` Wojciech Meyer
2012-05-28 15:52             ` Jeffrey Scofield
2012-05-27 18:19     ` Hongbo Zhang
2012-05-28  8:17     ` Paolo Donadeo
2012-05-30 12:41   ` Alain Frisch
2012-05-30 13:18     ` Markus Mottl
2012-05-30 13:37     ` Dan Bensen
2012-05-30 14:16       ` Hongbo Zhang
2012-05-30 14:23         ` Paolo Donadeo
     [not found]           ` <20120531081913.GA26742@securactive.lan>
2012-05-31 12:26             ` Paolo Donadeo
2012-05-31 12:38               ` Anil Madhavapeddy
2012-05-31 12:40                 ` Anil Madhavapeddy
2012-05-31 12:46                   ` Yaron Minsky
2012-05-31 12:47                   ` Gabriel Scherer
2012-05-31 22:08                 ` Paolo Donadeo
2012-05-30 14:14     ` Hongbo Zhang
2012-05-31 12:59       ` Alain Frisch
2012-05-31 13:21         ` Dmitry Grebeniuk
2012-05-31 14:30           ` Daniel Bünzli
2012-05-31 16:01         ` bob zhang
2012-05-31 17:28           ` Gerd Stolpmann
2012-05-31 18:03             ` Wojciech Meyer
2012-05-31 18:32               ` Gerd Stolpmann [this message]
2012-05-31 18:32             ` Hongbo Zhang

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=1338489164.17140.135.camel@thinkpad \
    --to=info@gerd-stolpmann.de \
    --cc=alain@frisch.fr \
    --cc=bobzhang1988@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=wojciech.meyer@googlemail.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).