Commit 0f864c7a authored by Bastian Kauschke's avatar Bastian Kauschke
Browse files

add config argument to `Printable.printMe`

parent 6e30c68a
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
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, printMe (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"
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