module Text.Syntax.Check.Prim (
printParseIso0, printParseIso,
printParseIso0Default, printParseIsoDefault
) where
import Text.Syntax.Poly.Type (SyntaxT, RunAsParser, RunAsPrinter)
import Text.Syntax.Printer.List (runAsPrinter)
import Text.Syntax.Parser.List.LazyMaybe (runAsParser)
printParseIso0 :: (Eq a, Show e0, Show e1) =>
RunAsPrinter tok tks a e0 -> RunAsParser tok tks a e1 ->
SyntaxT tok a -> a -> Either String a
printParseIso0 runPrint runParse syntax tree0 =
do tks <- either (Left . show) Right $ runPrint syntax tree0
tree1 <- either (Left . show) Right $ runParse syntax tks
if tree0 == tree1
then Right tree0
else Left "not isomorphism"
printParseIso :: (Eq a, Show e0, Show e1) =>
RunAsPrinter tok tks a e0 -> RunAsParser tok tks a e1
-> SyntaxT tok a -> tks -> Either String a
printParseIso runPrint runParse syntax tks0 =
do tree0 <- either (Left . show) Right $ runParse syntax tks0
printParseIso0 runPrint runParse syntax tree0
printParseIso0Default :: (Eq tok, Eq a) => SyntaxT tok a -> a -> Either String a
printParseIso0Default = printParseIso0 runAsPrinter runAsParser
printParseIsoDefault :: (Eq tok, Eq a) => SyntaxT tok a -> [tok] -> Either String a
printParseIsoDefault = printParseIso runAsPrinter runAsParser