(: 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 variable hnd:actions:={ } declare record hnd:Hand( result as item()*, skipchildren? as xs:boolean:=false() ); declare function hnd:handle($el as element(*),$state) { let $f:= function-lookup(xs:QName(name($el)=>trace("SSS")),2) otherwise fn($el,$state){hnd:Hand($state,false())} return $f($el,$state) }; declare function hnd:diags($parse as element(),$diags:=()) { let $_:=trace((name($parse),$diags),"diags") let $walk:= hnd:handle($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()) };