Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jake Donham <jake@d...>
Subject: Re: [Caml-list] camlp4 grammar and LIST1
On Tue, Mar 10, 2009 at 11:41 AM, Joel Reymont <joelr1@gmail.com> wrote:
>  inputDeclarations:
>  [
>    [ "Input"; ":";
>      l = LIST1 inputDeclaration SEP "," -> l
>    ]
>  ];
>
> Is it always necessary to write [ x = inputDeclaration -> x ] instead of
> just inputDeclaration?

I don't think this is ever necessary (although in the back of my mind
I have a fuzzy recollection that somewhere in the docs / wiki it says
that it is). I can't say why you got a type error one way but not the
other.

For debugging types, you might find it helpful to look at the output
of the preprocessing step, which has various type annotations.

> By the same token, can I shorten the gramar below to just [ openStatement |
> closedStatement ]?
>
>  statement: [ [ s = openStatement -> s | s = closedStatement -> s ] ];

Syntactically it is fine but I don't think this is going to do what
you want. Camlp4 parsers aren't backtracking; you have to distinguish
openStatement from closedStatement by parsing a token. Otherwise
you'll always follow the openStatement branch, then get a parse error
if the stream wasn't actually parseable as an openStatement. (I think
this is correct but it has been a few months since I worked on a
grammar, sorry if I remembered it wrong.)

Jake