module ATermWrite where

import ATermAbstractSyntax
import Data.List (intersperse)

writeATerm              :: ATerm -> String
writeATerm :: ATerm -> String
writeATerm ATerm
t            = Int -> ATerm -> String
writeAT Int
0 ATerm
t

writeAT                 :: Int -> ATerm -> String
writeAT :: Int -> ATerm -> String
writeAT Int
n (AAppl String
c [ATerm]
ts) = (if (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) then String
"\n" else String
"")
                         String -> String -> String
forall a. [a] -> [a] -> [a]
++ Int -> Char -> String
forall a. Int -> a -> [a]
replicate Int
n Char
' '  
                         String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
writeATermAux String
c ((ATerm -> String) -> [ATerm] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> ATerm -> String
writeAT (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
2)) [ATerm]
ts)
writeAT Int
n (AList [ATerm]
ts)    =  String -> String
bracket ([String] -> String
commaSep ((ATerm -> String) -> [ATerm] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> ATerm -> String
writeAT Int
n) [ATerm]
ts))
writeAT Int
_ (AInt Integer
i)      =  Integer -> String
forall a. Show a => a -> String
show Integer
i
writeAT Int
_ (AString String
s)   =  String -> String
quote String
s

writeATermAux           :: [Char] -> [[Char]] -> [Char]
writeATermAux :: String -> [String] -> String
writeATermAux String
c []      =  String
cString -> String -> String
forall a. [a] -> [a] -> [a]
++(String -> String
parenthesise String
"")
writeATermAux String
c [String]
ts      =  String
cString -> String -> String
forall a. [a] -> [a] -> [a]
++(String -> String
parenthesise ([String] -> String
commaSep [String]
ts))

commaSep                :: [[Char]] -> [Char]
commaSep :: [String] -> String
commaSep [String]
strs           =  [String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse String
"," [String]
strs)
bracket                 :: [Char] -> [Char]
bracket :: String -> String
bracket String
str             = String
"["String -> String -> String
forall a. [a] -> [a] -> [a]
++String
strString -> String -> String
forall a. [a] -> [a] -> [a]
++String
"]"
parenthesise            :: [Char] -> [Char]
parenthesise :: String -> String
parenthesise String
str        = String
"("String -> String -> String
forall a. [a] -> [a] -> [a]
++String
strString -> String -> String
forall a. [a] -> [a] -> [a]
++String
")"
quote                   :: [Char] -> [Char]
quote :: String -> String
quote String
str               = String
"\""String -> String -> String
forall a. [a] -> [a] -> [a]
++String
strString -> String -> String
forall a. [a] -> [a] -> [a]
++String
"\""