(: tools to analyse xml parse tree @author Andy Bunce :) module namespace hnd="lsp/handlers"; import module namespace pos="lsp/position" at "position.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 record hnd:symbol ( name as xs:string, type as xs:string, range-name? as pos:Range, range-full? as pos:Range, children? as array(hnd:symbol) ); declare function hnd:symbols($parse as element(),$syms as hnd:symbol* :=() ) { 'todo' }; declare function hnd:anotated-declaration($parse as element(),$syms) as hnd:hand { let $sym:=hnd:symbol( $parse/token, "AA" ) return hnd:hand(($syms,$sym),true()) };