<br><div class="gmail_quote">On Sat, Apr 2, 2011 at 7:45 AM, S. Doaitse Swierstra <span dir="ltr">&lt;<a href="mailto:doaitse@swierstra.net">doaitse@swierstra.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div style="word-wrap: break-word;">Can you explain what are the advantages of your library over the online version of all applicative parsers in the uu-parsinglib, which are not restricted to the monoidal results?</div></blockquote>
<div><br><br>    To tell you the truth, even though I&#39;ve read the uu-parsinglib documentation I wasn&#39;t even aware of different parser types it allowed. The library documentation does not exactly advertise online parsers. I&#39;m reading the &quot;A Short Tutorial&quot; paper now (<a href="http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-044.pdf">http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-044.pdf</a>). It is interesting, but very much misnamed: it is neither short nor a tutorial. It does a good job of explaining the library implementation, but there&#39;s very little in the way of usage. The Demo.Examples module on the other hand does not provide any example of incremental parsing.<br>
<br>    Would you mind providing a short example of use of an uu-parsinglib online parser that actually takes advantage of incremental parsing? Here is such an example of incremental-parser use that you can adapt:<br><br>
<blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">{-# LANGUAGE OverloadedStrings #-}<br><br>module Main where<br><br>import Prelude hiding (null)<br>
import Data.ByteString.Char8 (ByteString, hGet, null, unpack)<br>import System.Environment (getArgs)<br>import System.IO (hIsEOF, IOMode(ReadMode), withFile)<br>import Text.ParserCombinators.Incremental<br><br>main= getArgs &gt;&gt;= mapM_ incremental<br>
<br>incremental filename = withFile filename ReadMode (flip processHandle testParser)<br>   where processHandle h p = do chunk &lt;- hGet h 1024<br>                                if null chunk <br>                                   then putStrLn &quot;EOF&quot; &gt;&gt; extract (feedEof p)<br>
                                   else extract (feed chunk p) &gt;&gt;= processHandle h<br>         extract p = let (r, p&#39;) = resultPrefix p<br>                     in print r &gt;&gt; return p&#39;<br><br>testParser :: Parser ByteString [Int]<br>
testParser = many0 (fmap (\digits-&gt; [read $ unpack digits]) (takeWhile1 (\c-&gt; c &gt;= &quot;0&quot; &amp;&amp; c &lt;= &quot;9&quot;))<br>                    &lt;&lt;|&gt; skip anyToken)<br></blockquote><br><br>    This simple example will read a text file containing integers, in kilobyte chunks, and print out the list of integers. The parser is simplistic, but it serves to illustrate the main points of the interface:<br>
  - the parser is fed input in chunks,<br>  - the parsed results are read in chunks, and<br>  - the input chunks may overlap with result components.<br>
</div></div><br>