[add] railroad generation

This commit is contained in:
Andy Bunce 2025-10-03 15:27:41 +01:00
parent d26fae56e4
commit f867836ddf
11 changed files with 18682 additions and 1324 deletions

View file

@ -3,29 +3,29 @@
:)
module namespace hnd="lsp/handlers";
import module namespace lspt = 'lsp-typedefs' at "lsp-typedefs.xqm";
declare variable hnd:actions:={
}
declare record hnd:hand(
declare record hnd:Hand(
result as item()*,
skipchildren as xs:boolean
skipchildren? as xs:boolean:=false()
);
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: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(($parse,$diags),"diags")
let $h:= hnd:get-handler($parse,$diags)
let $walk:=$h($parse,$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,
@ -42,12 +42,12 @@ declare function hnd:symbols($parse as element(),$syms as lspt:symbol* :=() )
};
declare function hnd:anotated-declaration($parse as element(),$syms)
as hnd:hand
as hnd:Hand
{
let $sym:=lspt:symbol(
$parse/token,
"AA"
)
return hnd:hand(($syms,$sym),true())
return hnd:Hand(($syms,$sym),true())
};

View file

@ -19,6 +19,8 @@ declare variable $lsp-text:methods:=map{
"textDocument/documentSymbol" : lsp-text:symbols#1
};
declare variable lsp-text:word-reg:="[A-Z]|_|[a-z]|[À-Ö]|[Ø-ö]|[ø-˿]|[Ͱ-ͽ]|[Ϳ-῿]|[-]|[⁰-↏]|[Ⰰ-⿯]|[、-퟿]|[豈-﷏]|[ﷰ-<2D>]";
(:~ hover :)
declare
function lsp-text:hover($json as map(*))

View file

@ -7,7 +7,8 @@ declare record text:rec(
lines as xs:string+,
separator? as xs:string:=file:line-separator(),
text? as fn() as xs:string:= %method fn () { string-join(?lines,?separator) },
line? := %method fn($line) {?lines[$line]}
line? := %method fn($line) {?lines[$line]},
length? as xs:integer
);
(:~ json numbers :)
@ -30,6 +31,8 @@ declare record text:Range(
start as text:Position,
end as text:Position
);
(: create new text from string :)
declare function text:build($text as xs:string){
let $lines:=tokenize($text, '(\r\n?|\n\r?)')
return text:rec($lines)