diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-14 11:28:53 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-14 11:32:08 +0100 |
commit | 4b8d586412b024f24121e00c8ce0f2bc3eb53234 (patch) | |
tree | dcc006db9670a71c32bdf2bf13332227d1765e82 /src | |
parent | cc11c0743bbab50f0f9d7bcc33fd41533a280870 (diff) |
pretty print pipelines in .out files
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler.hs | 18 |
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 | ||
26 | import Data.Char | 27 | import Data.Char |
@@ -41,6 +42,7 @@ import System.FilePath | |||
41 | --import Debug.Trace | 42 | --import Debug.Trace |
42 | import qualified Data.Text as T | 43 | import qualified Data.Text as T |
43 | import qualified Data.Text.IO as TIO | 44 | import qualified Data.Text.IO as TIO |
45 | import qualified Text.Show.Pretty as PP | ||
44 | 46 | ||
45 | import LambdaCube.IR as IR | 47 | import LambdaCube.IR as IR |
46 | import LambdaCube.Compiler.Pretty hiding ((</>)) | 48 | import 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 | ||
211 | prettyShowUnlines :: Show a => a -> String | ||
212 | prettyShowUnlines = 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 | ||