aboutsummaryrefslogtreecommitdiff
path: root/docs/repl.js
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-11-17 20:07:24 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-11-17 20:27:13 -0500
commit7f8c1baa94bdccd37ba56a800d9de0e4fa008a89 (patch)
tree9f7d0b391ace261544dbf017adc1b2e5ae62c468 /docs/repl.js
parent1ee3d8ddcb8bb96172cb9874c69f838caf8d0297 (diff)
Allow shape n‿2 array to signal error (start,end) pairs in error reporting
Diffstat (limited to 'docs/repl.js')
-rw-r--r--docs/repl.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/docs/repl.js b/docs/repl.js
index 42184d8f..964f7fa3 100644
--- a/docs/repl.js
+++ b/docs/repl.js
@@ -11,13 +11,16 @@ let showErr = (s,e)=>{
while (w&&w.loc||(r!=='!'&&w.sh&&w.sh[0]===2)) {
let is; [is,w]=w;
let n=is.sh?is.sh[0]:0, i=n?is[0]:is;
+ let pair=n&&is.sh.length>1; if (pair) n*=2;
let to=i=>s.slice(0,i).join('').split('\n').map(l=>Array.from(l));
let ll=to(i), l=ll.length-1, j=ll[l].length, m=to()[l];
let k=1,o=i-j,cl=j; while (k<n&&(cl=is[k]-o)<m.length) k++;
+ let ol=k<n; if (pair) { if (k%2) cl=m.length; else { k--; cl++; } }
let c=Array(cl).fill(0); c[j]=1;
- for (let h=1;h<k;h++) c[is[h]-o]=1;
+ for (let h=1;h<k;h++) c[is[h]-o+(pair?h%2:0)]=1;
+ if (pair) for (let h=1;h<cl;h++) c[h]^=c[h-1];
let add = ['',m.join(''),c.map(t=>t?'^':' ').join('')];
- loc = add.concat(k<n?['(and other lines)']:[], loc);
+ loc = add.concat(ol?['(and other lines)']:[], loc);
}
if (r==='!') w=w?fmt(w).replace(/^/gm,'! '):'! Error';
else w=w.sh?w.join(''):w;