summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-14 11:28:53 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-14 11:32:08 +0100
commit4b8d586412b024f24121e00c8ce0f2bc3eb53234 (patch)
treedcc006db9670a71c32bdf2bf13332227d1765e82 /src
parentcc11c0743bbab50f0f9d7bcc33fd41533a280870 (diff)
pretty print pipelines in .out files
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/LambdaCube/Compiler.hs b/src/LambdaCube/Compiler.hs
index 916c57f5..8c3c4927 100644
--- a/src/LambdaCube/Compiler.hs
+++ b/src/LambdaCube/Compiler.hs
@@ -21,6 +21,7 @@ module LambdaCube.Compiler
21 21
22 , compilePipeline 22 , compilePipeline
23 , ppShow 23 , ppShow
24 , prettyShowUnlines
24 ) where 25 ) where
25 26
26import Data.Char 27import Data.Char
@@ -41,6 +42,7 @@ import System.FilePath
41--import Debug.Trace 42--import Debug.Trace
42import qualified Data.Text as T 43import qualified Data.Text as T
43import qualified Data.Text.IO as TIO 44import qualified Data.Text.IO as TIO
45import qualified Text.Show.Pretty as PP
44 46
45import LambdaCube.IR as IR 47import LambdaCube.IR as IR
46import LambdaCube.Compiler.Pretty hiding ((</>)) 48import LambdaCube.Compiler.Pretty hiding ((</>))
@@ -206,3 +208,19 @@ preCompile paths paths' backend mod = do
206 "Main" -> return ("./Main.lc", src) 208 "Main" -> return ("./Main.lc", src)
207 n -> ioFetch paths' imp n 209 n -> ioFetch paths' imp n
208 210
211prettyShowUnlines :: Show a => a -> String
212prettyShowUnlines = goPP 0 . PP.ppShow
213 where goPP _ [] = []
214 goPP n ('"':xs) | isMultilineString xs = "\"\"\"\n" ++ indent ++ go xs where
215 indent = replicate n ' '
216 go ('\\':'n':xs) = "\n" ++ indent ++ go xs
217 go ('\\':c:xs) = '\\':c:go xs
218 go ('"':xs) = "\n" ++ indent ++ "\"\"\"" ++ goPP n xs
219 go (x:xs) = x : go xs
220 goPP n (x:xs) = x : goPP (if x == '\n' then 0 else n+1) xs
221
222 isMultilineString ('\\':'n':xs) = True
223 isMultilineString ('\\':c:xs) = isMultilineString xs
224 isMultilineString ('"':xs) = False
225 isMultilineString (x:xs) = isMultilineString xs
226 isMultilineString [] = False