Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
camlp4 grammar and LIST1
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-03-10 (23:01)
From: Jake Donham <jake@d...>
Subject: Re: [Caml-list] camlp4 grammar and LIST1
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 = "bar"
  let baz = "baz"
  let bar_or_baz = "bar_or_baz"
  bar : [[ LIST0 "quux"; "bar" -> () ]];
  baz : [[ LIST0 "quux"; "baz" -> () ]];
  bar_or_baz : [[ bar | baz ]];
  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.