Version française
Home     About     Download     Resources     Contact us    
Browse thread
Stream parsers, again
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frank A. Christoph <christo@n...>
Subject: Stream parsers, again
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