import Data.Monoid (Monoid(..))
import Data.Semigroup (Semigroup(..))
import Data.String (IsString(..))
-import GHC.TypeLits (symbolVal)
+import Text.Show (Show(..))
import qualified Data.Functor as Functor
import qualified Data.HashMap.Strict as HM
import qualified Data.List as List
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TLB
-import Symantic.Univariant.Letable
+import Symantic.Typed.ObserveSharing
+import Symantic.Typed.Fixity
import Symantic.Parser.Grammar.Combinators
-import Symantic.Parser.Grammar.Fixity
-- * Type 'WriteGrammar'
newtype WriteGrammar (showName::Bool) a = WriteGrammar { unWriteGrammar ::
else s
where (o,c) = writeGrammarInh_pair inh
+instance CombAlternable (WriteGrammar sN) where
+ alt exn x y = WriteGrammar $ \inh ->
+ pairWriteGrammarInh inh op $
+ unWriteGrammar x inh
+ { writeGrammarInh_op = (op, SideL)
+ , writeGrammarInh_pair = pairParen
+ } <>
+ Just (" |^"<>fromString (show exn)<>" ") <>
+ unWriteGrammar y inh
+ { writeGrammarInh_op = (op, SideR)
+ , writeGrammarInh_pair = pairParen
+ }
+ where op = infixB SideL 3
+ throw exn = WriteGrammar $ \inh ->
+ pairWriteGrammarInh inh op $
+ Just ("throw "<>fromString (show exn))
+ where
+ op = infixN 9
+ failure _sf = "failure"
+ empty = "empty"
+ try x = WriteGrammar $ \inh ->
+ pairWriteGrammarInh inh op $
+ Just "try " <> unWriteGrammar x inh
+ where
+ op = infixN 9
instance CombApplicable (WriteGrammar sN) where
pure _ = WriteGrammar $ return Nothing
-- pure _ = "pure"
Just $ xt <> ", " <> yt
where
op = infixN 1
-instance CombAlternable (WriteGrammar sN) where
- empty = "empty"
- try x = WriteGrammar $ \inh ->
- pairWriteGrammarInh inh op $
- Just "try " <> unWriteGrammar x inh
- where
- op = infixN 9
- x <|> y = WriteGrammar $ \inh ->
- pairWriteGrammarInh inh op $
- unWriteGrammar x inh
- { writeGrammarInh_op = (op, SideL)
- , writeGrammarInh_pair = pairParen
- } <>
- Just " | " <>
- unWriteGrammar y inh
- { writeGrammarInh_op = (op, SideR)
- , writeGrammarInh_pair = pairParen
- }
- where op = infixB SideL 3
instance CombFoldable (WriteGrammar sN) where
chainPre f x = WriteGrammar $ \inh ->
pairWriteGrammarInh inh op $
where
op = infixN 9
instance CombSatisfiable tok (WriteGrammar sN) where
- satisfy _es _f = "satisfy"
+ satisfyOrFail _fs _f = "satisfy"
instance CombSelectable (WriteGrammar sN) where
branch lr l r = WriteGrammar $ \inh ->
pairWriteGrammarInh inh op $
unWriteGrammar r inh
where
op = infixN 9
-instance CombThrowable (WriteGrammar sN) where
- throw lbl = WriteGrammar $ \inh ->
- pairWriteGrammarInh inh op $
- Just ("throw "<>fromString (symbolVal lbl))
- where
- op = infixN 9