-- | textual input,-- cf. <http://www.lri.fr/~marche/tpdb/format.html>{-# language PatternSignatures, TypeSynonymInstances, FlexibleInstances #-}moduleTPDB.Plain.ReadwhereimportTPDB.DataimportText.ParsecimportText.Parsec.TokenimportText.Parsec.LanguageimportText.Parsec.CharimportControl.Monad(guard,void)trs::String->EitherString(TRSIdentifierIdentifier)trss=caseText.Parsec.parsereader"input"sofLefterr->Left$showerrRightt->Righttsrs::String->EitherString(SRSIdentifier)srss=caseText.Parsec.parsereader"input"sofLefterr->Left$showerrRightt->RightttypeParser=ParsecString()classReaderawherereader::Parsera-- | warning: by definition, {}[] may appear in identifierslexer=makeTokenParser$emptyDef{identStart=alphaNum<|>oneOf"_:!#$%&*+./<=>?@\\^|-~{}[]",identLetter=alphaNum<|>oneOf"_:!#$%&*+./<=>?@\\^|-~{}[]",commentLine="",commentStart="",commentEnd="",reservedNames=["VAR","THEORY","STRATEGY","RULES","->","->="]}instanceReaderIdentifierwherereader=doi<-identifierlexerreturn$Identifier{arity=0,name=i}instanceReaders=>Reader[s]wherereader=manyreader-- NOTE: this is dangerous since we read the variables as constants,-- and this needs to be patched up later.-- NOTE: this is more dangerous as we do not set the arity of identifiersinstance(Readerv,Readers)=>Reader(Termvs)wherereader=dof<-readerxs<-option[]$parenslexer$commaSeplexerreaderreturn$NodefxsinstanceReaderu=>Reader(Ruleu)wherereader=dol<-readers<-doreservedOplexer"->";returnTrue<|>doreservedOplexer"->=";returnFalser<-readerreturn$Rule{lhs=l,strict=s,top=False,rhs=r}dataDeclarationu=Var_Declaration[Identifier]|Theory_Declaration|Strategy_Declaration|Rules_Declaration[Ruleu]|Unknown_Declaration-- ^ this is super-ugly: a parenthesized, possibly nested, -- possibly comma-separated, list of identifiers or stringsdeclaration::Readeru=>Bool->Parser(Declarationu)declarationsep=parenslexer$doreservedlexer"VAR";xs<-manyreaderreturn$Var_Declarationxs<|>doreservedlexer"THEORY"error"TPDB.Plain.Read: parser for THEORY decl. missing"<|>doreservedlexer"STRATEGY"error"TPDB.Plain.Read: parser for THEORY decl. missing"<|>doreservedlexer"RULES"us<-(ifsepthencommaSeplexerelsemany)readerreturn$Rules_Declarationus<|>doanylist;returnUnknown_Declarationanylist=void$commaSeplexer$many(void(identifierlexer)<|>parenslexeranylist)instanceReader(SRSIdentifier)wherereader=dods<-many$declarationTruereturn$make_srsdsinstanceReader(TRSIdentifierIdentifier)wherereader=dods<-many$declarationFalsereturn$make_trsdsmake_srs::[Declaration[s]]->SRSsmake_srsds=letus=doRules_Declarationus<-ds;usinRS{signature=[],rules=us,separate=True}make_trs::[Declaration(TermIdentifierIdentifier)]->TRSIdentifierIdentifiermake_trsds=letvs=doVar_Declarationvs<-ds;vsus=doRules_Declarationus<-ds;usus'=repair_variablesvsusinRS{signature=[],rules=us',separate=False}repair_variablesvarsrules=doletxform(Nodec[])|c`elem`vars=Varcxform(Nodecargs)=Nodec(mapxformargs)rule<-rulesreturn$rule{lhs=xform$lhsrule,rhs=xform$rhsrule}