Version française
Home     About     Download     Resources     Contact us    
Browse thread
New Camlp4 behavior (problem with rules starting with OPT)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: New Camlp4 behavior (problem with rules starting with OPT)
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