summaryrefslogtreecommitdiff
path: root/tool
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 /tool
parentcc11c0743bbab50f0f9d7bcc33fd41533a280870 (diff)
pretty print pipelines in .out files
Diffstat (limited to 'tool')
-rw-r--r--tool/Compiler.hs21
1 files changed, 2 insertions, 19 deletions
diff --git a/tool/Compiler.hs b/tool/Compiler.hs
index e1984f80..7fdf9e99 100644
--- a/tool/Compiler.hs
+++ b/tool/Compiler.hs
@@ -3,7 +3,6 @@ import Options.Applicative
3import Data.Aeson 3import Data.Aeson
4import qualified Data.ByteString.Lazy as B 4import qualified Data.ByteString.Lazy as B
5import System.FilePath 5import System.FilePath
6import qualified Text.Show.Pretty as PP
7import Data.Version 6import Data.Version
8import Paths_lambdacube_compiler (version) 7import Paths_lambdacube_compiler (version)
9 8
@@ -48,7 +47,7 @@ compile cfg@Config{..} = do
48 Left err -> fail err 47 Left err -> fail err
49 Right ppl -> case pretty of 48 Right ppl -> case pretty of
50 False -> B.writeFile (withOutName $ baseName <> ".json") $ encode ppl 49 False -> B.writeFile (withOutName $ baseName <> ".json") $ encode ppl
51 True -> writeFile (withOutName $ baseName <> ".ppl") $ ppUnlines $ PP.ppShow ppl 50 True -> writeFile (withOutName $ baseName <> ".ppl") $ prettyShowUnlines ppl
52 51
53prettyPrint :: Config -> IO () 52prettyPrint :: Config -> IO ()
54prettyPrint Config{..} = do 53prettyPrint Config{..} = do
@@ -57,21 +56,5 @@ prettyPrint Config{..} = do
57 json <- B.readFile srcName 56 json <- B.readFile srcName
58 case eitherDecode json :: Either String Pipeline of 57 case eitherDecode json :: Either String Pipeline of
59 Left err -> putStrLn err 58 Left err -> putStrLn err
60 Right ppl -> writeFile (withOutName $ baseName <> ".ppl") $ ppUnlines $ PP.ppShow ppl 59 Right ppl -> writeFile (withOutName $ baseName <> ".ppl") $ prettyShowUnlines ppl
61 60
62ppUnlines :: String -> String
63ppUnlines = goPP 0
64 where goPP _ [] = []
65 goPP n ('"':xs) | isMultilineString xs = "\"\"\"\n" ++ indent ++ go xs where
66 indent = replicate n ' '
67 go ('\\':'n':xs) = "\n" ++ indent ++ go xs
68 go ('\\':c:xs) = '\\':c:go xs
69 go ('"':xs) = "\n" ++ indent ++ "\"\"\"" ++ goPP n xs
70 go (x:xs) = x : go xs
71 goPP n (x:xs) = x : goPP (if x == '\n' then 0 else n+1) xs
72
73 isMultilineString ('\\':'n':xs) = True
74 isMultilineString ('\\':c:xs) = isMultilineString xs
75 isMultilineString ('"':xs) = False
76 isMultilineString (x:xs) = isMultilineString xs
77 isMultilineString [] = False