* 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
* Re: [Caml-list] Streams
2002-04-09 18:09 ` [Caml-list] Cannot find Stream Parser Documentation Wolfram Kahl
@ 2002-04-10 11:03 ` Daniel de Rauglaudre
2002-04-11 14:35 ` Wolfram Kahl
0 siblings, 1 reply; 4+ messages in thread
From: Daniel de Rauglaudre @ 2002-04-10 11:03 UTC (permalink / raw)
To: caml-list
Hi,
> let pc0 c = parser n
> [< ' x
> when x == c
> ?? (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'")
> >] -> ();;
The "??" is unuseful for the first element of a stream pattern, because
when it fails, it raises Stream.Failure, not Stream.Error. The "??"
introduces a parameter for Stream.Error. Your code is equivalent to:
let pc0 c = parser n
[< ' x
when x == c
>] -> ();;
It was an error that the OCaml version accepted the "??" for the first
element.
--
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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
* Re: [Caml-list] Streams
2002-04-10 11:03 ` [Caml-list] Streams Daniel de Rauglaudre
@ 2002-04-11 14:35 ` Wolfram Kahl
0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Kahl @ 2002-04-11 14:35 UTC (permalink / raw)
To: caml-list
Hi,
Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr> pinpointed the problem:
>
> It was an error that the OCaml version accepted the "??" for the first
> element.
Thanks!
> Your code is equivalent to:
>
> let pc0 c = parser n
> [< ' x
> when x == c
> >] -> ();;
However, there is nothing on
http://caml.inria.fr/camlp4/tutorial/tutorial002.html
that indicates that even this might be legal ---
``when'' is not mentioned on that page.
Would it perhaps make sense to include an adapted version
of the old OCaml Manual section on streams
that tries to give a general description instead of
just a few selected examples?
(Also I have found it useful to leave two blanks after '
in parsers since in some instances I obtained very strange
(lexical?) errors.
)
Best regards,
Wolfram Kahl
-------------------
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
* [Caml-list] Cannot find Stream Parser Documentation
@ 2002-04-05 18:58 Wolfram Kahl
0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Kahl @ 2002-04-05 18:58 UTC (permalink / raw)
To: caml-list
Hi,
currently I am finally trying to port my stuff from OCaml-3.02
to OCaml-3.04, and I am having problems related with stream parsers:
I am using the stream error catcher
[< .... ?? HERE >]
--- the separator once was a single `?',
and had to be turned into `??' for OLabl, and now neither works!
ocamlc -I +labltk -pp camlp4o -c xmlParse.ml
File "xmlParse.ml", line 101, characters 6-7:
Parse error: '>]' expected after [stream_patt] (in [parser_case])
Preprocessing error
99 let pc c = parser n
100 [< ' x when x == c
101 ? (string_of_int n ^ ": pc '" ^ String.make 1 c ^ "'")
102 >] -> ();;
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.)
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?
The ocamldep chapter has only includes in its example Makefile:
# Dependencies
depend:
$(OCAMLDEP) $(INCLUDES) *.mli *.ml > .depend
Is there any trick that would force file-specific settings to ocamldep?
Many thanks in advance!
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
end of thread, other threads:[~2002-04-11 14:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <F241eHu7RVLCMUWktUq0000fbc1@hotmail.com>
2002-04-09 18:09 ` [Caml-list] Cannot find Stream Parser Documentation Wolfram Kahl
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox