Skip to content

Commit

Permalink
Update logParser script to version 0.8.8 (git 7a5a944)
Browse files Browse the repository at this point in the history
  • Loading branch information
stloeffler committed Feb 22, 2016
1 parent 4a8e323 commit e61cffa
Show file tree
Hide file tree
Showing 9 changed files with 826 additions and 56 deletions.
65 changes: 35 additions & 30 deletions res/resfiles/scripts/Hooks/logParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Title: Errors, warnings, badboxes
// Description: Looks for errors, warnings or badboxes in the LaTeX terminal output
// Author: Jonathan Kew, Stefan Löffler, Antonio Macrì, Henrik Skov Midtiby
// Version: 0.8.6
// Date: 2013-07-05
// Version: 0.8.8
// Date: 2016-01-11
// Script-Type: hook
// Hook: AfterTypeset

Expand Down Expand Up @@ -108,7 +108,7 @@ function LogParser()
// Additionally, it recognizes other warnings like "LaTeX Font Warning: ...\n(Font) ...".
// The macro \GenericWarning does not produce formatted output, so it is impossible
// to match it. We need to look for output generated by higher level commands.
Regex: new RegExp("^(?:Class|Package|LaTeX) ([^\\s]+) Warning: .+\n(?:\\(\\1\\)\\s.+\n)*(?:.*\\.\n)?"),
Regex: new RegExp("^(?:Class|Package|LaTeX) ([^\\s]+) Warning: (?:(?:\\(\\1\\)\\s.+)+|.+\n)*.*\\.\n"),
Callback: function(m, f) {
// We remove "\n(<name>) " from description:
var desc = m[0].replace(new RegExp("\\(" + m[1] + "\\)\\s(.+)\n", "g"), " $1")
Expand Down Expand Up @@ -173,11 +173,18 @@ function LogParser()
},
{
// \show and \showthe
Regex: new RegExp("^>\\s(.+(?:\\.|=(?:\\\\long\\s)?macro:)\n(?:.*\n)*?l\\.(\\d+)\\s.*)\n"),
Regex: new RegExp("^> (.+(?:\\.|=(?:\\\\long\\s)?macro:)\n(?:.*\n)*?l\\.(\\d+)\\s.*)\n"),
Callback: function(m, f) {
return new Result(Severity.Debug, f, m[2], m[1]);
}
},
{
// This pattern recognizes XeTeX \endL / \endR problems
Regex: new RegExp("^(\\\\endL or \\\\endR problem \\(\\d+ missing, \\d+ extra\\) in paragraph) at lines (\\d+)--\\d+\n"),
Callback: function(m, f) {
return new Result(Severity.Warning, f, m[2], m[1]);
}
},
{
// At last, we check for a rerun of LaTeX caused by some Latexmk's rule
Regex: new RegExp("^Latexmk: applying rule"),
Expand Down Expand Up @@ -257,14 +264,14 @@ LogParser.prototype.Parse = function(output, rootFileName)
}
}

this.WarnUTF8BOM();
this.WarnAuxFiles();
}


