Skip to content

Commit

Permalink
Avoid console message on empty compile output.
Browse files Browse the repository at this point in the history
Also, refactor some parsing code to avoid assuming the same number
of groups in all the regex patterns.  This was confusing me.
  • Loading branch information
cdsmith committed Feb 10, 2019
1 parent 2a6d02c commit 67982d3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions web/js/codeworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,14 +1072,16 @@ function parseCompileErrors(rawErrors) {
rawErrors.forEach(function(rawError) {
rawError = rawError.split('\n');
var firstLine = rawError[0].trim(),
message = rawError.slice(1).map((err) => {
otherLines = rawError.slice(1).map((err) => {
return err.trim()
}).join('\n'),
re1 = /^program\.hs:(\d+):((\d+)-?(\d+)?): (\w+):(.*)/,
re2 = /^program\.hs:\((\d+),(\d+)\)-\((\d+),(\d+)\): (\w+):(.*)/,
startLine, endLine, startCol, endCol, match, severity, description;

if (re1.test(firstLine)) {
if (firstLine.trim() === "") {
return;
} else if (re1.test(firstLine)) {
match = re1.exec(firstLine);
startLine = Number(match[1]) - 1;
endLine = startLine;
Expand All @@ -1097,24 +1099,26 @@ function parseCompileErrors(rawErrors) {
endCol = startCol + 1;
}
}
severity = match[5]
description = match[6] ? match[6].trim() + '\n' : "" + otherLines;
} else if (re2.test(firstLine)) {
match = re2.exec(firstLine);
startLine = Number(match[1]) - 1;
startCol = Number(match[2]) - 1;
endLine = Number(match[3]) - 1;
endCol = Number(match[4]) - 1;
severity = match[5]
description = match[6] ? match[6].trim() + '\n' : "" + otherLines;
} else {
console.log("Can not parse error header:", firstLine);
return;
}
severity = match[5]
description = match[6] ? match[6].trim() + '\n' : ""

errors.push({
from: CodeMirror.Pos(startLine, startCol),
to: CodeMirror.Pos(endLine, endCol),
severity: severity,
message: description + message
message: description
})
})
return errors;
Expand Down

0 comments on commit 67982d3

Please sign in to comment.