Skip to content

Instantly share code, notes, and snippets.

@ldfallas
Created February 7, 2012 11:28
Show Gist options
  • Save ldfallas/1759234 to your computer and use it in GitHub Desktop.
Save ldfallas/1759234 to your computer and use it in GitHub Desktop.
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