{-# language OverloadedStrings #-} {-# language QuasiQuotes #-} module TPDB.XTC.Write ( document , writeFile, renderLBS, renderText, def ) where import qualified TPDB.Data as D import qualified Data.Map as M import qualified Data.Text as T import qualified Text.XML as X import Prelude hiding (writeFile) import Text.XML (writeFile,renderLBS,renderText) import Text.Hamlet.XML import Data.Default (def) document :: D.Problem D.Identifier D.Identifier -> X.Document document p = X.Document (X.Prologue [] Nothing []) root [] where root = X.Element "problem" (M.fromList [("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance") ,("type","termination") ,("xsi:noNamespaceSchemaLocation","http://dev.aspsimon.org/xtc.xsd") ]) [xml| ^{trs $ D.trs p} $maybe s <- D.strategy p ^{strategy s} |] strategy s = case s of D.Full -> [xml|FULL|] trs :: D.TRS D.Identifier D.Identifier -> [X.Node] trs rs = [xml| $forall u <- D.rules rs ^{term $ D.lhs u} ^{term $ D.rhs u} $forall f <- D.signature rs #{T.pack $ show f} #{T.pack $ show $ D.arity f} |] term :: D.Term D.Identifier D.Identifier -> [X.Node] term t = case t of D.Var v -> [xml| #{T.pack $ show v} |] D.Node f args -> [xml| #{T.pack $ show f} $forall arg <- args ^{term arg} |]