[mod] update

This commit is contained in:
Andy Bunce 2025-11-12 22:45:05 +00:00
parent ddd772f563
commit cd369cd51e
11 changed files with 429 additions and 220 deletions

View file

@ -13,6 +13,8 @@ import module namespace p = 'Thyme' at "Thyme.xqm";
declare namespace th="http://www.thymeleaf.org";
declare namespace layout="http://www.ultraq.net.nz/thymeleaf/layout";
declare variable $ore:debug:=false(); (: trace messages:)
declare variable $ore:default-options:=map{"base": file:base-dir(),
"layout": true(),
"indent": "no"
@ -23,7 +25,8 @@ declare function ore:render($view as xs:string,$opts as map(*),$model as map(*))
as document-node(){
let $opts:=map:merge(($opts,$ore:default-options))
let $doc:=(ore:doc($view,$opts)
,message($model,"£ RENDER MODEL(" || $view ||"): "))
,message($model,"£ RENDER MODEL(" || $view ||"): ")
)
let $a:= ore:update($doc,$opts,$model)
return ore:decorate($a,$opts)
};
@ -38,9 +41,9 @@ declare function ore:update($doc ,$opts as map(*),$model as map(*))
replace node $each with (
for $item in map:get($model,substring-after($p,","))
let $model2:=map:put($model,substring-before($p,","),$item)
(:=>trace("MODEL2:"):)
(:=>ore:trace("MODEL2:"):)
let $x:=ore:update($each,$opts,$model2)
return $x (:=>trace("DD: "):)
return $x (:=>ore:trace("DD: "):)
))
,delete node @th:each
)
@ -62,10 +65,10 @@ declare %updating function ore:update-attrib($context as node(),$name as xs:stri
as empty-sequence(){
for $at in $context//*/@th:*[local-name(.) eq $name]
where not($at/ancestor::*/@th:each)
let $target:=$at/../@*[name() eq $name]=>trace("£ target: ")
let $target:=$at/../@*[name() eq $name]=>ore:trace("£ target: ")
return (
replace value of node $target with
ore:expression($at, $model)=>trace("£ ore:expression: ")
ore:expression($at, $model)=>ore:trace("£ ore:expression: ")
,delete node $at
)
};
@ -73,7 +76,7 @@ for $at in $context//*/@th:*[local-name(.) eq $name]
(: load doc from base folder:)
declare function ore:doc($file as xs:string,$opts as map(*))
as document-node(){
let $f:=file:resolve-path($file,$opts?base)=>trace("ore:doc")
let $f:=file:resolve-path($file,$opts?base)=>ore:trace("ore:doc")
return doc($f)
};
@ -113,7 +116,7 @@ as xs:string{
(:~ Return value of $atrib from model :)
declare function ore:expression($atrb as xs:string,$model as map(*))
as xs:string{
let $p:=ore:parse-text($atrb)=>trace("ore:expression: ")
let $p:=ore:parse-text($atrb)=>ore:trace("ore:expression: ")
let $exp:=substring-after($p,",")
return switch(substring-before($p,","))
@ -136,7 +139,7 @@ as xs:string{
declare function ore:expression-link($exp as xs:string)
as xs:string {
switch (true())
case starts-with($exp=>trace("EEEE: "), "http")
case starts-with($exp=>ore:trace("EEEE: "), "http")
case starts-with($exp, "//")
return $exp
case starts-with($exp, "/")
@ -233,3 +236,12 @@ as xs:string{
}
return string($s)
};
(:~ trace:)
declare function ore:trace($value as item()*, $label as xs:string)
as item()*
{
if($ore:debug)
then trace($value,$label)
else $value
};

View file

@ -9,7 +9,7 @@ declare variable $syms:actions as hnd:actionMap :={
"ContextValueDecl": syms:action#2,
"VarDecl": syms:VarDecl#2,
"FunctionDecl": syms:FunctionDecl#2,
"ItemTypeDecl": syms:action#2,
"ItemTypeDecl": syms:ItemTypeDecl#2,
"NamedRecordTypeDecl": syms:NamedRecordTypeDecl#2
};
@ -48,7 +48,6 @@ as hnd:State{
return $state
=>map:put("result",($state?result,$sym))
=>map:put("skipchildren",true())
};
declare function syms:FunctionDecl($parse as element(FunctionDecl),$state as hnd:State )
@ -63,6 +62,19 @@ as hnd:State{
=>map:put("skipchildren",true())
};
declare function syms:ItemTypeDecl($parse as element(ItemTypeDecl), $state as hnd:State )
as hnd:State{
let $name:=syms:localName($parse/EQName)
let $range:=pos:range-from-ast($parse/EQName,$state?extras?text)
let $full-range:=pos:range-from-ast($parse,$state?extras?text)
let $sym:=lspt:DocumentSymbol($name,$lspt:SymbolKindMap('TypeParameter'),$range,$full-range,"--TYPE")
=>trace("RECORD")
return $state
=>map:put("result",($state?result,$sym))
=>map:put("skipchildren",true())
};
declare function syms:NamedRecordTypeDecl($parse as element(NamedRecordTypeDecl), $state as hnd:State )
as hnd:State{
let $name:=syms:localName($parse/EQName)

83
webapp/lsp/set.xqm Normal file
View file

@ -0,0 +1,83 @@
module namespace set = "http://qt4cg.org/atomic-set";
(:
This package defines a type set:atomic-set which represents
a set of distinct atomic items. Atomic items are considered
distinct based on the comparison function fn:atomic-equal.
An instance of an atomic set can be constructed using a function
call such as set:build((1, 3, 5, 7, 9)).
If $A and $B are instances of set:atomic-set, then they
can be manipulated using methods including:
$A=?>size() - returns the number of items in the set
$A=?>empty() - returns true if the set is empty
$A=?>contains($k) - determines whether $k is a member of the set
$A=?>contains-all($B) - returns true if $B is a subset of $A
$A=?>values() - returns the items in $A, as a sequence
$A=?>add($k) - returns a new atomic set containing an additional item
$A=?>remove($k) - returns a new atomic set in which the given item is absent
$A=?>union($B) - returns a new atomic set holding the union of $A and $B
$A=?>intersect($B) - returns a new atomic set holding the intersection of $A and $B
$A=?>except($B) - returns a new atomic set holding the difference of $A and $B
:)
declare %public record set:atomic-set (
_data as map(xs:anyAtomicType, xs:boolean),
size as fn($set as set:atomic-set) as xs:integer,
empty as fn($set as set:atomic-set) as xs:boolean,
contains as fn($set as set:atomic-set, $value as xs:anyAtomicType) as xs:boolean,
contains-all as fn($set as set:atomic-set, $value as set:atomic-set) as xs:boolean,
add as fn($set as set:atomic-set, $item as xs:anyAtomicType) as set:atomic-set,
remove as fn($set as set:atomic-set, $item as xs:anyAtomicType) as set:atomic-set,
union as fn($set as set:atomic-set, $value as set:atomic-set) as set:atomic-set,
intersect as fn($set as set:atomic-set, $value as set:atomic-set) as set:atomic-set,
except as fn($set as set:atomic-set, $value as set:atomic-set) as set:atomic-set,
* );
declare %private variable DATA := "'_data'";
(:
The private function set:replaceData processes the internal map
by applying a supplied function, and returns a new atomic set
with the resulting internal map
:)
declare %private function set:replaceData (
$input as set:atomic-set,
$update as fn(map(*)) as map(*)) as map(xs:anyAtomicType, xs:boolean) {
map:put($input, $DATA, $update($input?$DATA))
}
declare %public function set:build (
$values as xs:anyAtomicType* := ()) {
{
_data:
map:build($values, values:=true#0, {'duplicates': 'use-first'}),
size: fn($set as set:atomic-set) as xs:integer
{ map:size($set?$DATA) },
empty: fn($set as set:atomic-set) as xs:boolean
{ map:empty($set?$DATA) },
contains: fn($set as set:atomic-set, $value as xs:anyAtomicType) as xs:boolean
{ map:contains($set?$DATA, $value) },
contains-all: fn($set as set:atomic-set, $other as set:atomic-set) as xs:boolean
{ every($other, map:contains($set?$DATA, ?)) },
values: fn($set as set:atomic-set) as xs:anyAtomicType*
{ keys($set?$DATA) },
add: fn($set as set:atomic-set, $value as xs:anyAtomicType) as xs:anyAtomicType*
{ set:replaceData($set, map:put(?, $value, true())) },
remove: fn($set as set:atomic-set, $value as xs:anyAtomicType) as xs:anyAtomicType*
{ set:replaceData($set, map:remove(?, $value)) },
union: fn($set as set:atomic-set, $other as set:atomic-set) as set:atomic-set
{ set:replaceData($set, fn($this) {map:merge(($this, $other?$DATA),
{'duplicates': 'use-first'})})
},
intersect: fn($set as set:atomic-set, $other as set:atomic-set) as set:atomic-set
{ set:replaceData($set, map:filter(?, $other?contains)) },
except: fn($set as set:atomic-set, $other as set:atomic-set) as set:atomic-set
{ set:replaceData($set, map:remove(?, $other?values())) }
}
};

View file

@ -211,8 +211,9 @@
value="https://raw.githubusercontent.com/Quodatum/xqdoca/refs/heads/master/src/main/lib/model.xqm">
model.xqm (Quodatum/xqdoca)</option>
<option
value="https://git.quodatum.duckdns.org/api/v1/repos/quodatum/basex-lsp/raw/webapp/lsp/lsp-text.xqm">
lsp-text.xqm (quodatum/basex-lsp FORGEIO)</option>
value="https://git.quodatum.duckdns.org/api/v1/repos/quodatum/basex-lsp/raw/webapp/lsp/set.xqm">
set.xqm (quodatum/basex-lsp FORGEIO)</option>
<option
value="https://raw.githubusercontent.com/dnovatchev/Articles/refs/heads/main/Generators/Code/generator.xq">
generator.xquery</option>

View file

@ -16684,7 +16684,7 @@ var lsp = (function (exports) {
diagnostics = diagnosticFilter(diagnostics, state);
let sorted = diagnostics.slice().sort((a, b) => a.from - b.from || a.to - b.to);
let deco = new RangeSetBuilder(), active = [], pos = 0;
let scan = state.doc.iter(), scanPos = 0;
let scan = state.doc.iter(), scanPos = 0, docLen = state.doc.length;
for (let i = 0;;) {
let next = i == sorted.length ? null : sorted[i];
if (!next && !active.length)
@ -16696,6 +16696,8 @@ var lsp = (function (exports) {
}
else {
from = next.from;
if (from > docLen)
break;
to = next.to;
active.push(next);
i++;
@ -16712,8 +16714,9 @@ var lsp = (function (exports) {
break;
}
}
to = Math.min(to, docLen);
let widget = false;
if (active.some(d => d.from == from && d.to == to)) {
if (active.some(d => d.from == from && (d.to == to || to == docLen))) {
widget = from == to;
if (!widget && to - from < 10) {
let behind = from - (scanPos + scan.value.length);
@ -16750,6 +16753,8 @@ var lsp = (function (exports) {
}));
}
pos = to;
if (pos == docLen)
break;
for (let i = 0; i < active.length; i++)
if (active[i].to <= pos)
active.splice(i--, 1);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long