summaryrefslogtreecommitdiff
path: root/src/SPL/PrettyPrinter.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SPL/PrettyPrinter.hs')
-rw-r--r--src/SPL/PrettyPrinter.hs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/SPL/PrettyPrinter.hs b/src/SPL/PrettyPrinter.hs
index d711203..6d55d1b 100644
--- a/src/SPL/PrettyPrinter.hs
+++ b/src/SPL/PrettyPrinter.hs
@@ -10,6 +10,9 @@ import Control.Monad.State.Lazy
import Control.Monad.Identity
import Data.Char
+prettyPrint :: Pprint t => t -> String
+prettyPrint t = result $ execState (pprint t) (St 0 "")
+
-- For Extensibility
data St = St
{ indent :: Int
@@ -37,6 +40,7 @@ instance Pprint Function where
Just x -> pprint x
pprint ") :: "
pprint $ fvars f
+ pprint "("
pprint $ fname f
instance Pprint Variable where
@@ -53,6 +57,7 @@ instance Pprint Type where
pprint TInt = pprint "Int"
pprint TBool = pprint "Bool"
pprint TChar = pprint "Char"
+ pprint TVoid = pprint "Void"
pprint (TList t) = do
pprint "]"
pprint t
@@ -67,6 +72,7 @@ instance Pprint Type where
pprint ts
pprint "->"
pprint t
+ pprint (TVar v) = pprint v
instance Pprint Statement where
pprint (If expr smt1 (Just smt2)) = do
@@ -89,8 +95,9 @@ instance Pprint Statement where
pprint "){"
pprint expr
pprint "while ("
- pprint (Assign name expr) = do
+ pprint (Assign name fields expr) = do
pprint expr
+ pprint fields
pprint " = "
pprint name
pprint (Eval expr) = do
@@ -108,6 +115,7 @@ instance Pprint Statement where
pprint _ = error "Cannot pprint unknow statement"
instance Pprint Expression where
+ pprint (Var v) = pprint v
pprint (Field name field) = do
pprint field
pprint name
@@ -172,18 +180,7 @@ instance Pprint Literal where
pprint _ = error "Cannot pprint unknown literal"
instance Pprint a => Pprint [a] where
- pprint xs = mapM_ pprint xs
+ pprint = mapM_ pprint . reverse
instance Pprint Char where
pprint c = modify (\st -> st { result = (c : result st) })
-
--- prettyPrint :: [] -> String
--- prettyPrint ts = prettyPrint` ts newState
--- where
--- newState :: State
--- newState = State {indent = 0}
---
--- prettyPrint` :: [Token] -> Print
--- prettyPrint` [] = \s ->
--- prettyPrint` (t:ts) =
-