(: tools to analyse xml parse tree @author Andy Bunce :) module namespace hnd="lsp/handlers"; import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm"; declare record hnd:hand( result as item()*, skipchildren as xs:boolean ); declare function hnd:default-handler($el as element(*),$state) as function(*){ fn(){hnd:hand($state,false())} }; declare function hnd:get-handler($el as element(*),$state) as function(*) { function-lookup(xs:QName(name($el)),2) otherwise hnd:default-handler($el,$state) }; declare function hnd:diags($parse as element(),$diags:=()) { let $_:=trace(($parse,$diags),"diags") let $h:= hnd:get-handler($parse,$diags) let $walk:=$h($parse,$diags) return if($walk?skipchildren) then $walk?result else fold-left($parse/*,$diags, fn($r,$this){ hnd:diags($this,$r) }) }; declare function hnd:symbols($parse as element(),$syms as lspt:symbol* :=() ) { 'todo' }; declare function hnd:anotated-declaration($parse as element(),$syms) as hnd:hand { let $sym:=lspt:symbol( $parse/token, "AA" ) return hnd:hand(($syms,$sym),true()) };