aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-26 15:37:22 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-26 15:37:22 -0400
commit6796d0d1a56d94336f78e390a16f347e302efad8 (patch)
tree5780729b503a30f27d950e814542675e03483b2a /docs
parentdb6239e74f13f6335c9c77e7a5dfa7461017f3ec (diff)
Show source code position in error output if available
Diffstat (limited to 'docs')
-rw-r--r--docs/repl.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/docs/repl.js b/docs/repl.js
index 14927537..18a472aa 100644
--- a/docs/repl.js
+++ b/docs/repl.js
@@ -14,10 +14,15 @@ let repl = ()=>{
try {
doc.rslt.textContent=fmt(bqn(s));
} catch(e) {
- let s=e.src, w=e.message, i=-1;
- if (s==="Compiler"&&w.sh[0]===2) [i,w]=w;
- if (s==="!") w=w?fmt(w).replace(/^/gm,'! '):'! Error';
- else w=w.sh?w.join(""):w;
+ let r=e.src, w=e.message, i=-1;
+ if (r==='Compiler'&&w.sh[0]===2) [i,w]=w;
+ if (r==='!') w=w?fmt(w).replace(/^/gm,'! '):'! Error';
+ else w=w.sh?w.join(''):w;
+ if (i>=0) {
+ 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');
+ }
doc.rslt.classList.add('err');
doc.rslt.textContent=w;
}