<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.IO.Streams.Attoparsec</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_System-IO-Streams-Attoparsec.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/System-IO-Streams-Attoparsec.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">io-streams-1.1.4.5: Simple, composable, and easy-to-use stream I/O</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr></table><p class="caption">System.IO.Streams.Attoparsec</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Parsing </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>This module provides support for parsing values from <code>InputStream</code>s using <code>attoparsec</code>. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:parseFromStream">parseFromStream</a> :: <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a> r -> <a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> <a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/System-IO.html#t:IO">IO</a> r</li><li class="src short"><a href="#v:parserToInputStream">parserToInputStream</a> :: <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-Maybe.html#t:Maybe">Maybe</a> r) -> <a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> <a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/System-IO.html#t:IO">IO</a> (<a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> r)</li><li class="src short"><span class="keyword">data</span> <a href="#t:ParseException">ParseException</a> = <a href="#v:ParseException">ParseException</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-String.html#t:String">String</a></li></ul></div><div id="interface"><h1 id="g:1">Parsing </h1><div class="top"><p class="src"><a name="v:parseFromStream" class="def">parseFromStream</a> :: <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a> r -> <a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> <a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/System-IO.html#t:IO">IO</a> r<a href="src/System-IO-Streams-Internal-Attoparsec.html#parseFromStream" class="link">Source</a></p><div class="doc"><p>Supplies an <code>attoparsec</code> <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a></code> with an <code><a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a></code>, returning the final parsed value or a <code><a href="System-IO-Streams-Attoparsec.html#t:ParseException">ParseException</a></code> if parsing fails. </p><p><code><a href="System-IO-Streams-Attoparsec.html#v:parseFromStream">parseFromStream</a></code> consumes only as much input as necessary to satisfy the <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a></code> and unconsumed input is pushed back onto the <code><a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a></code>. </p><p>If the <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a></code> exhausts the <code><a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a></code>, it receives an <code>EOF</code>. </p><p>Example: </p><pre> ghci> import <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html">Data.Attoparsec.ByteString.Char8</a> ghci> is <- <code><a href="System-IO-Streams.html#t:fromList">fromList</a></code> ["12345xxx" :: <code><a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a></code>] ghci> <code><a href="System-IO-Streams-Attoparsec.html#v:parseFromStream">parseFromStream</a></code> (<code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:takeWhile">takeWhile</a></code> <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:isDigit">isDigit</a></code>) is "12345" ghci> <code><a href="System-IO-Streams.html#t:read">read</a></code> is Just "xxx" </pre></div></div><div class="top"><p class="src"><a name="v:parserToInputStream" class="def">parserToInputStream</a> :: <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a> (<a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-Maybe.html#t:Maybe">Maybe</a> r) -> <a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> <a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/System-IO.html#t:IO">IO</a> (<a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a> r)<a href="src/System-IO-Streams-Internal-Attoparsec.html#parserToInputStream" class="link">Source</a></p><div class="doc"><p>Given a <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString.html#t:Parser">Parser</a></code> yielding values of type <code><code><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-Maybe.html#t:Maybe">Maybe</a></code> r</code>, transforms an <code><a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a></code> over byte strings to an <code><a href="System-IO-Streams-Internal.html#t:InputStream">InputStream</a></code> yielding values of type <code>r</code>. </p><p>If the parser yields <code>Just x</code>, then <code>x</code> will be passed along downstream, and if the parser yields <code>Nothing</code>, that will be interpreted as end-of-stream. </p><p>Upon a parse error, <code><a href="System-IO-Streams-Attoparsec.html#v:parserToInputStream">parserToInputStream</a></code> will throw a <code><a href="System-IO-Streams-Attoparsec.html#t:ParseException">ParseException</a></code>. </p><p>Example: </p><pre> ghci> import <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Control-Applicative.html">Control.Applicative</a> ghci> import <a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html">Data.Attoparsec.ByteString.Char8</a> ghci> is <- <code><a href="System-IO-Streams.html#t:fromList">fromList</a></code> ["1 2 3 4 5" :: <code><a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a></code>] ghci> let parser = (<code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:endOfInput">endOfInput</a></code> >> <code><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Control-Applicative.html#t:pure">pure</a></code> <code><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-Maybe.html#v:Nothing">Nothing</a></code>) <|> (Just <$> (<code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:skipWhile">skipWhile</a></code> <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:isSpace">isSpace</a></code> *> <code><a href="/usr/share/doc/ghc/html/libraries/attoparsec-0.10.4.0/Data-Attoparsec-ByteString-Char8.html#t:decimal">decimal</a></code>)) ghci> <code><a href="System-IO-Streams-Attoparsec.html#v:parserToInputStream">parserToInputStream</a></code> parser is >>= <code><a href="System-IO-Streams.html#t:toList">toList</a></code> [1,2,3,4,5] ghci> is' <- <code><a href="System-IO-Streams.html#t:fromList">fromList</a></code> ["1 2xx3 4 5" :: <code><a href="/usr/share/doc/ghc/html/libraries/bytestring-0.10.0.2/Data-ByteString.html#t:ByteString">ByteString</a></code>] >>= <code><a href="System-IO-Streams-Attoparsec.html#v:parserToInputStream">parserToInputStream</a></code> parser ghci> <code>read</code> is' Just 1 ghci> <code>read</code> is' Just 2 ghci> <code>read</code> is' *** Exception: Parse exception: Failed reading: takeWhile1 </pre></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:ParseException" class="def">ParseException</a> <a href="src/System-IO-Streams-Internal-Attoparsec.html#ParseException" class="link">Source</a></p><div class="doc"><p>An exception raised when parsing fails. </p></div><div class="subs constructors"><p class="caption">Constructors</p><table><tr><td class="src"><a name="v:ParseException" class="def">ParseException</a> <a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-String.html#t:String">String</a></td><td class="doc empty"> </td></tr></table></div><div class="subs instances"><p id="control.i:ParseException" class="caption collapser" onclick="toggleSection('i:ParseException')">Instances</p><div id="section.i:ParseException" class="show"><table><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Text-Show.html#t:Show">Show</a> <a href="System-IO-Streams-Attoparsec.html#t:ParseException">ParseException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Data-Typeable-Internal.html#t:Typeable">Typeable</a> <a href="System-IO-Streams-Attoparsec.html#t:ParseException">ParseException</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="/usr/share/doc/ghc/html/libraries/base-4.6.0.1/Control-Exception-Base.html#t:Exception">Exception</a> <a href="System-IO-Streams-Attoparsec.html#t:ParseException">ParseException</a></td><td class="doc empty"> </td></tr></table></div></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.13.2</p></div></body></html>