caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Stream parsers, again
@ 2000-02-01  2:19 Frank A. Christoph
  2000-02-02 15:46 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 2+ messages in thread
From: Frank A. Christoph @ 2000-02-01  2:19 UTC (permalink / raw)
  To: CAML List

Regarding my previous message, I just figured out that it is actually quite
easy to get "midstream" counts. Define this:

let count = parser bp [< >] -> bp

and then you can insert it in critical places like the example I gave:

  parser [< e = p; i = count; e' = p' ? err i >] -> ...

BTW, it is nice that the error expression is itself lazily evaluated. I
think it is too restrictive that it needs to return a string rather than an
arbitrary type, but fortunately you can just raise an exception from within
the stream error exception itself:

  exception Err of int
  let err cnt = raise (Err cnt)

--fac




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

* Re: Stream parsers, again
  2000-02-01  2:19 Stream parsers, again Frank A. Christoph
@ 2000-02-02 15:46 ` Daniel de Rauglaudre
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel de Rauglaudre @ 2000-02-02 15:46 UTC (permalink / raw)
  To: Frank A. Christoph, CAML List

Hello,

On Tue, Feb 01, 2000 at 11:19:18AM +0900, Frank A. Christoph wrote:

> let count = parser bp [< >] -> bp

This function already exists: "Stream.count".

>   parser [< e = p; i = count; e' = p' ? err i >] -> ...
> 
> BTW, it is nice that the error expression is itself lazily evaluated.

If you got the name of the stream (i.e. "strm"), you can also use:

   parser [< e = p; e' = p' ? err (Stream.count strm) >] -> ...

> I think it is too restrictive that it needs to return a string
> rather than an arbitrary type

Mmm... Remember that polymorphic exceptions are impossible in Caml.
Your solution:

>   exception Err of int
>   let err cnt = raise (Err cnt)

... is the good one.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/



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

end of thread, other threads:[~2000-02-02 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-01  2:19 Stream parsers, again Frank A. Christoph
2000-02-02 15:46 ` Daniel de Rauglaudre

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