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=2.1 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id DCC7FBBAF for ; Wed, 22 Jul 2009 12:03:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqECAIGAZkrRVdzWkWdsb2JhbACZJj8BAQEBCQkMBxGkRIEckGwBAwIEhAoFgUA X-IronPort-AV: E=Sophos;i="4.43,245,1246831200"; d="scan'208";a="43789231" Received: from mail-fx0-f214.google.com ([209.85.220.214]) by mail4-smtp-sop.national.inria.fr with ESMTP; 22 Jul 2009 12:03:02 +0200 Received: by fxm10 with SMTP id 10so76199fxm.27 for ; Wed, 22 Jul 2009 03:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=FF0hATO1Phb1q8Bdg51bLR+0jZx/nA1jsHyZOcwoR9k=; b=L+fX+7T69vK1ej9hdwDLS8YwajFvGMZlWROou8Bd7VIuwmQrHnL6hlw72jxy0FtX+O 2m90d4iAP+9RC2j0SyzOpisLAgMIi7lLMIqEPLxBQfJ/GCnHJk8vT5c+qRVxRMLi/NnL C54zAIUmSxjfcbX2cOmvy6BLg3Rw3ZI/IQoHI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=rcM4rD2gU/g0GIZMHyi1RQr5wv6PijNoNiRW7hZjmKlgjprxxdIhIi04Z7aYMufKSm N2jPdk3Vg/aKDDGNqBL+jwUntV4DNq3/cvbaORPRdl75zn0OOZJZ5Fs3a5cZh39+P6ap 1zWkPir+BbDqwKrfikXF20RU2D1lKxy56IFpA= MIME-Version: 1.0 Received: by 10.204.121.194 with SMTP id i2mr705806bkr.101.1248256981685; Wed, 22 Jul 2009 03:03:01 -0700 (PDT) In-Reply-To: <1248006890.4590.166.camel@serge2> References: <1248006890.4590.166.camel@serge2> Date: Wed, 22 Jul 2009 12:03:01 +0200 Message-ID: <527cf6bc0907220303l4b5ea63ch442c92d186f45cc1@mail.gmail.com> Subject: Re: [Caml-list] DELETE_RULE arguments? From: blue storm To: Serge Leblanc Cc: caml-list@yquem.inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; syntax:01 camlp:01 parsers:01 camlp:01 expr:01 expr:01 syntax:01 syntaxes:01 val:01 storm:98 2009:98 wrote:01 parsing:01 caml-list:01 grammar:02 On Sun, Jul 19, 2009 at 2:34 PM, Serge Leblanc wrote: > Otherwise, is there a way to know if the active syntax, is the revised or > not? The way used in Camlp4Parsers/Camlp4ListComprehension.ml is to try to delete a rule and see if it fails : value is_revised = try do { DELETE_RULE Gram expr: "["; sem_expr_for_list; "::"; expr; "]" END; True } with [ Not_found -> False ]; It works fine in this case as the grammar rule have to be deleted anyway, but if you don't want to affect the grammar you could test parsing for failure. Something like : value is_revised = try do { Gram.parse_string Syntax.expr Loc.ghost "fun [ x -> x]"; True } with [ _ -> False]; Of course, those tests could fail given a syntax that is neither the classic nor the revised syntax. Eg. if you write an extension adding the fun [ .. ] syntax to the standard syntax and it would return true. A safer way to test the used syntaxes is the Register.loaded_modules values : # #camlp4o;; # Camlp4.Register.loaded_modules;; - : string list ref = {contents = ["Camlp4OCamlParserParser"; "Camlp4OCamlRevisedParserParser"; "Camlp4OCamlParser"; "Camlp4OCamlRevisedParser"]} # #camlp4r;; # Camlp4.Register.loaded_modules; - : ref (list string) = {val=["Camlp4OCamlRevisedParserParser"; "Camlp4OCamlRevisedParser"]}