X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/idiomatic.git/blobdiff_plain/1d14f8b4c3061f3bbecbbd2df4c230a9dd1fd985..da0744c9c33ae9440765aecde2faf00f7187032f:/index.js
diff --git a/index.js b/index.js
index b1a1a24..76c9158 100644
--- a/index.js
+++ b/index.js
@@ -37,7 +37,7 @@ app.get('/index', async (req,res,next) => {
console.log(new Date().toLocaleTimeString(), 'index')
const reductions = counter()
const doit = branch => {reductions.count(branch.type)}
- visitor.wander(mods,doit)
+ visitor.walk(mods,doit)
const result = `
${reductions.size()} non-terminals
${reductions.total()} reductions
@@ -59,7 +59,7 @@ app.get('/terminal', (req,res) => {
const {type,field} = req.query
const lits = counter()
const doit = branch => {if(branch.type==type) lits.count(branch[field])}
- visitor.wander(mods,doit)
+ visitor.walk(mods,doit)
const result = style('terminal',type)+`
${lits.size()} uniques
${lits.total()} total
@@ -79,8 +79,7 @@ app.get('/usage', (req,res) => {
${stack.at(-1)}
${sxpr(stack[width ?? 2], depth ?? 3)}`)
}
- visitor.wander(mods,doit)
- const vis = row => row.split(/\n/)[3].trim().replaceAll(/<.*?>/g,'').replaceAll(/\.\.+/g,'..')
+ visitor.walk(mods,doit)
list.sort((a,b) => vis(a)>vis(b) ? 1 : -1)
const q = (id,delta) => Object.entries(req.query)
.map(([k,v]) => k == id ? `${k}=${+v+delta}` : `${k}=${v}`)
@@ -102,7 +101,7 @@ app.get('/nesting', (req,res) => {
if(stack.at(-1)==file && branch.type==type && branch.start==start && branch.end==end) {
const path = stack.slice(0,-1).map((n,i) => `
|
- | ${n.type}:
+ | ${n.type}:
| ${sxpr(n,3,null,stack[i-1])}`).reverse()
const hit = stack[1]
result.push(`
@@ -110,10 +109,30 @@ app.get('/nesting', (req,res) => {
${escape(JSON.stringify(hit,omit,2))}`)
}
}
- visitor.wander(mods,doit)
+ visitor.walk(mods,doit)
res.send(style('nesting',key)+`${result.join(" ")}`)
})
+app.get('/similar', (req,res) => {
+ const {file,type,key,start,end,nest} = req.query
+ let nested
+ visitor.walk(mods,(branch,stack) => {
+ if(stack.at(-1)==file && branch.type==type && branch.start==start && branch.end==end)
+ nested = stack[nest]
+ })
+ const norm = node => vis(`\n\n\n${sxpr(node,3,null)}`)
+ const source = (file,node) => mods.find(mod => mod.file == file).text.substring(+node.start,+node.end)
+ const want = norm(nested)
+ const result = []
+ visitor.walk(mods,(branch,stack) => {
+ if(norm(branch) == want) result.push(`${escape(source(stack.at(-1),branch))} `)
+ })
+ res.send(style('similar',key)+
+ `${want} ` +
+ result.join("\n")
+ )
+})
+
// H E L P E R S
@@ -185,4 +204,17 @@ function elipsis(obj) {
return `(${dots})`
}
+function vis(row) {
+ return row.split(/\n/)[3].trim()
+ .replaceAll(/<.*?>/g,'')
+ .replaceAll(/\.\.+/g,'..')
+}
+
+
+function query(obj,adj={}) {
+ return Object.entries(obj)
+ .map(([k,v]) => k in adj ? `${k}=${adj[k](v)}` : `${k}=${v}`)
+ .join('&')
+}
+
app.listen(1954)
\ No newline at end of file
|