Created
February 7, 2012 11:28
-
-
Save ldfallas/1759234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SCPPrint where | |
import SCParser | |
import Text.PrettyPrint.HughesPJ | |
--toStringP :: Expr -> String | |
toStringP (ScSymbol name) = text name | |
toStringP (ScNumber num) = text $ show num | |
toStringP (ScDouble num) = text $ show num | |
toStringP ScNil = text "'()" | |
toStringP (ScQuote exp) = text "'" <> (toStringP exp) | |
toStringP (ScBool value) = text $ if value then "#t" else "#f" | |
toStringP (ScString str) = quotes str | |
toStringP (ScCons first rest) = parens ( hang (toStringP first) 3 (sep $ toStringPCons rest)) | |
toStringPCons (ScCons part rest) = ((toStringP part) : (toStringPCons rest)) | |
toStringPCons ScNil = [] | |
toStringPCons other = [(text ".") , (toStringP other) ] | |
parseAndPrint text = | |
case (parseIt text) of | |
Right parsed -> Just $ toStringP parsed | |
_ -> Nothing | |
parseAndRender style text = | |
case (parseIt text) of | |
Right parsed -> putStr $ renderStyle style $ toStringP parsed | |
_ -> putStr "ParseError" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment