X-Git-Url: https://dreyeck.freedombox.rocks/gitweb/idiomatic.git/blobdiff_plain/96f9e23cc6e9201f27fb656588199e234901420e..682a7215ae646bc71baf0be528b9c7d55b1cb445:/index.js diff --git a/index.js b/index.js index b3334a5..18f87de 100644 --- a/index.js +++ b/index.js @@ -1,33 +1,13 @@ -let express = require('express') -let acorn = require('acorn') -let fs = require('fs') -// let fs = require('node:fs/promises'); - -let visitor = require('./visitor.js') -let dir = '../wiki-client/lib' -let mods = [] - -const app = express() - - -// P A G E S - -app.get('/index', async (req,res,next) => { - console.log(new Date().toLocaleTimeString(), 'index') - const reductions = counter() - fs.readdir(dir, async (err, files) => { - mods = await Promise.all(files.map(load)) - const doit = branch => {reductions.count(branch.type)} - visitor.wander(mods,doit) - const result = ` -
${reductions.size()} non-terminals
-
${reductions.total()} reductions
-
${reductions.tally()
- .map(([k,v]) => `${v} ${link(k)}`)
- .join("
")}`
- res.send(result);
- next()
- })
+const express = require('express')
+const acorn = require('acorn')
+const fs = require('fs')
+// const fs = require('node:fs/promises');
+const visitor = require('./visitor.js')
+
+const dir = '../wiki-client/lib'
+const mods = []
+fs.readdir(dir, async (err, files) => {
+ mods.push(... await Promise.all(files.map(load)))
})
async function load(file) {
@@ -39,6 +19,27 @@ async function load(file) {
})
}
+
+// P A G E S
+
+const style = ''
+const app = express()
+
+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)
+ const result = `
+
${reductions.size()} non-terminals
+
${reductions.total()} reductions
+
${reductions.tally()
+ .map(([k,v]) => `${v} ${link(k)}`)
+ .join("
")}`
+ res.send(style+result);
+ next()
+ })
+
function link(key) {
if(key.match(/^Ident/)) return `${key}`
if(key.match(/^(As|B|L|U).*Ex/)) return `${key}`
@@ -48,35 +49,50 @@ function link(key) {
app.get('/terminal', (req,res) => {
+ const {type,field} = req.query
const lits = counter()
- const id = req.query.type
- const field = req.query.field
- const doit = branch => {if(branch.type==id) lits.count(branch[field])}
+ const doit = branch => {if(branch.type==type) lits.count(branch[field])}
visitor.wander(mods,doit)
const result = `
${lits.size()} uniques
${lits.total()} total
${lits.tally()
- .map(([k,v]) => `${v} ${escape(k)}`)
+ .map(([k,v]) => `${v} ${escape(k)}`)
.join("
")}`
- res.send(result)
+ res.send(style+result)
})
app.get('/usage', (req,res) => {
- const type = req.query.type
- const field = req.query.field
- const key = req.query.key
+ const {type,field,key} = req.query
const list = []
const doit = (branch,stack) => {
- if(branch.type==type && branch[field]==key)
- list.push(`${stack.at(-1)} ${sxpr(stack[2],3)}`
- // `${stack.length}
- // ${stack.at(-1)}-${branch.start}-${branch.end}
- // (${stack.slice(0,6).map(n => n.end-n.start).join(" ")})`
- )
+ if(branch.type==type && branch[field]==key)list.push(`
+
+ ${stack.at(-1)}
+ ${sxpr(stack[2],3)}`)
}
visitor.wander(mods,doit)
- res.send(`
${JSON.stringify(req.query,null,2)}${list.join("${JSON.stringify(req.query,null,2)}${list.join("${escape(JSON.stringify(hit,omit,2))}`)
+ }
+ }
+ visitor.wander(mods,doit)
+ res.send(style+`${JSON.stringify(req.query,null,2)}${result.join("