36 lines
925 B
Text
36 lines
925 B
Text
(: tools to analyse xml parse tree
|
|
@author Andy Bunce
|
|
:)
|
|
module namespace hnd="lsp/handlers";
|
|
|
|
|
|
(:~ structure returned by tree walkers :)
|
|
declare record hnd:Result(
|
|
result as item()*,
|
|
skipchildren? as xs:boolean:=false()
|
|
);
|
|
|
|
declare type hnd:actionFn as fn($parse as element(),$state as hnd:Result ) as hnd:Result;
|
|
|
|
declare type hnd:actionMap as map(xs:string,hnd:actionFn);
|
|
|
|
declare function hnd:walk($parse as element(),
|
|
$actions as hnd:actionMap,
|
|
$state as hnd:Result )
|
|
as hnd:Result
|
|
{
|
|
let $action:=$actions(name($parse))
|
|
let $result:= if(exists($action))
|
|
then $action($parse,$state)
|
|
else hnd:Result($state)
|
|
|
|
return if($result?skipchildren)
|
|
then $result
|
|
else fold-left(
|
|
$parse/*,$state,
|
|
fn($state,$this){hnd:walk($this, $actions, $state)}
|
|
)
|
|
};
|
|
|
|
|
|
|