Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] camlp4 and streams

3 views
Skip to first unread message

Isaac Freeman

unread,
May 13, 2007, 12:00:57 PM5/13/07
to caml...@yquem.inria.fr
Hello,

I am having some problems using streams in my camlp4 extentions. The code:

EXTEND
expr: LEVEL "expr1"
[[ "yield"; e1 = expr LEVEL "simple";
"continue"; e2 = expr LEVEL "simple" ->
<:expr< [< $e1$; $e2$ >] >> ]];
END;;

produces the error:

isaac@lappy:~/stuff/ocaml$ ocamlc -pp "camlp4o pa_extend.cmo
q_MLast.cmo" -I +camlp4 -c gen-syntax.ml
File "gen-syntax.ml", line 8, characters 18-20:
While expanding quotation "expr":
Parse error: illegal begin of expression
Uncaught exception: Pcaml.Qerror("expr", 1, _)
Preprocessor error

However, when I change the stream into a list, it works fine, so I'm
sure there is just some technicality in using streams here that I'm
not accounting for properly. Any ideas?

Thanks,
Isaac

--
James "Isaac" Freeman
memotype (at) gmail.com

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Nicolas Pouillard

unread,
May 13, 2007, 4:29:32 PM5/13/07
to Isaac Freeman
On 5/13/07, Isaac Freeman <memo...@gmail.com> wrote:
> Hello,
>
> I am having some problems using streams in my camlp4 extentions. The code:
>
> EXTEND
> expr: LEVEL "expr1"
> [[ "yield"; e1 = expr LEVEL "simple";
> "continue"; e2 = expr LEVEL "simple" ->
> <:expr< [< $e1$; $e2$ >] >> ]];
> END;;
>
> produces the error:
>
> isaac@lappy:~/stuff/ocaml$ ocamlc -pp "camlp4o pa_extend.cmo
> q_MLast.cmo" -I +camlp4 -c gen-syntax.ml
> File "gen-syntax.ml", line 8, characters 18-20:
> While expanding quotation "expr":
> Parse error: illegal begin of expression
> Uncaught exception: Pcaml.Qerror("expr", 1, _)
> Preprocessor error
>
> However, when I change the stream into a list, it works fine, so I'm
> sure there is just some technicality in using streams here that I'm
> not accounting for properly. Any ideas?

You are hitting a limitation of the old camlp4 implementation. The
thing is that the quotation expander <:expr<...>> provided by
q_MLast.cmo is somewhat limited to the revised syntax.

BTW in revised streams syntax is: [: ... :] (instead of [< ... >]) and
elements starts with a backquote instead of a single quote.

Indeed the stream syntax is provided as a syntactic sugar over regular
OCaml code using the Stream module from the standard library.

However the new Camlp4 implementation provided in 3.10 lift that
shortcoming by giving a full reflection system. So if you want to use
the original syntax everywhere you can use camlp4of that provided
quotation (<:expr<...>>, patt, ctyp...) in the original syntax
including syntactic sugars.

Here is a 3.10 valid extension:

$ cat ext.ml
open Camlp4.PreCast;;
open Syntax;;
EXTEND Gram
expr: LEVEL "top"


[[ "yield"; e1 = expr LEVEL "simple";
"continue"; e2 = expr LEVEL "simple" ->
<:expr< [< $e1$; $e2$ >] >> ]];
END;;

$ ocamlc -c -I +camlp4 -pp camlp4of ext.ml
$ camlp4o ./ext.cmo -str 'yield e1 continue e2'
Stream.lapp (fun _ -> e1) (Stream.slazy (fun _ -> e2))

Best regards,

--
Nicolas Pouillard

0 new messages