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

* Re: [Caml-list] New Camlp4 behavior (problem with rules starting with OPT)
  2007-04-13  8:27 New Camlp4 behavior (problem with rules starting with OPT) Martin Jambon
@ 2007-04-13 13:49 ` Nicolas Pouillard
  2007-04-13 21:43   ` Martin Jambon
  2007-04-14  5:16   ` Christian Stork
  2007-04-14  5:20 ` Christian Stork
  1 sibling, 2 replies; 5+ messages in thread
From: Nicolas Pouillard @ 2007-04-13 13:49 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list

On 4/13/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> With camlp4 3.10.0+beta, the following syntax extension does not work,
> but it used to work in the "old" camlp4.

IMHO having rules starting with OPT don't fit very well with the
camlp4 parsing mechanism.

It works in the 3.09 version but I don't know why.

I think that you shouldn't rely on that anymore.

Cheers,

-- 
Nicolas Pouillard


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

* Re: [Caml-list] New Camlp4 behavior (problem with rules starting with OPT)
  2007-04-13 13:49 ` [Caml-list] " Nicolas Pouillard
@ 2007-04-13 21:43   ` Martin Jambon
  2007-04-14  5:16   ` Christian Stork
  1 sibling, 0 replies; 5+ messages in thread
From: Martin Jambon @ 2007-04-13 21:43 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

On Fri, 13 Apr 2007, Nicolas Pouillard wrote:

> On 4/13/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> > With camlp4 3.10.0+beta, the following syntax extension does not work,
> > but it used to work in the "old" camlp4.
>
> IMHO having rules starting with OPT don't fit very well with the
> camlp4 parsing mechanism.
>
> It works in the 3.09 version but I don't know why.
>
> I think that you shouldn't rely on that anymore.

Perhaps you can have camlp4 test and reject such rules automatically. It
would be a big timesaver.


Thanks


Martin

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


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

* Re: [Caml-list] New Camlp4 behavior (problem with rules starting with OPT)
  2007-04-13 13:49 ` [Caml-list] " Nicolas Pouillard
  2007-04-13 21:43   ` Martin Jambon
@ 2007-04-14  5:16   ` Christian Stork
  1 sibling, 0 replies; 5+ messages in thread
From: Christian Stork @ 2007-04-14  5:16 UTC (permalink / raw)
  To: caml-list

On Fri, Apr 13, 2007 at 03:49:32PM +0200, Nicolas Pouillard wrote:
> On 4/13/07, Martin Jambon <martin.jambon@ens-lyon.org> wrote:
> >With camlp4 3.10.0+beta, the following syntax extension does not work,
> >but it used to work in the "old" camlp4.
> 
> IMHO having rules starting with OPT don't fit very well with the
> camlp4 parsing mechanism.
> 
> It works in the 3.09 version but I don't know why.
> 
> I think that you shouldn't rely on that anymore.

Hmm, then the same applies to rules starting with LIST0, too?  I think
this has at least to be documented.

Why not "simply" expand such rules into to obvious pair of rules?  After
all, OPT is just a shorthand for the programmer anyway.  Or are you
anticipating problems specifying such rules for DELETE?

-- 
Chris Stork   <>  Support eff.org!  <>   http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint:  B08B 602C C806 C492 D069  021E 41F3 8C8D 50F9 CA2F


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

* Re: [Caml-list] New Camlp4 behavior (problem with rules starting with OPT)
  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-14  5:20 ` Christian Stork
  1 sibling, 0 replies; 5+ messages in thread
From: Christian Stork @ 2007-04-14  5:20 UTC (permalink / raw)
  To: caml-list

On Fri, Apr 13, 2007 at 01:27:24AM -0700, Martin Jambon wrote:
> With camlp4 3.10.0+beta, the following syntax extension does not work, 
> but it used to work in the "old" camlp4.
> 
...
>   item: [
>     [ mut = OPT "mutable"; name = LIDENT -> () ]
...
According to http://pauillac.inria.fr/~pouillar/camlp4-changes.html :

    In grammars, constructions (LIST0, LIST1, OPT) no longer accept a
    single token. LIST0 STRING can be replaced by lIST0 [ x = STRING ->
    x ]

So this shouldn't work at all?!  Nicolas, does this restriction still
exist?

-- 
Chris Stork   <>  Support eff.org!  <>   http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint:  B08B 602C C806 C492 D069  021E 41F3 8C8D 50F9 CA2F


^ 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).