Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error lines by adding regex for empty/only-spaces lines #113

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions examples/coffeeshop.html
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,41 @@ <H3 STYLE="flex-grow:1" ID="title">The CoffeeShop</H3>
els.sample.contentDocument.body.style = "margin:0; padding:0;";
postRun();
els.sample.contentWindow.addEventListener('error', function(e) {
//console.log(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");
rowOffset = -1;
for (var line of lines) {
if (line.match(/Algebra\s?\(/)) {
kungfooman marked this conversation as resolved.
Show resolved Hide resolved
break;
}
rowOffset++;
}
if (rowOffset == -1) {
rowOffset = 0;
}
}
// show error in HTML
els.sample.contentDocument.body.innerHTML+=`<PRE>${e.message}</PRE>`;
// show error in ace editor
var row = e.lineno;
var row = rowOffset + e.lineno;
//console.log("rowOffset", rowOffset, "e.lineno", e.lineno)
kungfooman marked this conversation as resolved.
Show resolved Hide resolved
// e.lineno is one off in same cases... fixing that, otherwise it looks strange
// Chrome
if (e.message.includes("Unexpected identifier")) {
if (
e.message.includes("Unexpected identifier") ||
e.message.includes("Uncaught SyntaxError:")
) {
row--;
}
// Mozilla
if (e.message.includes("unexpected token: identifier")) {
if (
e.message.includes("unexpected token: identifier") ||
e.message.includes("SyntaxError: unexpected token: '") ||
e.message.includes("SyntaxError: invalid arrow-function arguments") // var D = asd ()=>L ^ M;
) {
row--;
}
editor.getSession().setAnnotations([{
Expand Down
3 changes: 2 additions & 1 deletion ganja.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down