diff --git a/examples/coffeeshop.html b/examples/coffeeshop.html index 5b9af83..d8ac2ba 100644 --- a/examples/coffeeshop.html +++ b/examples/coffeeshop.html @@ -578,19 +578,21 @@

The CoffeeShop

els.sample.contentDocument.body.style = "margin:0; padding:0;"; postRun(); els.sample.contentWindow.addEventListener('error', function(e) { + var rowOffset = 0; + if (e.filename == "") { + // Figure out line where `Algebra(..., ()=>{...}` starts in ACE Editor (because error is offsetted from there) + var lines = editor.getValue().split("\n"); + for (var line of lines) { + if (line.match(/\bAlgebra\s*\(/)) { + break; + } + rowOffset++; + } + } // show error in HTML els.sample.contentDocument.body.innerHTML+=`
${e.message}
`; // show error in ace editor - var row = e.lineno; - // e.lineno is one off in same cases... fixing that, otherwise it looks strange - // Chrome - if (e.message.includes("Unexpected identifier")) { - row--; - } - // Mozilla - if (e.message.includes("unexpected token: identifier")) { - row--; - } + var row = rowOffset + e.lineno - 1; editor.getSession().setAnnotations([{ row, column: e.colno, diff --git a/ganja.js b/ganja.js index 013ca7d..93d850d 100644 --- a/ganja.js +++ b/ganja.js @@ -1535,7 +1535,8 @@ /^\d+[.]{0,1}\d*[ei][\+\-_]{0,1}\d*|^\.\d+[ei][\+\-_]{0,1}\d*|^e_\d*/g, // 2: literal numbers in scientific notation (with small hack for i and e_ asciimath) /^\d+[.]{0,1}\d*[E][+-]{0,1}\d*|^\.\d+[E][+-]{0,1}\d*|^0x\d+|^\d+[.]{0,1}\d*|^\.\d+|^\(\/.*[^\\]\/\)/g, // 3: literal hex, nonsci numbers and regex (surround regex with extra brackets!) /^(\.Normalized|\.Length|\.\.\.|>>>=|===|!==|>>>|<<=|>>=|=>|\|\||[<>\+\-\*%&|^\/!\=]=|\*\*|\+\+|\-\-|<<|>>|\&\&|\^\^|^[{}()\[\];.,<>\+\-\*%|&^!~?:=\/]{1})/g, // 4: punctuator - /^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*/gu] // 5: identifier + /^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*/gu, // 5: identifier + /\s+/g] // 6: empty lines while (txt.length) for(t in tokens) if(resi=txt.match(tokens[t])){ tok.push([t|0,resi[0]]); txt=txt.slice(resi[0].length); break;} // tokenise // Translate algebraic literals. (scientific e-notation to "this.Coeff" tok=tok.map(t=>(t[0]==2)?[2,'Element.Coeff('+basis.indexOf((!options.Cayley?simplify:(x)=>x)('e'+t[1].split(/e_|e|i/)[1]||1).replace('-',''))+','+(simplify(t[1].split(/e_|e|i/)[1]||1).match('-')?"-1*":"")+parseFloat(t[1][0]=='e'?1:t[1].split(/e_|e|i/)[0])+')']:t);