[add] railroad generation
This commit is contained in:
parent
d26fae56e4
commit
f867836ddf
11 changed files with 18682 additions and 1324 deletions
12
README.md
12
README.md
|
@ -59,8 +59,16 @@ State is held in [websocket attributes](https://docs.basex.org/main/WebSocket_Fu
|
|||
|client|the client initialize message|
|
||||
|initialized|set true after client sends initialized message|
|
||||
|files|A map whose keys are open uris, values are maps (doctype-> attribute name where doctype is stored| |
|
||||
|file-{uuid}|name of websocket attribute with textDocument|
|
||||
|parse-{uuid}|name of websocket attribute with parse tree XML|
|
||||
|file-{uuid}|name of websocket attribute containing the textDocument|
|
||||
|parse-{uuid}|name of websocket attribute containing parse tree XML|
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
WS->>lsp-ws: message
|
||||
lsp-ws->>rpc: reply
|
||||
rpc->>+John: John, can you hear me?
|
||||
|
||||
```
|
||||
|
||||
#### XQuery 4.0 parser
|
||||
The ebnf is taken from Gunther Rademacher's rex-parser-generator
|
||||
|
|
File diff suppressed because it is too large
Load diff
18478
docs/XQuery-40.ebnf.xhtml
Normal file
18478
docs/XQuery-40.ebnf.xhtml
Normal file
File diff suppressed because one or more lines are too long
|
@ -28,6 +28,7 @@
|
|||
"lsp-build": "rollup bundles/cm6/lsp.js -m true -f iife -o webapp/static/clients/codemirror/lsp.bundle.js -p node-resolve,tla --output.name lsp",
|
||||
"lsp-min": "cd webapp/static/clients/codemirror && npx minify lsp.bundle.js > lsp.bundle.min.js ",
|
||||
"min": "cd dist && npx minify cm6.bundle.js > cm6.bundle.min.js && npx minify lsp.bundle.js > lsp.bundle.min.js",
|
||||
"javac": "cd bundles/grammar && javac --release 17 -cp %BASEX12%\\BaseX.jar -d build xq4.java && cd build && jar cf ../../../webapp/custom/xq4.jar . "
|
||||
"javac": "cd bundles/grammar && javac --release 17 -cp %BASEX12%\\BaseX.jar -d build xq4.java && cd build && jar cf ../../../webapp/custom/xq4.jar . ",
|
||||
"railroad server": "cd C:/Users/mrwhe/apps/rr-2.5-java11 && java -jar rr.war -gui -port:5555"
|
||||
}
|
||||
}
|
||||
|
|
19
scripts/makesite.xq
Normal file
19
scripts/makesite.xq
Normal file
|
@ -0,0 +1,19 @@
|
|||
(:~ generate site :)
|
||||
import module namespace qform = 'urn:quodatum:http.form' at 'postutil.xqm';
|
||||
(:~ local RR server :)
|
||||
declare variable $rr-server := "https://www.bottlecaps.de/rr/ui";
|
||||
|
||||
declare variable $base := "../bundles/grammar/"=>file:resolve-path(file:base-dir() );
|
||||
declare variable $dest := "../docs/v2/"=>file:resolve-path(file:base-dir() );
|
||||
|
||||
declare variable $opts:=map{
|
||||
"task":"VIEW",
|
||||
"frame":"diagram",
|
||||
"width":992
|
||||
};
|
||||
for $file in file:list($base,false(),"*.ebnf")
|
||||
let $ebnf:=file:read-text(file:resolve-path($file,$base))=>trace("EEEE")
|
||||
let $rr:=qform:post-form(map:put($opts,"ebnf",$ebnf),$rr-server)
|
||||
let $t:=xslt:transform($rr,"toc.xsl",map{"title": $file=>trace("file: ")})
|
||||
let $d:=file:resolve-path($file || ".xhtml",$dest )
|
||||
return file:write($d,$t,map{"method":"xhtml"})
|
21
scripts/railroad.xq
Normal file
21
scripts/railroad.xq
Normal file
|
@ -0,0 +1,21 @@
|
|||
(: run railroad to generate html doc :)
|
||||
|
||||
|
||||
(:~ local RR war :)
|
||||
declare variable $RR-WAR := "C:\Users\mrwhe\apps\rr-2.5-java11\webapps\rr.war";
|
||||
|
||||
declare variable $base := "../bundles/grammar/"=>file:resolve-path(file:base-dir() );
|
||||
declare variable $dest := "../docs/v2/"=>file:resolve-path(file:base-dir() );
|
||||
|
||||
declare function local:rr-run($ebnf){
|
||||
proc:system("java",("-jar",$RR-WAR,$ebnf))
|
||||
};
|
||||
|
||||
for $file in file:list($base,false(),"*.ebnf")
|
||||
let $rr:= file:resolve-path($file,$base)
|
||||
=>local:rr-run()
|
||||
|
||||
|
||||
let $t:=xslt:transform($rr,"toc.xsl",map{"title": $file=>trace("file: ")})
|
||||
let $d:=file:resolve-path($file || ".xhtml",$dest )
|
||||
return file:write($d,$t,map{"method":"xhtml"})
|
128
scripts/toc.xsl
Normal file
128
scripts/toc.xsl
Normal file
|
@ -0,0 +1,128 @@
|
|||
<!-- enrich rr https://github.com/GuntherRademacher/rr output
|
||||
@author Andy Bunce, Quodatum
|
||||
@license Apache 2
|
||||
-->
|
||||
<xsl:stylesheet version="3.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:xhtml="http://www.w3.org/1999/xhtml"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
exclude-result-prefixes="svg">
|
||||
<xsl:mode on-no-match="shallow-copy"/>
|
||||
<xsl:param name="title" as="xs:string" select="'(untitled)'"/>
|
||||
<xsl:variable name="names" select="/xhtml:html/xhtml:body/xhtml:p/xhtml:a/@name/string()=>sort()" />
|
||||
|
||||
<xsl:template match="xhtml:body" >
|
||||
<xsl:copy>
|
||||
<xhtml:header style="display:flex;justify-content:space-evenly;">
|
||||
<xhtml:div><xsl:value-of select="$title"/></xhtml:div>
|
||||
<xhtml:div >
|
||||
<xhtml:details id="the-details">
|
||||
<xhtml:summary>Find</xhtml:summary>
|
||||
<xhtml:div>
|
||||
<xsl:call-template name="toc"/>
|
||||
</xhtml:div>
|
||||
</xhtml:details>
|
||||
<xhtml:script>
|
||||
var details = document.getElementById("the-details"), // form
|
||||
document.addEventListener('click', function(e){
|
||||
if(!details.contains(e.target)){
|
||||
details.removeAttribute('open')
|
||||
}
|
||||
})
|
||||
</xhtml:script>
|
||||
</xhtml:div>
|
||||
</xhtml:header>
|
||||
<xhtml:main>
|
||||
<xhtml:div >
|
||||
<xsl:apply-templates />
|
||||
</xhtml:div>
|
||||
</xhtml:main>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="xhtml:head/xhtml:meta[last()]">
|
||||
<xsl:copy-of select="."/>
|
||||
<xhtml:meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
<xhtml:meta name="date" content="{ current-dateTime() }"/>
|
||||
</xsl:template>
|
||||
|
||||
<!-- add extra styles -->
|
||||
<xsl:template match="xhtml:head/xhtml:style[@type='text/css'][1]" >
|
||||
<xsl:copy>
|
||||
html {
|
||||
scroll-behavior: smooth;
|
||||
}
|
||||
|
||||
nav {
|
||||
top: 8vh;
|
||||
width:100%;
|
||||
border: 1px solid #ffe9e9;
|
||||
background-color: #fffed6;
|
||||
}
|
||||
|
||||
#the-reset { padding: 2px; }
|
||||
#the-reset:hover { background-color: bisque; }
|
||||
|
||||
#the-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
height:50vh;
|
||||
overflow-y:scroll;
|
||||
}
|
||||
|
||||
#the-list li {
|
||||
padding: 1px;
|
||||
}
|
||||
#the-list li:hover { background: #fffed6; }
|
||||
#the-list li.hide { display: none; }
|
||||
|
||||
header{
|
||||
height: 20px;
|
||||
padding: 0px;
|
||||
background-color: #fffed6;
|
||||
z-index: 99;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
a{
|
||||
scroll-margin-top: 2rem;
|
||||
}
|
||||
<xsl:value-of select="."/>
|
||||
</xsl:copy>
|
||||
</xsl:template>
|
||||
|
||||
<!-- insert toc -->
|
||||
<xsl:template name="toc" >
|
||||
<xhtml:nav class="section-nav">
|
||||
<xhtml:label for="name">Productions:</xhtml:label>
|
||||
<xhtml:input type="text" id="the-filter" name="name" placeholder="filter..." size="5"/>
|
||||
<xhtml:a href="#" title="Reset" id="the-reset"
|
||||
onclick="document.getElementById('the-details').removeAttribute('open');update();"
|
||||
>X</xhtml:a>
|
||||
<xhtml:ul id="the-list">
|
||||
<xsl:for-each select="$names">
|
||||
<xhtml:li>
|
||||
<xhtml:a href="#{.}"><xsl:value-of select="."/></xhtml:a>
|
||||
</xhtml:li>
|
||||
</xsl:for-each>
|
||||
</xhtml:ul>
|
||||
</xhtml:nav>
|
||||
<xhtml:script>
|
||||
var filter = document.getElementById("the-filter"), // search box
|
||||
list = document.querySelectorAll("#the-list li"); // all list items
|
||||
update=function(){
|
||||
let search = filter.value.toLowerCase();
|
||||
for (let i of list) {
|
||||
let item = i.innerHTML.toLowerCase();
|
||||
if (item.indexOf(search) == -1) { i.classList.add("hide"); }
|
||||
else { i.classList.remove("hide"); }
|
||||
}
|
||||
};
|
||||
window.addEventListener("load", () => {filter.onkeyup =update;});
|
||||
</xhtml:script>
|
||||
</xsl:template>
|
||||
|
||||
</xsl:stylesheet>
|
|
@ -1,5 +1,5 @@
|
|||
import module namespace hnd="lsp/handlers" at "../webapp/lsp/handlers.xqm";
|
||||
declare variable $src:="sample.docs/parse-pdfbox.xml";
|
||||
declare variable $parse:=doc($src);
|
||||
declare variable $parse:=doc($src)/*;
|
||||
|
||||
hnd:diags($parse )
|
||||
hnd:diags($parse )
|
||||
|
|
|
@ -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())
|
||||
};
|
||||
|
||||
|
|
|
@ -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(*))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue