Commit e4674557 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Fix whitespace

parent d970ad3c
......@@ -3,26 +3,29 @@ module MA.PartitionPrinter
, printPartition
, writePartition
, showPartition
) where
)
where
import Data.Foldable
import Data.List (intersperse)
import qualified Data.HashMap.Strict as M
import Data.IntSet (IntSet)
import qualified Data.IntSet as S
import Data.Text (Text)
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Builder (Builder)
import qualified Data.Text.Lazy.Builder as Build
import qualified Data.Text.Lazy.Builder.Int as Build
import qualified Data.Text.Lazy.IO as TLazyIO
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
import Data.Partition (Partition, State)
import qualified Data.Partition as Partition
import MA.Coalgebra.Parser (SymbolTable(..))
import Data.List ( intersperse )
import qualified Data.HashMap.Strict as M
import Data.IntSet ( IntSet )
import qualified Data.IntSet as S
import Data.Text ( Text )
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Builder ( Builder )
import qualified Data.Text.Lazy.Builder as Build
import qualified Data.Text.Lazy.Builder.Int as Build
import qualified Data.Text.Lazy.IO as TLazyIO
import Data.MorphismEncoding ( Encoding )
import qualified Data.MorphismEncoding as Encoding
import Data.Partition ( Partition
, State
)
import qualified Data.Partition as Partition
import MA.Coalgebra.Parser ( SymbolTable(..) )
import MA.FunctorExpression.Sorts
......@@ -37,42 +40,48 @@ printPartition :: Encoding a (Sorted h1) -> SymbolTable -> Partition -> IO ()
printPartition enc symTab part =
TLazyIO.putStr (Build.toLazyText (formatPartition enc symTab part))
writePartition :: FilePath -> Encoding a (Sorted h1) -> SymbolTable -> Partition -> IO ()
writePartition
:: FilePath -> Encoding a (Sorted h1) -> SymbolTable -> Partition -> IO ()
writePartition file enc symTab part =
TLazyIO.writeFile file (Build.toLazyText (formatPartition enc symTab part))
showPartition :: Encoding a (Sorted h1) -> SymbolTable -> Partition -> Text
showPartition enc symTab part =
TL.toStrict (Build.toLazyText (formatPartition enc symTab part))
formatPartition :: Encoding a (Sorted h1) -> SymbolTable -> Partition -> Builder
formatPartition encoding symbolTable partition =
let blocks = Partition.toBlocks partition
sort1 = statesWithSort1 encoding
sort1 = statesWithSort1 encoding
restrictedBlocks = restrictBlocks blocks sort1
in foldMap (uncurry (formatBlock symbolTable)) (zip [0..] restrictedBlocks)
in foldMap (uncurry (formatBlock symbolTable)) (zip [0 ..] restrictedBlocks)
formatBlock :: SymbolTable -> Int -> [State] -> Builder
formatBlock (SymbolTable symbolTable) num states =
"Block " <> Build.decimal num <> ": "
<> (fold (intersperse ", " (map formatState states)))
<> "\n"
"Block "
<> Build.decimal num
<> ": "
<> (fold (intersperse ", " (map formatState states)))
<> "\n"
where
formatState x =
case M.lookup x symbolTable of
Nothing ->
error $
"formatBlock: State " ++
show x ++ " has no name (this should not happen)"
Just name -> Build.fromText name
formatState x = case M.lookup x symbolTable of
Nothing ->
error
$ "formatBlock: State "
++ show x
++ " has no name (this should not happen)"
Just name -> Build.fromText name
statesWithSort1 :: Encoding a (Sorted h1) -> IntSet
statesWithSort1 enc =
S.filter
((1 ==) . sortedSort . Encoding.typeOf enc)
(S.fromList (Encoding.states enc))
statesWithSort1 enc = S.filter ((1 ==) . sortedSort . Encoding.typeOf enc)
(S.fromList (Encoding.states enc))
restrictBlocks :: [[State]] -> IntSet -> [[State]]
restrictBlocks blocks sort1 = filter (not . null) (map (filter isSort1) blocks)
where
isSort1 x = S.member x sort1
where isSort1 x = S.member x sort1
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