* Re: [Caml-list] Cannot find Stream Parser Documentation
[not found] <F241eHu7RVLCMUWktUq0000fbc1@hotmail.com>
@ 2002-04-09 18:09 ` Wolfram Kahl
2002-04-10 11:03 ` [Caml-list] Streams Daniel de Rauglaudre
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Kahl @ 2002-04-09 18:09 UTC (permalink / raw)
To: caml-list; +Cc: rtarpine
To my questions about streams and camlp4, I received two answers so far:
The first one from Ryan Tarpine <rtarpine@hotmail.com> unintentionally didn't
make it to the list:
>
> >From: Wolfram Kahl <kahl@cas.mcmaster.ca>
> >To: caml-list@inria.fr
> >Subject: [Caml-list] Cannot find Stream Parser Documentation
> >Date: Fri, 5 Apr 2002 13:58:18 -0500
> >
> >...
> >
> >The documentation for stream parsers that had been in the
> >``Language extensions'' chapter of the OCaml manual
> >seems to have disappeared, too.
> >I looked for it in the camlp4 directory,
> >but that directory doesn't even contain a README.
> >
> >In the OCaml distribution, camlp4 seems to come with no documentation
> >besides the manpage!
> >(And on the camlp4 web pages, I couldn't find anything related
> > to the implementation of streams.)
>
> I found the most information on stream parsers to be in camlp4's tutorial
> section, not the reference manual like I expected. See
> <http://caml.inria.fr/camlp4/tutorial/tutorial002.html> for the best info I
> stumbled across. It seems that '??' is the correct syntax, and your code
> works if you take out the 'when' clause, so maybe this is a bug?
>
> >A related issue: Among about 50 modules, only one uses stream parsers.
> >But
> >
> > ocamldep -pp camlp4o *.mli *.ml > .depend
> >
> >takes much longer than without camlp4.
> >How can I tell ocamldep to use camlp4 only for this file?
> >
> >...
>
> I recommend using Mr. Mottl's OCamlMakefile to manage your project. See
> <http://www.ai.univie.ac.at/~markus/home/ocaml_sources.html#OCamlMakefile>
> for info. With OCamlMakefile you just place the comment (*pp camlp4o *) at
> the top of any files that need to be preprocessed, and it takes care of the
> dirty work!
>
> HTH,
>
> Ryan Tarpine, rtarpine@hotmail.com
> "To err is human, to compute divine. Trust your computer but not its
> programmer."
> - Morris Kingston
>
In the second, Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
provides a practical pattern for use in hand-made makefiles:
>
> Regarding dependencies, there are several solutions. As far as I'm
> concerned, I chose to name my camlp4 files .ml4 and to produce the .ml
> file before computing the dependencies, like this:
>
> ======================================================================
> foo.ml: foo.ml4
> camlp4o pr_o.cmo -impl $< > $@
>
> depend: foo.ml
> ocamldep *.ml *.mli > .depend
> ======================================================================
>
> Of course, I do not produce the .ml file for compiling; I use ocamlc
> -pp:
>
> ======================================================================
> foo.cmo: foo.ml4
> ocamlc -c -pp "camlp4o -impl" -impl $<
>
> ======================================================================
This solves my ocamldep problem.
However, my real problem is not solved yet:
The stream language as currently supported by camlp4
apparently does not contain the full stream language of OCaml 3.02
(and many, many previous versions),
and I cannot find any document that explains the differences.
(In addition, all the OCaml sites at INRIA seem to be down since at least
yesterday ...)
So I did a few experiments with camlp4 stream translation:
My original code (this worked for years!):
Input 1:
-------------------------------
let pc0 c = parser n
[< ' x
when x == c
?? (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'")
>] -> ();;
-------------------------------
Message:
-------------------------------
File "streamTest.ml4", line 4, characters 8-10:
Parse error: '>]' expected after [stream_patt] (in [parser_case])
-------------------------------
The error points to `??'.
Since Ryan Tarpine points out that the ``when'' might be the problem,
but I need the condition, I try to factorise:
Input 2:
-------------------------------
let pc0 c = parser n
[< ' x
when (x == c)
>] -> ();;
let pc c = parser n
[< _ = pc0 c
?? (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'")
>] -> ();;
-------------------------------
Message:
-------------------------------
File "streamTest.ml4", line 7, characters 8-10:
Parse error: '>]' expected after [stream_patt] (in [parser_case])
-------------------------------
The error points to `??', again.
This is particularly interesting given that the following works
(only difference: two invocations of pc0 before `??'):
Input 3:
-------------------------------
let pc0 c = parser n
[< ' x
when (x == c)
>] -> ();;
let pc c = parser n
[< _ = pc0 c; _ = pc0 c
?? (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'")
>] -> ();;
-------------------------------
Output:
-------------------------------
let pc0 c (strm__ : _ Stream.t) =
let n = Stream.count strm__ in
match Stream.peek strm__ with
Some x when x == c -> Stream.junk strm__; ()
| _ -> raise Stream.Failure
;;
let pc c (strm__ : _ Stream.t) =
let n = Stream.count strm__ in
let _ = pc0 c strm__ in
let _ =
try pc0 c strm__ with
Stream.Failure ->
raise
(Stream.Error (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'"))
in
()
;;
-------------------------------
Against my expectations,
only the last invocation of pc0 is inside the try ... catch.
(Parentheses around the two invocations of pc0 are not accepted.)
I'm puzzled... Should I rather recode all my 247 Stream parsers manually?
Wolfram
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 4+ messages in thread