1 {-# LANGUAGE UndecidableInstances #-}
2 -- | Interpreter to serialize an expression into a 'Text'.
3 module Language.Symantic.Interpreting.Text where
5 import Data.Text (Text)
6 import qualified Data.Text as Text
7 import Prelude hiding (Integral(..))
9 import Language.Symantic.Parsing.Grammar
13 -- | Interpreter's data.
16 { unTextI -- Inherited attributes:
19 -- Synthetised attributes:
22 type TextI_Lambda_Depth = Int
23 instance Show (TextI h) where
24 show = Text.unpack . text_from_term
27 text_from_term :: TextI h -> Text
28 text_from_term r = unTextI r (infixN0, L) 0
32 -- ** Helpers for lambda applications
33 textI0 :: Text -> TextI h
34 textI0 name = TextI $ \_op _v -> name
35 textI1 :: Text -> TextI a1 -> TextI h
36 textI1 name (TextI a1) = TextI $ \po v ->
43 textI2 :: Text -> TextI a1 -> TextI a2 -> TextI h
44 textI2 name (TextI a1) (TextI a2) =
53 textI3 :: Text -> TextI a1 -> TextI a2 -> TextI a3 -> TextI h
54 textI3 name (TextI a1) (TextI a2) (TextI a3) =
65 textI_infix :: Text -> Infix -> TextI a1 -> TextI a2 -> TextI h
66 textI_infix name op (TextI a1) (TextI a2) =