From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 93820BC69 for ; Sat, 6 Oct 2007 09:35:39 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAEfXBkfAXQInh2dsb2JhbACOOAEBAQgKKQ X-IronPort-AV: E=Sophos;i="4.21,238,1188770400"; d="scan'208";a="2442970" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Oct 2007 09:35:39 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l967Zdq0023490 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sat, 6 Oct 2007 09:35:39 +0200 X-IronPort-AV: E=Sophos;i="4.21,238,1188770400"; d="scan'208";a="2442969" Received: from peray.inria.fr (HELO ausone.inria.fr) ([128.93.8.98]) by mail2-relais-roc.national.inria.fr with SMTP; 06 Oct 2007 09:35:38 +0200 Received: by ausone.inria.fr (sSMTP sendmail emulation); Sat, _d Oct 2007 09:35:06 +0200 From: "Nicolas Pouillard" Cc: caml-list Subject: Re: [Caml-list] camlp4: Understanding class_declaration To: joelr1 References: In-Reply-To: Date: Sat, 06 Oct 2007 09:35:06 +0200 Message-Id: <1191655159-sup-9578@ausone.local> User-Agent: Sup/0.1 Content-Type: text/plain; charset=utf-8 X-j-chkmail-Score: MSGID : 47073ACB.000 on concorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at concorde with ID 47073ACB.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 camlp:01 grammars:01 parsers:01 parser:01 syntax:01 grammars:01 associative:01 syntax:01 ocaml:01 expr:01 expr:01 variants:01 expander:01 lexical:01 Excerpts from joelr1's message of Thu Oct 04 18:40:58 +0200 2007: > Would someone kindly explain LEFTA, SELF, ANTIQUOT and QUOTATION below? The main page about camlp4 extensible grammars/parsers is: http://brion.inria.fr/gallium/index.php/Extensible_Parser The syntax of grammars is given in: http://brion.inria.fr/gallium/index.php/EXTEND * LEFTA is left associative (its the default). * SELF refers to the current rule (class_declaration here), in most common cases SELF does what you want. ANTIQUOT and QUOTATION are token types like STRING, INT... The backquote syntax mark the begining of an OCaml pattern. So ANTIQUOT is a constructor (the token type [1]). The lexical syntax of an antiquotation is "$name:...$" or "$...$", it use in order to treat quotations [2] such as <:class_expr< myclass = object method m = $e$ end >> where `e' should better be an expression (Ast.expr). [1]: http://brion.inria.fr/gallium/index.php/Generic_Token_Type [2]: http://brion.inria.fr/gallium/index.php/Quotation > > class_declaration: > [ LEFTA > [ c1 = SELF; "and"; c2 = SELF -> > <:class_expr< $c1$ and $c2$ >> > | `ANTIQUOT (""|"cdcl"|"anti"|"list" as n) s -> > <:class_expr< $anti:mk_anti ~c:"class_expr" n s$ >> > | `QUOTATION x -> Quotation.expand _loc x > Quotation.DynAst.class_expr_tag > | ci = class_info_for_class_expr; ce = class_fun_binding -> > <:class_expr< $ci$ = $ce$ >> > ] ] > > It seems they are variants but that's about as much as I understand. > What are the "cdcl", "anti" or "list", for example? Why are they > strings? They are antiquotations names so you can write (don't pay attention to "anti") <:class_expr< $cdcl:x$ and $list:xs$ >>. > And why is `QUOTATION x expanded into Quotation.expand _loc x > Quotation.DynAst.class_expr_tag? When you see <:class_expr<...>> you give "..." to the quotation expander manager that will call the registered expanding function (the class_expr_tag is too indicate the requested type). Best regards, -- Nicolas Pouillard aka Ertai