// Read-only scan of a downloaded Lean project: import closure from a root and flagged constructs. // usage: node scan.js const fs = require("fs"), path = require("path"); const [src, root] = process.argv.slice(2); const FLAG = /\bsorry\b|^\s*admit\b|[;(\s]admit\s*$|^\s*(private\s+|protected\s+)?(axiom|constant)\b|native_decide|implemented_by|@\[extern|\bunsafe\b|\bpartial\s+def\b|ofReduceBool|trustCompiler|#eval|run_cmd|run_tac|^\s*(syntax|macro|elab|elab_rules|macro_rules|notation|infix|infixl|infixr|prefix|postfix)\b|^\s*initialize\b|\bdecide\s*:=\s*true|^\s*(@\[[^\]]*\]\s*)?(scoped\s+)?instance\b|attribute\s*\[(scoped\s+)?instance|Lean\.Elab|set_option\s+(debug|maxRecDepth|backward)/; const seen = new Set([root]), q = [root], flagged = [], ext = new Set(); let lines = 0; while (q.length) { const mod = q.shift(), f = path.join(src, mod.split(".").join("/") + ".lean"); if (!fs.existsSync(f)) { ext.add(mod); continue; } const ls = fs.readFileSync(f, "utf8").split("\n"); lines += ls.length; ls.forEach((l, i) => { const m = l.match(/^(?:public\s+)?import\s+(\S+)/); if (m) { if (!seen.has(m[1])) { seen.add(m[1]); q.push(m[1]); } return; } if (FLAG.test(l)) flagged.push(`${mod}:${i + 1}: ${l.trim().slice(0, 150)}`); }); } const local = [...seen].filter(m => !ext.has(m)); console.log("local modules:", local.length, "lines:", lines, "| external:", [...ext].join(", ")); console.log("flagged:", flagged.length); flagged.forEach(x => console.log(" " + x));