1 {-# LANGUAGE UndecidableInstances #-}
2 -- | Interpreter to serialize an expression into a 'Text'.
3 module Language.Symantic.Interpreting.View where
5 import Data.Text (Text)
6 import qualified Data.Text as Text
7 import Prelude hiding (Integral(..))
9 import Language.Symantic.Grammar
13 -- | Interpreter's data.
16 { unView -- Inherited attributes:
19 -- Synthetised attributes:
23 instance Show (View a) where
24 show = Text.unpack . view
27 view :: View a -> Text
28 view r = unView r (infixN0, SideL) 0
31 view0 :: Text -> View a
32 view0 name = View $ \_op _v -> name
34 view1 :: Text -> View a1 -> View a
35 view1 name (View a1) = View $ \po v ->
43 view2 :: Text -> View a1 -> View a2 -> View a
44 view2 name (View a1) (View a2) =
54 view3 :: Text -> View a1 -> View a2 -> View a3 -> View a
55 view3 name (View a1) (View a2) (View a3) =
66 viewInfix :: Text -> Infix -> View a1 -> View a2 -> View a
67 viewInfix name op (View a1) (View a2) =