Commit 3b06bce9 authored by Bastian Kauschke's avatar Bastian Kauschke
Browse files

deduplicate coalgebra printing

parent 139877fb
{-# LANGUAGE AllowAmbiguousTypes #-}
module Copar.CoalgebraPrinter (printEncoding) where
module Copar.CoalgebraPrinter (printCoalgebra, printEncoding) where
import Control.Monad.ST
import qualified Data.HashMap.Strict as HM
......@@ -14,10 +14,22 @@ import qualified Data.Vector.Utils as V
import qualified Data.List as List
import Data.Maybe (fromJust)
import Copar.FunctorExpression.Type (FunctorExpression (..))
import Copar.FunctorExpression.Sorts (Sort, sortTable)
import Copar.FunctorExpression.Desorting
import Copar.Coalgebra.Parser
import Copar.Coalgebra.Printer
import Copar.RefinementInterface
import Copar.Functors.SomeFunctor
import Copar.FunctorPrinter (printParseableFunctor)
printCoalgebra :: FunctorExpression SomeFunctor Sort
-> Encoding (Label (Desorted SomeFunctor)) (F1 (Desorted SomeFunctor))
-> SymbolTable -> Build.Builder
printCoalgebra f encoding symbols =
Build.fromText (printParseableFunctor f) <>
"\n\n" <>
(printEncoding encoding symbols (sortTable f))
printEncoding :: forall f. (ParseMorphism f, PrintMorphism f)
=> Encoding (Label (Desorted f)) (F1 (Desorted f))
......
......@@ -33,7 +33,7 @@ import Copar.FunctorPrinter
import Copar.Functors
import Copar.FunctorDescription
import qualified Data.CoalgebraEncoding as Encoding
import Copar.FunctorExpression.Sorts (Sort, sortedSort, sortTable)
import Copar.FunctorExpression.Sorts (Sort, sortedSort)
import qualified Data.Partition as Partition
import Copar.Functors.SomeFunctor (SomeFunctor)
import Copar.FunctorExpression.Type (FunctorExpression (..))
......@@ -476,9 +476,7 @@ main = do
evaluate (minimize f encoding symbolTable part)
withTimeStat stats "output-duration" $ do
T.putStrLn $ printParseableFunctor f
T.putStrLn ""
LT.putStrLn $ Build.toLazyText $ printEncoding encoding' symbolTable' (sortTable f)
LT.putStrLn $ Build.toLazyText $ printCoalgebra f encoding' symbolTable'
finalizeStats stats
(GraphCommand r) -> do
(_, (symbolTable, encoding)) <- do
......@@ -510,9 +508,7 @@ main = do
Left err -> hPutStrLn stderr err >> exitFailure
Right res -> evaluate res
T.putStrLn $ printParseableFunctor f
T.putStrLn ""
LT.putStrLn $ Build.toLazyText $ printEncoding encoding symbolTable (sortTable f)
LT.putStrLn $ Build.toLazyText $ printCoalgebra f encoding symbolTable
helpOverview :: Text -> Doc AnsiStyle
......
......@@ -95,10 +95,7 @@ testFileMinimize mini =
let
(enc', symTab') = minimize f enc symTab part
return (LT.unpack . Build.toLazyText $ Build.fromText (printParseableFunctor f)
<> "\n\n"
<> printEncoding enc' symTab' (sortTable f)
<> "\n")
return (LT.unpack . Build.toLazyText $ printCoalgebra f enc' symTab' <> "\n")
testFileMinimizeIdentity :: FilePath -> Spec
testFileMinimizeIdentity file =
......@@ -111,9 +108,7 @@ testFileMinimizeIdentity file =
let
(enc', symTab') = minimize f enc symTab part
coalgebra = Build.fromText (printParseableFunctor f)
<> "\n\n"
<> printEncoding enc' (anonymizeSymbols symTab') (sortTable f)
coalgebra = printCoalgebra f enc' (anonymizeSymbols symTab')
reparsed = P.parseCoalgebra P.defaultConfig "(minimized)" $ LT.toStrict (Build.toLazyText coalgebra)
case reparsed of
......@@ -123,7 +118,4 @@ testFileMinimizeIdentity file =
let
(enc''', symTab''') = minimize f' enc'' symTab'' part'
Build.fromText (printParseableFunctor f)
<> "\n\n"
<> (printEncoding enc''' (anonymizeSymbols symTab''') (sortTable f')) `shouldBe`
coalgebra
printCoalgebra f' enc''' (anonymizeSymbols symTab''') `shouldBe` coalgebra
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment