From 65b18cc1f01c6cb851694283c1d10db5f4008757 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 4 Mar 2023 22:24:43 +0000 Subject: [PATCH] bugfix: make parsing more robust Now it parses output from ChatGPT :P --- src/app.mjs | 1 - src/esbuild.mjs | 5 ++++- src/lib/parse_summary.mjs | 13 ++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app.mjs b/src/app.mjs index 9e85c41..83b17de 100644 --- a/src/app.mjs +++ b/src/app.mjs @@ -13,7 +13,6 @@ function do_visualisation(el_in, el_out) { console.log(summary); const svg = make_graph(summary); - console.log(svg); const container = document.createElement("div"); container.innerHTML = svg; diff --git a/src/esbuild.mjs b/src/esbuild.mjs index c449aab..e94fa3e 100644 --- a/src/esbuild.mjs +++ b/src/esbuild.mjs @@ -81,7 +81,10 @@ function make_context() { { name: "copy-html", setup(build) { - build.onEnd(_result => { + build.onEnd(result => { + if (result.errors.length > 0 || result.warnings.length > 0) + console.log(result); + console.log(`${new Date().toISOString()} | Build complete`); do_html(); }) } diff --git a/src/lib/parse_summary.mjs b/src/lib/parse_summary.mjs index ee21c9b..ab5290f 100644 --- a/src/lib/parse_summary.mjs +++ b/src/lib/parse_summary.mjs @@ -15,12 +15,14 @@ export default function parse_summary(text) { const sep_output_shape = lines[2].search("Output Shape"); const sep_param_hash = lines[2].search("Param #"); const sep_connected_to = has_connected_to ? lines[2].search("Connected to") : lines[2].length; - + console.log(`DEBUG:layers_raw`, layers_raw); let layer_prev = null; let acc = []; for (const line of layers_raw) { - if(line.trim().length == 0) { + console.log(`DEBUG:layers/line`, line, `CONDITION B`, line.trim().search(/^\-+$/)); + if(line.trim().length == 0 || line.trim().search(/^[-_]+$/) > -1) { if(acc.length === 0) continue; + console.log(`LAYER`); console.log(`DEBUG:params`, acc.map(layer_line => layer_line.substring(sep_param_hash, sep_connected_to).trim())); // Handle parsed item @@ -39,7 +41,8 @@ export default function parse_summary(text) { result.connected_to = [ layer_prev.name ]; } - result.type = result.name_raw.match(/ \(([^)]+)\)/)[1]; + console.log(`DEBUG:result`, result) + result.type = result.name_raw.match(/ \(([^)]+)(?:\)|$)/)[1]; result.name = result.name_raw.split(/\s+/)[0]; layer_prev = result; @@ -47,8 +50,8 @@ export default function parse_summary(text) { acc.length = 0; } - - acc.push(line); + else + acc.push(line); } const edges = [];