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 all 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
22 changes: 12 additions & 10 deletions examples/coffeeshop.html
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,21 @@ <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) {
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+=`<PRE>${e.message}</PRE>`;
// 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,
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