X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/idiomatic.git/blobdiff_plain/da0744c9c33ae9440765aecde2faf00f7187032f..6dd85f31cb74c4597a1a625e097e29e89ed83f41:/index.js?ds=inline
diff --git a/index.js b/index.js
index 76c9158..9f1a2b7 100644
--- a/index.js
+++ b/index.js
@@ -1,9 +1,11 @@
const express = require('express')
const acorn = require('acorn')
const fs = require('fs')
-// const fs = require('node:fs/promises');
const visitor = require('./visitor.js')
+
+// P A R S E
+
const dir = '../wiki-client/lib'
const mods = []
fs.readdir(dir, async (err, files) => {
@@ -30,14 +32,13 @@ const style = (title,here='') => `
.hi {background-color:pink;}
section {letter-spacing:.2rem; font-size:1.2rem;}
- â ${title} ${escape(here)} â`
+ `
const app = express()
-app.get('/index', async (req,res,next) => {
- console.log(new Date().toLocaleTimeString(), 'index')
+app.get('/index', async (req,res) => {
const reductions = counter()
- const doit = branch => {reductions.count(branch.type)}
- visitor.walk(mods,doit)
+ visitor.walk(mods,branch =>
+ reductions.count(branch.type))
const result = `
| ${v} | ${link(k)}`)
.join("\n")}`
res.send(style('index')+result);
- next()
- })
-function link(key) {
- if(key.match(/^Ident/)) return `${key}`
- if(key.match(/^(As|B|L|U).*Ex/)) return `${key}`
- if(key.match(/^Lit/)) return `${key}`
- return key
-}
+ function link(key) {
+ if(key.match(/^Ident/)) return `${key}`
+ if(key.match(/^(As|B|L|U).*Ex/)) return `${key}`
+ if(key.match(/^Lit/)) return `${key}`
+ return key
+ }
+})
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.walk(mods,doit)
+ const terms = counter()
+ visitor.walk(mods,branch => {
+ if(branch.type==type)
+ terms.count(branch[field])})
const result = style('terminal',type)+`
- ${lits.size()} uniques
- ${lits.total()} total
- ${lits.tally()
+ ${terms.size()} uniques
+ ${terms.total()} total
+ ${terms.tally()
.map(([k,v]) => `| ${v} | ${escape(k)}`)
.join("\n")} | `
res.send(result)
@@ -73,13 +74,11 @@ app.get('/usage', (req,res) => {
const {type,field,key,width,depth} = req.query
const list = []
const files = counter()
- const doit = (branch,stack) => {
+ visitor.walk(mods,(branch,stack) => {
if(branch.type==type && branch[field]==key)list.push(`
|
${stack.at(-1)}
- | ${sxpr(stack[width ?? 2], depth ?? 3)}`)
- }
- visitor.walk(mods,doit)
+ | ${sxpr(stack[width ?? 2], depth ?? 3)}`)})
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}`)
@@ -90,14 +89,14 @@ app.get('/usage', (req,res) => {
res.send(style('usage',key)+`
${files.total()} uses in ${files.size()} files
${files.tally().map(([k,v]) => `| ${v} | ${k}`).join("\n")} |
-
â ${d('width')} ${d('depth')} â
+ ${d('width')} ${d('depth')}
`)
})
app.get('/nesting', (req,res) => {
const {file,type,key,start,end} = req.query
const result = []
- const doit = (branch,stack) => {
+ visitor.walk(mods,(branch,stack) => {
if(stack.at(-1)==file && branch.type==type && branch.start==start && branch.end==end) {
const path = stack.slice(0,-1).map((n,i) => `
|
@@ -108,8 +107,7 @@ app.get('/nesting', (req,res) => {
${escape(JSON.stringify(hit,omit,2))}`)
}
- }
- visitor.walk(mods,doit)
+ })
res.send(style('nesting',key)+`${result.join(" ")}`)
})
@@ -118,15 +116,14 @@ app.get('/similar', (req,res) => {
let nested
visitor.walk(mods,(branch,stack) => {
if(stack.at(-1)==file && branch.type==type && branch.start==start && branch.end==end)
- nested = stack[nest]
- })
+ 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))} `)
- })
+ if(norm(branch) == want)
+ result.push(`${escape(source(stack.at(-1),branch))} `)})
res.send(style('similar',key)+
`${want} ` +
result.join("\n")
@@ -210,7 +207,6 @@ function vis(row) {
.replaceAll(/\.\.+/g,'..')
}
-
function query(obj,adj={}) {
return Object.entries(obj)
.map(([k,v]) => k in adj ? `${k}=${adj[k](v)}` : `${k}=${v}`)
|