From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id B19EA7ED26 for ; Thu, 31 May 2012 20:32:43 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqQCAB+4x0/U4367k2dsb2JhbABEgx2CMK5HIgEBAQEJCQsJFAMkghkBBSMEUhALGgImAgJXBhMJiAYHpkCSNIEjiW6ENIESA40kiQOEQI0G X-IronPort-AV: E=Sophos;i="4.75,693,1330902000"; d="scan'208";a="160788461" Received: from moutng.kundenserver.de ([212.227.126.187]) by mail1-smtp-roc.national.inria.fr with ESMTP; 31 May 2012 20:32:43 +0200 Received: from office1.lan.sumadev.de (dslb-188-097-013-091.pools.arcor-ip.net [188.97.13.91]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0LlVlX-1RyuPn1YjX-00bHGK; Thu, 31 May 2012 20:32:41 +0200 Received: from [192.168.5.106] (dslb-188-097-013-091.pools.arcor-ip.net [188.97.13.91]) by office1.lan.sumadev.de (Postfix) with ESMTPSA id C0079C00D0; Thu, 31 May 2012 20:32:39 +0200 (CEST) From: Gerd Stolpmann To: Wojciech Meyer Cc: bob zhang , Alain Frisch , caml-list@inria.fr In-Reply-To: References: <4FC61595.6070009@frisch.fr> <4FC62B53.20504@gmail.com> <4FC76B3E.2070509@frisch.fr> <1338485339.17140.120.camel@thinkpad> Content-Type: text/plain; charset="UTF-8" Date: Thu, 31 May 2012 20:32:44 +0200 Message-ID: <1338489164.17140.135.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:+ZFDVMDn6g8X8aE9I8UsYFGPq7ziiRTmxaBK1xHbuu3 36KchxwgTEzjFaTNc1Ia9bCIlcKix/DFcQApp1P++a45K0RaOw 7Nk4dOquCOZSBwiv8vdQdSbjWGw2Yo5pqcmLfE/6HnsjDYizp4 8KyM1YoZnFVFla89sjA/iLRfY8iSP64UCx7XzbAIUJewEnHYak nuMCuFhX1kMBe0BSrt3abnBzSX38Dg4lcGPkBzeHAheFQQ5jRp 2rNhvmTRRXqUuudQVrDomf++hQG7wEVsG7axdJv+RuY5LnmIzx MilD1BDcr5PTi9WzBxEEt0RYGuGpFDzA+52EP+bB77ICxepO4/ kCq6O3yvCpafyTDX5Jja8Th0WnvTxgenSZ/23Ksxc Subject: Re: [Caml-list] Re: Syntax extensions without Camlp4 Am Donnerstag, den 31.05.2012, 19:03 +0100 schrieb Wojciech Meyer: > Gerd Stolpmann 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. ------------------------------------------------------------