Skip to content
GitLab
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
0f864c7a
Commit
0f864c7a
authored
May 11, 2020
by
Bastian Kauschke
Browse files
add config argument to `Printable.printMe`
parent
6e30c68a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Copar/FunctorExpression/Printable.hs
View file @
0f864c7a
module
Copar.FunctorExpression.Printable
(
Printable
(
..
)
,
PrintConfig
(
..
)
,
printTree
,
sortAsScope
)
where
...
...
@@ -35,5 +36,7 @@ printInner f (((scope, v):h):rs) =
printInner
f
(
[]
:
rs
)
=
printInner
f
rs
printInner
_
[]
=
mempty
data
PrintConfig
=
PrintConfig
{
withName
::
Build
.
Builder
->
Build
.
Builder
}
class
Printable
f
where
printMe
::
f
Build
.
Builder
->
Build
.
Builder
printMe
::
PrintConfig
->
f
Build
.
Builder
->
Build
.
Builder
src/Copar/FunctorPrinter.hs
View file @
0f864c7a
module
Copar.FunctorPrinter
(
printFunctor
,
Printable
)
where
module
Copar.FunctorPrinter
(
printFunctor
,
printParseableFunctor
,
Printable
)
where
import
Data.Text
as
T
import
Data.Text.Lazy
as
Lazy
...
...
@@ -10,18 +10,30 @@ import Copar.FunctorExpression.Type (FunctorExpression (..))
printFunctor
::
(
Printable
f
,
Foldable
f
,
Functor
f
)
=>
FunctorExpression
f
Sort
->
T
.
Text
printFunctor
(
Functor
_
f'
)
=
Lazy
.
toStrict
(
Build
.
toLazyText
(
printTree
inner
f'
))
printFunctor
Variable
=
"Variable X"
inner
::
(
Printable
f
,
Foldable
f
,
Functor
f
)
=>
f
(
FunctorExpression
f
Sort
)
-- ([('sort, subfunctor)], functor)
->
([(
Build
.
Builder
,
f
(
FunctorExpression
f
Sort
))],
Build
.
Builder
)
inner
f
=
(
foldMap
getChild
f
,
print
Me
(
fmap
printChild
f
))
inner
f
=
(
foldMap
getChild
f
,
print
(
fmap
printChild
f
))
where
print
=
printMe
PrintConfig
{
withName
=
\
name
->
name
<>
" "
}
printChild
Variable
=
"X"
printChild
(
Functor
sort
_
)
=
sortAsScope
sort
getChild
Variable
=
[]
getChild
(
Functor
sort
f'
)
=
[(
sortAsScope
sort
,
f'
)]
printParseableFunctor
::
(
Printable
f
,
Foldable
f
,
Functor
f
)
=>
FunctorExpression
f
Sort
->
T
.
Text
printParseableFunctor
(
Functor
_
f'
)
=
Lazy
.
toStrict
(
Build
.
toLazyText
(
print
(
fmap
printInner
f'
)))
where
print
::
forall
f
.
(
Printable
f
)
=>
f
Build
.
Builder
->
Build
.
Builder
print
=
printMe
PrintConfig
{
withName
=
\
_
->
""
}
printInner
::
(
Printable
f
,
Foldable
f
,
Functor
f
)
=>
FunctorExpression
f
Sort
->
Build
.
Builder
printInner
Variable
=
"X"
printInner
(
Functor
_
inner
)
=
"("
<>
print
(
fmap
printInner
inner
)
<>
")"
printParseableFunctor
Variable
=
"X"
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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