LogParser.MatchNewFile = (function()
{
// Should catch filenames of the following forms:
// * abc -- Encountered with MiKTeX. Currently, the algorithm only captures filenames with no parenthesis and that are not wrapped
// * /abc, "/abc"
// * ./abc, "./abc"
// * .\abc, ".\abc"
Expand All @@ -273,10 +280,14 @@ LogParser.MatchNewFile = (function()
// * C:/abc, "C:/abc"
// * C:\abc, "C:\abc"
// * \\server\abc, "\\server\abc"
var fileRegexp = new RegExp('^\\("((?:[a-zA-Z]:[\\\\/]|/|\\.{1,2}[\\\\/]|\\\\\\\\)(?:[^"]|\n)+)"|^\\(((?:/|\\.{1,2}[\\\\/]|[a-zA-Z]:[\\\\/]|\\\\\\\\)[^ ()\n]+)');
var fileRegexp = new RegExp('^\\("((?:[a-zA-Z]:[\\\\/]|/|\\.{1,2}[\\\\/]|\\\\\\\\)(?:[^"]|\n)+)"|^\\(((?:/|\\.{1,2}[\\\\/]|[a-zA-Z]:[\\\\/]|\\\\\\\\)[^ ()\n]+|[^ ()\n\r]+\\.[a-zA-Z0-9]{1,4}\\b)');
var absolutePathRegexp = new RegExp('^[a-zA-Z]:[\\\\/]|/|\\\\\\\\');
var fileContinuingRegexp = new RegExp('[/\\\\ ()\n]');
var filenameRegexp = new RegExp("[^\\.]\\.[a-zA-Z0-9]{1,4}$");
var parenRegexp = new RegExp("\\((?:[^()]|\n)*\\)");
function isPathAbsolute(path) {
return absolutePathRegexp.exec(path);
}
function getBasePath(path) {
var i = Math.max(path.lastIndexOf('/'), path.lastIndexOf('\\'));
return (i == -1) ? path : path.slice(0, i+1);
Expand Down Expand Up @@ -317,7 +328,7 @@ LogParser.MatchNewFile = (function()
if (match) {
output = output.slice(match[0].length);
if (typeof(match[2]) != "undefined") {
var basePath = match[2][0] == '.' ? getBasePath(rootFileName) : "";
var basePath = isPathAbsolute(match[2]) ? "" : getBasePath(rootFileName);
var m, svmatch = null, svoutput = null;
// We ignore preceeding characters in the same line, and simply consider
// max_print_line: filenames which start in the middle of a line never
Expand All @@ -335,11 +346,13 @@ LogParser.MatchNewFile = (function()
else if (m[0] == '(') {
output = output.slice(sepPos);
lookahead = fileRegexp.exec(output);
if (lookahead)
if (lookahead) {
break;
}
m = parenRegexp.exec(output);
if (!m)
if (!m) {
break;
}
output = output.slice(m[0].length);
var nolf = m[0].replace(/\n/g, '');
match[2] += nolf;
Expand All @@ -349,16 +362,17 @@ LogParser.MatchNewFile = (function()
output = output.slice(sepPos + 1);
var existence = TW.fileExists(basePath + match[2]);
if (m[0] == '/' || m[0] == '\\') {
if (existence == DOESNTEXIST)
if (existence == DOESNTEXIST) {
return null;
}
}
else {
if (existence == EXISTS)
break;
if (existence == MAYEXIST && filenameRegexp.test(match[2]) &&
// It seems that after a file may only be a newline
// or a space followed by another file \( or a page \[
(m[0] == '\n' || m[0] == ' ' && /^\s*[([]/.test(output))) {
(m[0] == '\n' || m[0] == ' ' && /^\s*[([<]/.test(output))) {
svmatch = match[2];
svoutput = output;
}
Expand All @@ -368,11 +382,18 @@ LogParser.MatchNewFile = (function()
len++;
}
else if (len % max_print_line) {
if (existence == DOESNTEXIST)
if (existence == DOESNTEXIST) {
if (filenameRegexp.test(match[2])) {
svmatch = match[2];
svoutput = output;
break;
}
return null;
}
if (!filenameRegexp.test(match[2])) {
if (!svmatch)
if (!svmatch) {
return null;
}
match[2] = svmatch;
output = svoutput;
}
Expand All @@ -392,28 +413,13 @@ LogParser.MatchNewFile = (function()
})();


LogParser.prototype.WarnUTF8BOM = function()
{
if (TW.target.currentCodecName != "UTF-8" || !TW.target.writeUTF8BOM)
return;
for (var i = this.Results.length-1; i >= 0; i--) {
if (this.Results[i].Description.indexOf("LaTeX Error: Missing \\begin{document}.") > -1) {
TW.warning(null, "", "The UTF-8 byte order mark can confuse some " +
"variants of TeX. You may want to disable it in the encoding popup " +
"available from the status bar.")
break;
}
}
}


LogParser.prototype.WarnAuxFiles = function()
{
for (var i = this.Results.length-1; i >= 0; i--) {
if (this.Results[i].Description.indexOf("File ended while scanning use of") > -1) {
if (TW.question(null, "", "While typesetting, a corrupt .aux " +
"file from a previous run was detected. You should remove " +
"it and rerun the typesetting process. Do you want to display" +
"it and rerun the typesetting process. Do you want to display " +
"the \"Remove Aux Files...\" dialog now?", 0x14000) == 0x4000)
TW.target.removeAuxFiles();
break;
Expand Down Expand Up @@ -498,7 +504,6 @@ LogParser.GenerateResultRow = (function()
})();



// We allow other scripts to use and reconfigure this parser
if (typeof(justLoad) == "undefined") {
var parser = new LogParser();
Expand Down
90 changes: 64 additions & 26 deletions testcases/logParser/logParserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
justLoad = null;


function GenerateDiff(expected, unexpected)
function GenerateResultDiff(expected, unexpected)
{
var s = "";
s += "<table border='0' cellspacing='0' cellpadding='4'>";
Expand Down Expand Up @@ -77,10 +77,18 @@ if (file.status == 0) {
return result;
};

var s = "";
function TestResult(expected, generated) {
this.Expected = expected;
this.Generated = generated;
var passed = expected.length == generated.length;
for (var k=0; k<expected.length && passed; k++) {
passed = Result.Equals(expected[k], generated[k]);
}
this.Passed = passed;
}

function RunTests(folder) {
var grouping = false;
var testResults = [];
for (var i = 1; ; i++) {
var filename = folder + "/" + i + ".test";
var result = TW.readFile(filename);
Expand All @@ -89,6 +97,7 @@ if (file.status == 0) {
}
result = result.result;

testResults[i] = [];
for (var j = 0; j < fex.length; j++) {
TW.fileExists = fex[j];
totalTests++;
Expand All @@ -100,40 +109,68 @@ if (file.status == 0) {

var expected = eval("(function(){return " + exp + ";})()");
var generated = parser.Results;
var testResult = new TestResult(expected, generated);
testResults[i][j] = testResult;
failedTests += testResult.Passed ? 0 : 1;
}
}
return testResults;
}

var passed = expected.length == generated.length;
for (var k=0; k<expected.length && passed; k++) {
passed = Result.Equals(expected[k], generated[k]);
}

if (!passed) {
if (grouping) {
s += "</td></tr>";
grouping = false;
function GenerateDiff(folder, testResults) {
var s = "";
var iFirst = 1;
for (var i = 1; i < testResults.length; i++) {
var jFirst = 0;
for (var j = 0; j < testResults[i].length; j++) {
var testResult = testResults[i][j];
if (!testResult.Passed) {
if (iFirst < i) {
s += "<tr>";
s += "<td style='background-color: green'></td>";
if (iFirst == i - 1) {
s += "<td valign='top' colspan='2'>" + folder + "/" + iFirst + ".test</td>";
} else {
s += "<td valign='top' colspan='2'>" + folder + "/" + iFirst + "..." + (i-1) + ".test</td>";
}
s += "</tr>";
}
if (jFirst < j) {
s += "<tr>";
s += "<td style='background-color: green'></td>";
if (jFirst == j - 1) {
s += "<td valign='top' colspan='2'>" + folder + "/" + i + "[" + jFirst + "].test</td>";
} else {
s += "<td valign='top' colspan='2'>" + folder + "/" + i + "[" + jFirst + "..." + j + "].test</td>";
}
s += "</tr>";
}
s += "<tr>";
s += "<td style='background-color: red'></td>";
s += "<td valign='top'>" + filename + " [" + j + "]</td>";
s += "<td valign='top'><font size=-2>" + GenerateDiff(expected, generated) + "</font></td>";
s += "<td valign='top'>" + folder + "/" + i + "[" + j + "].test</td>";
s += "<td valign='top'><font size=-2>" + GenerateResultDiff(testResult.Expected, testResult.Generated) + "</font></td>";
s += "</tr>";
iFirst = i + 1;
jFirst = j + 1;
}
else if (grouping) {
s += ", " + filename + " [" + j + "]";
}
else {
s += "<tr>";
s += "<td style='background-color: green'></td>";
s += "<td valign='top' colspan='2'>" + filename + " [" + j + "]";
grouping = true;
}
failedTests += passed ? 0 : 1;
}
}
if (grouping) {
s += "</td></tr>";
if (iFirst < testResults.length) {
s += "<tr>";
s += "<td style='background-color: green'></td>";
if (iFirst == testResults.length - 1) {
s += "<td valign='top' colspan='2'>" + folder + "/" + iFirst + ".test</td>";
} else {
s += "<td valign='top' colspan='2'>" + folder + "/" + iFirst + "..." + (testResults.length-1) + ".test</td>";
}
s += "</tr>";
}
return s;
}

var s = "";

var folders = [ "tests-miktex", "tests-texlive-ubuntu" ];
for (var j = 0; j < folders.length; j++) {
var files = TW.readFile(folders[j] + "/files.js");
Expand All @@ -143,7 +180,8 @@ if (file.status == 0) {
else {
files = [];
}
RunTests(folders[j]);
var testResults = RunTests(folders[j]);
s += GenerateDiff(folders[j], testResults);
}

var html = "<html><body>";
Expand Down
Loading

0 comments on commit e61cffa

Please sign in to comment.