aboutsummaryrefslogtreecommitdiff
path: root/docs/repl.js
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-26 19:05:00 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-26 19:05:00 -0400
commit3db7480a4d54684ec7f24d1ae1bcdae6c285511d (patch)
tree03b86d255385104b8acffaa7c646a338510c0d34 /docs/repl.js
parent0c59728d5f8bae5ae6add34de9db76ae86cf95ae (diff)
Display multiple error sources if they are on the same line
Diffstat (limited to 'docs/repl.js')
-rw-r--r--docs/repl.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/docs/repl.js b/docs/repl.js
index cb3ec52e..da06e383 100644
--- a/docs/repl.js
+++ b/docs/repl.js
@@ -14,14 +14,19 @@ let repl = ()=>{
try {
doc.rslt.textContent=fmt(bqn(s));
} catch(e) {
- let r=e.src, w=e.message, i=-1;
- if (r==='Compiler'&&w.sh[0]===2) [i,w]=w;
+ let r=e.src, w=e.message, is=null;
+ if (r==='Compiler'&&w.sh[0]===2) [is,w]=w;
if (r==='!') w=w?fmt(w).replace(/^/gm,'! '):'! Error';
else w=w.sh?w.join(''):w;
- if (i>=0) {
+ if (is!==null) {
+ let n=is.sh?is.sh[0]:0, i=n?is[0]:is;
let to=i=>Array.from(s).slice(0,i).join('').split('\n');
- let ll=to(i), l=ll.length-1, j=ll[l].length;
- w = [w,'',to()[l],' '.repeat(j)+'^'].join('\n');
+ 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 c=Array(cl).fill(0); c[j]=1;
+ for (let h=1;h<k;h++) c[is[h]-o]=1;
+ w = [w,'',m,c.map(t=>t?'^':' ').join('')].join('\n');
+ if (k<n) w+='\n'+'(and other lines)';
}
doc.rslt.classList.add('err');
doc.rslt.textContent=w;