/usr/share/doc/libghc-boomerang-doc/html/Text-Boomerang.html is in libghc-boomerang-doc 1.4.5.2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <!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>Text.Boomerang</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="file:///usr/share/javascript/mathjax/MathJax.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
window.onload = function () {pageLoad();setSynopsis("mini_Text-Boomerang.html");};
//]]>
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/Text-Boomerang.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">boomerang-1.4.5.2: Library for invertible parsing and printing</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">Text.Boomerang</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Boomerang is a DSL for creating parsers and pretty-printers using a
single specification. Instead of writing a parser, and then writing a
separate pretty-printer, both are created at once. This saves time,
and ensures that the parser and pretty-printer are inverses and stay
in-sync with each other.</p><p>Boomerang is a generalized derivative of the Zwaluw library created by
Sjoerd Visscher and Martijn van Steenbergen:</p><p><a href="http://hackage.haskell.org/package/Zwaluw">http://hackage.haskell.org/package/Zwaluw</a></p><p>Boomerang is similar in purpose, but different in implementation to:</p><p><a href="http://hackage.haskell.org/package/invertible-syntax">http://hackage.haskell.org/package/invertible-syntax</a></p><p>Here is a simple example. First we enable three language extensions:</p><pre> {-# LANGUAGE TemplateHaskell, TypeOperators, OverloadedStrings #-}</pre><p>In the imports, note that we hide <code>((.), id)</code> from <code>Prelude</code> and use
<code>((.), id)</code> from <a href="file:///usr/share/doc/ghc-doc/html/libraries/base-4.9.0.0/Control-Category.html">Control.Category</a> instead.</p><pre>
module Main where
import Prelude hiding ((.), id)
import Control.Category ((.), id)
import Control.Monad (forever)
import Text.Boomerang
import Text.Boomerang.String
import Text.Boomerang.TH
import System.IO (hFlush, stdout)</pre><p>Next we define a type that we want to be able to pretty-print and define parsers for:</p><pre>data Foo
= Bar
| Baz Int Char
deriving (Eq, Show)</pre><p>Then we generate some combinators for the type:</p><pre>$(makeBoomerangs ''Foo)</pre><p>The combinators will be named after the constructors, but with an r prefixed to them. In this case, <code>rBar</code> and <code>rBaz</code>.</p><p>Now we can define a grammar:</p><pre>foo :: StringBoomerang () (Foo :- ())
foo =
( rBar
<> rBaz . "baz-" . int . "-" . alpha
)</pre><p><code>.</code> is used to compose parsers together. <code><a href="Text-Boomerang-Combinators.html#v:-60--62-"><></a></code> is used for choice.</p><p>Now we can use <code>foo</code> as a printer or a parser.</p><p>Here is an example of a successful parse:</p><pre>test1 = parseString foo "baz-2-c"</pre><pre>*Main> test1
Right (Baz 2 <code>c</code>)
</pre><p>And another example:</p><pre>test2 = parseString foo ""</pre><pre>*Main> test2
Right Bar
</pre><p>Here is an example of a parse error:</p><pre>test3 = parseString foo "baz-2-3"</pre><pre>*Main> test3
Left parse error at (0, 6): unexpected '3'; expecting an alphabetic Unicode character
</pre><p>we can also use <code>foo</code> to pretty-print a value:</p><pre>test4 = unparseString foo (Baz 1 'z')</pre><pre>*Main> test4
Just "baz-1-z"
</pre><p>Here is a little app that allows you to interactively test <code>foo</code>.</p><pre>testInvert :: String -> IO ()
testInvert str =
case parseString foo str of
(Left e) -> print e
(Right f') ->
do putStrLn $ "Parsed: " ++ show f'
case unparseString foo f' of
Nothing -> putStrLn "unparseString failed to produce a value."
(Just s) -> putStrLn $ "Pretty: " ++ s</pre><pre>main = forever $
do putStr "Enter a string to parse: "
hFlush stdout
l <- getLine
testInvert l</pre></div></div><div id="interface"><h1>Documentation</h1><div class="top"><p class="src">module <a href="Text-Boomerang-Combinators.html">Text.Boomerang.Combinators</a></p></div><div class="top"><p class="src">module <a href="Text-Boomerang-Error.html">Text.Boomerang.Error</a></p></div><div class="top"><p class="src">module <a href="Text-Boomerang-HStack.html">Text.Boomerang.HStack</a></p></div><div class="top"><p class="src">module <a href="Text-Boomerang-Prim.html">Text.Boomerang.Prim</a></p></div><div class="top"><p class="src">module <a href="Text-Boomerang-Pos.html">Text.Boomerang.Pos</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>
|