caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* New Camlp4 behavior (problem with rules starting with OPT)
@ 2007-04-13  8:27 Martin Jambon
  2007-04-13 13:49 ` [Caml-list] " Nicolas Pouillard
  2007-04-14  5:20 ` Christian Stork
  0 siblings, 2 replies; 5+ messages in thread
From: Martin Jambon @ 2007-04-13  8:27 UTC (permalink / raw)
  To: caml-list

With camlp4 3.10.0+beta, the following syntax extension does not work, 
but it used to work in the "old" camlp4.

File pa_toto.ml:
----------------

(* ocamlc -c -I +camlp4 -pp camlp4orf pa_toto.ml *)

open Camlp4.PreCast
open Syntax

EXTEND Gram
   GLOBAL: str_item;
   str_item: LEVEL "top" [
     [ "TEST"; "{"; l = item_list; "}" -> <:str_item< >> ]
   ];

   item_list: [
     [ x = item; ";"; l = SELF -> x :: l
     | x = item; ";" -> [x]
     | x = item -> [x] ]
   ];

   item: [
     [ mut = OPT "mutable"; name = LIDENT -> () ]
   ];
END



File toto.ml:
-------------

(* camlp4o -parser pa_toto.cmo -printer o toto.ml *)

TEST { a; b; }



camlp4o -parser pa_toto.cmo -printer o toto.ml
File "toto.ml", line 3, characters 11-12:
Parse error: LIDENT _ expected (in [item])

This points to the second ";".


One possible fix consists in getting rid of the leading OPT.
It's how it's done in Camlp4OCamlParser.ml (label_declaration):

Before:
-------
   item: [
     [ mut = OPT "mutable"; name = LIDENT -> () ]
   ];


After:
------

   item: [
     [ "mutable"; name = LIDENT -> ()
     | name = LIDENT -> () ]
   ];


I don't know if it's a bug or a new "feature", but this is definitely 
annoying. Could the old behavior be restored?


Thanks


Martin

--
Martin Jambon
http://martin.jambon.free.fr


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-14  5:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-13  8:27 New Camlp4 behavior (problem with rules starting with OPT) Martin Jambon
2007-04-13 13:49 ` [Caml-list] " Nicolas Pouillard
2007-04-13 21:43   ` Martin Jambon
2007-04-14  5:16   ` Christian Stork
2007-04-14  5:20 ` Christian Stork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).