/usr/share/doc/libghc-language-python-doc/html/src/Language-Python-Common-Pretty.html is in libghc-language-python-doc 0.4.1-4.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>src/Language/Python/Common/Pretty.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}</span>
<a name="line-2"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-3"></a><span class='hs-comment'>-- |</span>
<a name="line-4"></a><span class='hs-comment'>-- Module : Language.Python.Common.Pretty</span>
<a name="line-5"></a><span class='hs-comment'>-- Copyright : (c) 2009 Bernie Pope </span>
<a name="line-6"></a><span class='hs-comment'>-- License : BSD-style</span>
<a name="line-7"></a><span class='hs-comment'>-- Maintainer : bjpop@csse.unimelb.edu.au</span>
<a name="line-8"></a><span class='hs-comment'>-- Stability : experimental</span>
<a name="line-9"></a><span class='hs-comment'>-- Portability : ghc</span>
<a name="line-10"></a><span class='hs-comment'>--</span>
<a name="line-11"></a><span class='hs-comment'>-- Convenience class for pretty printing combinators.</span>
<a name="line-12"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-13"></a>
<a name="line-14"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Language</span><span class='hs-varop'>.</span><span class='hs-conid'>Python</span><span class='hs-varop'>.</span><span class='hs-conid'>Common</span><span class='hs-varop'>.</span><span class='hs-conid'>Pretty</span> <span class='hs-layout'>(</span><span class='hs-keyword'>module</span> <span class='hs-conid'>TextPP</span><span class='hs-layout'>,</span> <span class='hs-keyword'>module</span> <span class='hs-conid'>Language</span><span class='hs-varop'>.</span><span class='hs-conid'>Python</span><span class='hs-varop'>.</span><span class='hs-conid'>Common</span><span class='hs-varop'>.</span><span class='hs-conid'>Pretty</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-15"></a>
<a name="line-16"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Text</span><span class='hs-varop'>.</span><span class='hs-conid'>PrettyPrint</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>TextPP</span>
<a name="line-17"></a>
<a name="line-18"></a><span class='hs-comment'>--------------------------------------------------------------------------------</span>
<a name="line-19"></a>
<a name="line-20"></a><span class='hs-comment'>-- | All types which can be transformed into a 'Doc'.</span>
<a name="line-21"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyword'>where</span>
<a name="line-22"></a> <span class='hs-varid'>pretty</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span>
<a name="line-23"></a>
<a name="line-24"></a><a name="prettyText"></a><span class='hs-comment'>-- | Transform values into strings.</span>
<a name="line-25"></a><span class='hs-definition'>prettyText</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>String</span>
<a name="line-26"></a><span class='hs-definition'>prettyText</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>render</span> <span class='hs-varop'>.</span> <span class='hs-varid'>pretty</span>
<a name="line-27"></a>
<a name="line-28"></a><a name="prettyPrefix"></a><span class='hs-comment'>-- | Print just the prefix of something</span>
<a name="line-29"></a><span class='hs-definition'>prettyPrefix</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span>
<a name="line-30"></a><span class='hs-definition'>prettyPrefix</span> <span class='hs-varid'>maxLen</span> <span class='hs-varid'>x</span>
<a name="line-31"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>length</span> <span class='hs-varid'>fullText</span> <span class='hs-varop'><=</span> <span class='hs-varid'>maxLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pretty</span> <span class='hs-varid'>fullText</span>
<a name="line-32"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pretty</span> <span class='hs-layout'>(</span><span class='hs-varid'>take</span> <span class='hs-varid'>maxLen</span> <span class='hs-varid'>fullText</span><span class='hs-layout'>)</span> <span class='hs-varop'><+></span> <span class='hs-varid'>text</span> <span class='hs-str'>"..."</span>
<a name="line-33"></a> <span class='hs-keyword'>where</span>
<a name="line-34"></a> <span class='hs-varid'>fullText</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>prettyText</span> <span class='hs-varid'>x</span>
<a name="line-35"></a>
<a name="line-36"></a><a name="instance%20Pretty%20String"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-conid'>String</span> <span class='hs-keyword'>where</span>
<a name="line-37"></a> <span class='hs-varid'>pretty</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>text</span> <span class='hs-varid'>s</span>
<a name="line-38"></a>
<a name="line-39"></a><a name="parensIf"></a><span class='hs-comment'>-- | Conditionally wrap parentheses around an item.</span>
<a name="line-40"></a><span class='hs-definition'>parensIf</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-layout'>(</span><span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Bool</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span>
<a name="line-41"></a><span class='hs-definition'>parensIf</span> <span class='hs-varid'>test</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>test</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>then</span> <span class='hs-varid'>parens</span> <span class='hs-varop'>$</span> <span class='hs-varid'>pretty</span> <span class='hs-varid'>x</span> <span class='hs-keyword'>else</span> <span class='hs-varid'>pretty</span> <span class='hs-varid'>x</span>
<a name="line-42"></a>
<a name="line-43"></a><a name="perhaps"></a><span class='hs-definition'>perhaps</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Maybe</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span>
<a name="line-44"></a><span class='hs-definition'>perhaps</span> <span class='hs-conid'>Nothing</span> <span class='hs-varid'>doc</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>empty</span>
<a name="line-45"></a><span class='hs-definition'>perhaps</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-layout'>{</span><span class='hs-layout'>}</span><span class='hs-layout'>)</span> <span class='hs-varid'>doc</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>doc</span>
<a name="line-46"></a>
<a name="line-47"></a><a name="commaList"></a><span class='hs-comment'>-- | A list of things separated by commas.</span>
<a name="line-48"></a><span class='hs-definition'>commaList</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Doc</span>
<a name="line-49"></a><span class='hs-definition'>commaList</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hsep</span> <span class='hs-varop'>.</span> <span class='hs-varid'>punctuate</span> <span class='hs-varid'>comma</span> <span class='hs-varop'>.</span> <span class='hs-varid'>map</span> <span class='hs-varid'>pretty</span>
<a name="line-50"></a>
<a name="line-51"></a><a name="instance%20Pretty%20Int"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-conid'>Int</span> <span class='hs-keyword'>where</span>
<a name="line-52"></a> <span class='hs-varid'>pretty</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>int</span>
<a name="line-53"></a>
<a name="line-54"></a><a name="instance%20Pretty%20Integer"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-conid'>Integer</span> <span class='hs-keyword'>where</span>
<a name="line-55"></a> <span class='hs-varid'>pretty</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>integer</span>
<a name="line-56"></a>
<a name="line-57"></a><a name="instance%20Pretty%20Double"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-conid'>Double</span> <span class='hs-keyword'>where</span>
<a name="line-58"></a> <span class='hs-varid'>pretty</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>double</span>
<a name="line-59"></a>
<a name="line-60"></a><a name="instance%20Pretty%20Bool"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-conid'>Bool</span> <span class='hs-keyword'>where</span>
<a name="line-61"></a> <span class='hs-varid'>pretty</span> <span class='hs-conid'>True</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>text</span> <span class='hs-str'>"True"</span>
<a name="line-62"></a> <span class='hs-varid'>pretty</span> <span class='hs-conid'>False</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>text</span> <span class='hs-str'>"False"</span>
<a name="line-63"></a>
<a name="line-64"></a><a name="instance%20Pretty%20(Maybe%20a)"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Pretty</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>Pretty</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-varid'>a</span><span class='hs-layout'>)</span> <span class='hs-keyword'>where</span>
<a name="line-65"></a> <span class='hs-varid'>pretty</span> <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>empty</span>
<a name="line-66"></a> <span class='hs-varid'>pretty</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pretty</span> <span class='hs-varid'>x</span>
</pre></body>
</html>
|