Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Software
CoPaR
Commits
3b06bce9
Commit
3b06bce9
authored
Nov 16, 2020
by
Bastian Kauschke
Browse files
deduplicate coalgebra printing
parent
139877fb
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/Copar/CoalgebraPrinter.hs
View file @
3b06bce9
{-# 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
))
...
...
src/main/Main.hs
View file @
3b06bce9
...
...
@@ -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
...
...
tests/Examples.hs
View file @
3b06bce9
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment