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.3 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 288C8BBAF for ; Wed, 11 Mar 2009 00:01:45 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqEGAEeOtknRVd2CdWdsb2JhbACUbz8BDAoLBxGtBY9eAQMBA4QKBoUm X-IronPort-AV: E=Sophos;i="4.38,338,1233529200"; d="scan'208";a="36370882" Received: from mail-qy0-f130.google.com ([209.85.221.130]) by mail4-smtp-sop.national.inria.fr with ESMTP; 11 Mar 2009 00:01:44 +0100 Received: by qyk36 with SMTP id 36so1900368qyk.1 for ; Tue, 10 Mar 2009 16:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=ZGieBoE6EHhqnJu87bhWFGs0PAPVhTQD6aBtqBaHPj8=; b=lF6y7ltMgExqg3N6dS3at1jZlICnpaBpbIpYuF9UMY3p+Awb7yr8ndyIJmjAeG0511 o4UpK3QjoEicJd2El5WOXWsP3jslmbuQmG9AhaI6/u/Mf35MAioYkb9WZoSMlryEVi0k +DtAszVMKRU5FRSyOhlLeDN1EHpxuJvQkfNwQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=GuqQ4AdWGetxUEHbW7XOZdSIL/xKfq6DU/F70WvSqV/y7vZ7BXm7lHlKMF+3rw6G5V BLn1yCRvCusQIJd98zQoMX07yOTRKoJFZ8YsKMP0OBhZX937PJiWcNkOwAvG+85MvG6+ k6udXBBixZ9oSjQkNjDhyBZ94C97mjs0M4GpY= MIME-Version: 1.0 Sender: jake.donham@gmail.com Received: by 10.224.45.210 with SMTP id g18mr10207588qaf.171.1236726103405; Tue, 10 Mar 2009 16:01:43 -0700 (PDT) In-Reply-To: References: <6485A041-8698-471F-9D9C-BF3DFF0D3018@gmail.com> Date: Tue, 10 Mar 2009 16:01:43 -0700 X-Google-Sender-Auth: 9145764aae03e8ed Message-ID: Subject: Re: [Caml-list] camlp4 grammar and LIST1 From: Jake Donham To: Joel Reymont Cc: "O'Caml Mailing List" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; camlp:01 camlp:01 baz:01 baz:01 quux:01 quux:01 recursive:01 branching:01 10,:98 2009:98 token:01 wrote:01 caml-list:01 grammar:02 parse:02 On Tue, Mar 10, 2009 at 3:07 PM, Joel Reymont wrote: > I have it like this at the moment. Are you saying it won't work? Here's an example of what I'm talking about: open Camlp4.PreCast let bar = Gram.Entry.mk "bar" let baz = Gram.Entry.mk "baz" let bar_or_baz = Gram.Entry.mk "bar_or_baz" ;; EXTEND Gram bar : [[ LIST0 "quux"; "bar" -> () ]]; baz : [[ LIST0 "quux"; "baz" -> () ]]; bar_or_baz : [[ bar | baz ]]; END ;; Gram.parse_string bar_or_baz Loc.ghost "quux quux baz" The given string does not parse because we've already committed to the bar branch. However, several variations I tried did not show this behavior (e.g. only one quux in the string). I think there are some special cases, although they are not documented anywhere I have found. An approach that works for me is to think "recursive descent" and always give rules that check at least one token before branching to another rule. Jake