-- | Construct for decorating expressions with additional informationmoduleLanguage.Syntactic.Constructs.DecorationwhereimportData.TreeimportLanguage.Syntactic---------------------------------------------------------------------------------- * Decoration---------------------------------------------------------------------------------- | Decorating symbols with additional information---- One usage of 'Decor' is to decorate every node of a syntax tree. This is done-- simply by changing---- > AST dom sig---- to---- > AST (Decor info dom) sig---- Injection\/projection of an decorated tree is done using 'injDecor' \/-- 'prjDecor'.dataDecorinfoexprsigwhereDecor::{decorInfo::info(DenResultsig),decorExpr::exprsig}->DecorinfoexprsiginstanceConstrainedexpr=>Constrained(Decorinfoexpr)wheretypeSat(Decorinfoexpr)=SatexprexprDict(Decor_a)=exprDictainstanceProjectsubsup=>Projectsub(Decorinfosup)whereprj=prj.decorExprinstanceEqualityexpr=>Equality(Decorinfoexpr)whereequalab=decorExpra`equal`decorExprbexprHash=exprHash.decorExprinstanceRenderexpr=>Render(Decorinfoexpr)whererenderArgsargs=renderArgsargs.decorExprrender=render.decorExprinstanceToTreeexpr=>ToTree(Decorinfoexpr)wheretoTreeArgsargs=toTreeArgsargs.decorExprinstanceEvalexpr=>Eval(Decorinfoexpr)whereevaluate=evaluate.decorExprinjDecor::(sub:<:sup)=>info(DenResultsig)->subsig->AST(Decorinfosup)siginjDecorinfo=Sym.Decorinfo.injprjDecor::(sub:<:sup)=>AST(Decorinfosup)sig->Maybe(info(DenResultsig),subsig)prjDecora=doSym(Decorinfob)<-returnac<-prjbreturn(info,c)-- | Get the decoration of the top-level nodegetInfo::AST(Decorinfodom)sig->info(DenResultsig)getInfo(Sym(Decorinfo_))=infogetInfo(f:$_)=getInfof-- | Update the decoration of the top-level nodeupdateDecor::forallinfodoma.(infoa->infoa)->ASTF(Decorinfodom)a->ASTF(Decorinfodom)aupdateDecorf=matchupdatewhereupdate::(a~DenResultsig)=>Decorinfodomsig->Args(AST(Decorinfodom))sig->ASTF(Decorinfodom)aupdate(Decorinfoa)args=appArgs(Symsym)argswheresym=Decor(finfo)a-- | Lift a function that operates on expressions with associated information to-- operate on an 'Decor' expression. This function is convenient to use together-- with e.g. 'queryNodeSimple' when the domain has the form-- @(`Decor` info dom)@.liftDecor::(exprs->info(DenResults)->b)->(Decorinfoexprs->b)liftDecorf(Decorinfoa)=fainfo-- | Collect the decorations of all nodescollectInfo::(forallsig.infosig->b)->AST(Decorinfodom)sig->[b]collectInfocoll(Sym(Decorinfo_))=[collinfo]collectInfocoll(f:$a)=collectInfocollf++collectInfocolla-- | Rendering of decorated syntax treestoTreeDecor::forallinfodoma.(Renderinfo,ToTreedom)=>ASTF(Decorinfodom)a->TreeStringtoTreeDecora=mkTree[]awheremkTree::[TreeString]->AST(Decorinfodom)sig->TreeStringmkTreeargs(Sym(Decorinfoexpr))=NodeinfoStr[toTreeArgsargsexpr]whereinfoStr="<<"++renderinfo++">>"mkTreeargs(f:$a)=mkTree(mkTree[]a:args)f-- | Show an decorated syntax tree using ASCII artshowDecor::(Renderinfo,ToTreedom)=>ASTF(Decorinfodom)a->StringshowDecor=drawTree.toTreeDecor-- | Print an decorated syntax tree using ASCII artdrawDecor::(Renderinfo,ToTreedom)=>ASTF(Decorinfodom)a->IO()drawDecor=putStrLn.showDecor-- | Strip decorations from an 'AST'stripDecor::AST(Decorinfodom)sig->ASTdomsigstripDecor(Sym(Decor_a))=SymastripDecor(f:$a)=stripDecorf:$stripDecora