[add] initial handler stuff

This commit is contained in:
Andy Bunce 2025-09-07 22:04:53 +01:00
parent 7deb653208
commit 9533519b8a
10 changed files with 284 additions and 187 deletions

56
webapp/lsp/handlers.xqm Normal file
View file

@ -0,0 +1,56 @@
(: 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 $h:= hnd:get-handler($parse,$diags)($parse,$diags)
return if($h?skipchildren)
then $h?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())
};