{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE ViewPatterns #-}
module Language.RNC.Write where
import Control.Applicative (Applicative(..))
import Control.Monad
+import Data.Bool
import Data.Functor.Compose (Compose(..))
import Data.Semigroup hiding (option)
import Data.Text (Text)
import Prelude hiding (any)
import qualified Data.Text as Text
+import qualified Data.List as List
import Language.RNC.Sym
import Language.RNC.Fixity
pure _ = writeText $ "\"\""
Writer f <*> Writer x = Writer $ \rm po pp ->
pairInfix pp po op $
- f rm (op, SideL) pp <> ", " <> x rm (op, SideR) pp
+ Text.intercalate ", " $
+ List.filter (not . Text.null) $
+ [ f rm (op, SideL) pp
+ , x rm (op, SideR) pp ]
where op = infixB SideL 10
instance Sym_Rule Writer where
rule n (Writer w) = Writer $ \rm po pp ->
Compose (Writer . unWriter <$> ws <>
[Writer $ unWriter $ many $ Writer w])
instance Sym_RNC Writer where
- position (Writer w) = Writer w
element n (Writer w) = Writer $ \rm po pp ->
pairInfix pp po op $
"element \""<>Text.pack (show n)<>"\" "<>w rm (op,SideR) PairBrace