From: Wolfram Kahl <kahl@cas.mcmaster.ca>
To: caml-list@inria.fr
Cc: rtarpine@hotmail.com
Subject: Re: [Caml-list] Cannot find Stream Parser Documentation
Date: Tue, 9 Apr 2002 14:09:29 -0400 [thread overview]
Message-ID: <200204091809.g39I9TV03521@demokrit.cas.mcmaster.ca> (raw)
In-Reply-To: <F241eHu7RVLCMUWktUq0000fbc1@hotmail.com> (rtarpine@hotmail.com)
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
next parent reply other threads:[~2002-04-10 8:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <F241eHu7RVLCMUWktUq0000fbc1@hotmail.com>
2002-04-09 18:09 ` Wolfram Kahl [this message]
2002-04-10 11:03 ` [Caml-list] Streams Daniel de Rauglaudre
2002-04-11 14:35 ` Wolfram Kahl
2002-04-05 18:58 [Caml-list] Cannot find Stream Parser Documentation Wolfram Kahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200204091809.g39I9TV03521@demokrit.cas.mcmaster.ca \
--to=kahl@cas.mcmaster.ca \
--cc=caml-list@inria.fr \
--cc=rtarpine@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox