From: Francis Russell Date: Sun, 16 Sep 2012 10:54:02 +0000 (+0100) Subject: Add pretty printing for parsed representation. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=c53281cc8940b7c2f2a1f17453103792f44b404d;p=francis%2Fofc.git Add pretty printing for parsed representation. --- diff --git a/ofc.cabal b/ofc.cabal index b7d2160..c2fa95d 100644 --- a/ofc.cabal +++ b/ofc.cabal @@ -10,4 +10,4 @@ Executable ofc Main-is: Main.hs Hs-Source-Dirs: src GHC-Options: -Wall -fno-warn-missing-signatures - Build-Depends: base, containers, parsec >= 3 + Build-Depends: base, containers, parsec >= 3, pretty diff --git a/src/HighLevel.hs b/src/HighLevel.hs index e00f5b0..a1bbd00 100644 --- a/src/HighLevel.hs +++ b/src/HighLevel.hs @@ -1,6 +1,7 @@ module HighLevel where import TargetMapping -import Data.Map as Map (Map, lookup, insertWithKey, empty) +import Text.PrettyPrint +import Data.Map as Map (Map, lookup, insertWithKey, assocs, empty) import Data.List (foldl') -- The top-level types @@ -40,7 +41,20 @@ data OFL = OFL { symbols :: SymbolTable, assignments :: [Assignment], targetMappings :: MappingTable -} deriving Show +} + +toDoc :: OFL -> Doc +toDoc ofl = symbolDoc $$ assignmentsDoc $$ targetMappingsDoc + where + symbolDoc = text "Symbol table:" + $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assocs $ symbols ofl]) + assignmentsDoc = text "Assignments: " + $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assignments ofl]) + targetMappingsDoc = text "Target properties: " + $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assocs $ targetMappings ofl]) + +instance Show OFL where + show ofl = renderStyle Style {mode = PageMode, lineLength=10, ribbonsPerLine=1.5 } $ toDoc ofl -- Symbol table manipulators addValueDeclaration :: OFL -> String -> BaseType -> [IndexType] -> OFL