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 /tool | |
parent | cc11c0743bbab50f0f9d7bcc33fd41533a280870 (diff) |
pretty print pipelines in .out files
Diffstat (limited to 'tool')
-rw-r--r-- | tool/Compiler.hs | 21 |
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 | |||
3 | import Data.Aeson | 3 | import Data.Aeson |
4 | import qualified Data.ByteString.Lazy as B | 4 | import qualified Data.ByteString.Lazy as B |
5 | import System.FilePath | 5 | import System.FilePath |
6 | import qualified Text.Show.Pretty as PP | ||
7 | import Data.Version | 6 | import Data.Version |
8 | import Paths_lambdacube_compiler (version) | 7 | import 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 | ||
53 | prettyPrint :: Config -> IO () | 52 | prettyPrint :: Config -> IO () |
54 | prettyPrint Config{..} = do | 53 | prettyPrint 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 | ||
62 | ppUnlines :: String -> String | ||
63 | ppUnlines = 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 | ||