mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #4940 from overleaf/bg-add-prettier-and-eslint-to-latex-log-parser
add prettier and eslint to latex log parser GitOrigin-RevId: 6985fb253c0e4935fae0bbae34823ab058dfb34c
This commit is contained in:
parent
eede3a26b6
commit
88a69257dc
6 changed files with 2442 additions and 544 deletions
73
libraries/latex-log-parser/.eslintrc
Normal file
73
libraries/latex-log-parser/.eslintrc
Normal file
|
@ -0,0 +1,73 @@
|
|||
// this file was auto-generated, do not edit it directly.
|
||||
// instead run bin/update_build_scripts from
|
||||
// https://github.com/sharelatex/sharelatex-dev-environment
|
||||
{
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"standard",
|
||||
"prettier"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2018
|
||||
},
|
||||
"plugins": [
|
||||
"mocha",
|
||||
"chai-expect",
|
||||
"chai-friendly"
|
||||
],
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true
|
||||
},
|
||||
"rules": {
|
||||
// Swap the no-unused-expressions rule with a more chai-friendly one
|
||||
"no-unused-expressions": 0,
|
||||
"chai-friendly/no-unused-expressions": "error",
|
||||
|
||||
// Do not allow importing of implicit dependencies.
|
||||
"import/no-extraneous-dependencies": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
// Test specific rules
|
||||
"files": ["test/**/*.js"],
|
||||
"globals": {
|
||||
"expect": true
|
||||
},
|
||||
"rules": {
|
||||
// mocha-specific rules
|
||||
"mocha/handle-done-callback": "error",
|
||||
"mocha/no-exclusive-tests": "error",
|
||||
"mocha/no-global-tests": "error",
|
||||
"mocha/no-identical-title": "error",
|
||||
"mocha/no-nested-tests": "error",
|
||||
"mocha/no-pending-tests": "error",
|
||||
"mocha/no-skipped-tests": "error",
|
||||
"mocha/no-mocha-arrows": "error",
|
||||
|
||||
// chai-specific rules
|
||||
"chai-expect/missing-assertion": "error",
|
||||
"chai-expect/terminating-properties": "error",
|
||||
|
||||
// prefer-arrow-callback applies to all callbacks, not just ones in mocha tests.
|
||||
// we don't enforce this at the top-level - just in tests to manage `this` scope
|
||||
// based on mocha's context mechanism
|
||||
"mocha/prefer-arrow-callback": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
// Backend specific rules
|
||||
"files": ["lib/**/*.js", "index.js"],
|
||||
"rules": {
|
||||
// don't allow console.log in backend code
|
||||
"no-console": "error",
|
||||
|
||||
// Do not allow importing of implicit dependencies.
|
||||
"import/no-extraneous-dependencies": ["error", {
|
||||
// Do not allow importing of devDependencies.
|
||||
"devDependencies": false
|
||||
}]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
11
libraries/latex-log-parser/.prettierrc
Normal file
11
libraries/latex-log-parser/.prettierrc
Normal file
|
@ -0,0 +1,11 @@
|
|||
# This file was auto-generated, do not edit it directly.
|
||||
# Instead run bin/update_build_scripts from
|
||||
# https://github.com/sharelatex/sharelatex-dev-environment
|
||||
{
|
||||
"arrowParens": "avoid",
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"useTabs": false
|
||||
}
|
1785
libraries/latex-log-parser/package-lock.json
generated
1785
libraries/latex-log-parser/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,14 +3,26 @@
|
|||
"version": "2.0.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"lint": "echo noop",
|
||||
"format": "echo noop",
|
||||
"test:ci": "echo noop",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"compile": "sh ./bin/compile.sh"
|
||||
"lint": "eslint --max-warnings 0 --format unix src || /bin/true",
|
||||
"lint:fix": "eslint --fix src",
|
||||
"format": "prettier --list-different $PWD/src/'**/*.js'",
|
||||
"format:fix": "prettier --write $PWD/src/'**/*.js'",
|
||||
"test:ci": "echo ci tests not implemented"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.21.0",
|
||||
"eslint-config-prettier": "^8.1.0",
|
||||
"eslint-config-standard": "^16.0.2",
|
||||
"eslint-plugin-chai-expect": "^2.2.0",
|
||||
"eslint-plugin-chai-friendly": "^0.7.2",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-mocha": "^9.0.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"eslint-plugin-promise": "^5.1.0",
|
||||
"prettier": "^2.2.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,238 +1,252 @@
|
|||
define(function() {
|
||||
|
||||
define(function () {
|
||||
// [fullLine, lineNumber, messageType, message]
|
||||
const LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/;
|
||||
const LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/
|
||||
|
||||
const MESSAGE_LEVELS = {
|
||||
"INFO": "info",
|
||||
"WARN": "warning",
|
||||
"ERROR": "error"
|
||||
};
|
||||
|
||||
const BibLogParser = function(text, options) {
|
||||
if (typeof text !== 'string') {
|
||||
throw new Error("BibLogParser Error: text parameter must be a string");
|
||||
INFO: 'info',
|
||||
WARN: 'warning',
|
||||
ERROR: 'error',
|
||||
}
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n');
|
||||
this.options = options || {};
|
||||
this.lines = text.split('\n');
|
||||
};
|
||||
|
||||
const consume = function(logText, regex, process) {
|
||||
let match;
|
||||
let text = logText;
|
||||
const result = [];
|
||||
const re = regex;
|
||||
let iterationCount = 0;
|
||||
const BibLogParser = function (text, options) {
|
||||
if (typeof text !== 'string') {
|
||||
throw new Error('BibLogParser Error: text parameter must be a string')
|
||||
}
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n')
|
||||
this.options = options || {}
|
||||
this.lines = text.split('\n')
|
||||
}
|
||||
|
||||
const consume = function (logText, regex, process) {
|
||||
let match
|
||||
let text = logText
|
||||
const result = []
|
||||
const re = regex
|
||||
let iterationCount = 0
|
||||
while ((match = re.exec(text))) {
|
||||
iterationCount += 1;
|
||||
const newEntry = process(match);
|
||||
iterationCount += 1
|
||||
const newEntry = process(match)
|
||||
|
||||
// Too many log entries can cause browser crashes
|
||||
// Construct a too many files error from the last match
|
||||
var maxErrors = 100;
|
||||
var maxErrors = 100
|
||||
if (iterationCount >= maxErrors) {
|
||||
var level = newEntry.level + "s";
|
||||
var level = newEntry.level + 's'
|
||||
newEntry.message = [
|
||||
"Over",
|
||||
'Over',
|
||||
maxErrors,
|
||||
level,
|
||||
"returned. Download raw logs to see full list"
|
||||
].join(" ");
|
||||
newEntry.line = undefined;
|
||||
result.unshift(newEntry);
|
||||
return [result, ""];
|
||||
'returned. Download raw logs to see full list',
|
||||
].join(' ')
|
||||
newEntry.line = undefined
|
||||
result.unshift(newEntry)
|
||||
return [result, '']
|
||||
}
|
||||
|
||||
result.push(newEntry);
|
||||
text = (
|
||||
(match.input.slice(0, match.index)) +
|
||||
(match.input.slice(match.index+match[0].length+1, match.input.length))
|
||||
);
|
||||
result.push(newEntry)
|
||||
text =
|
||||
match.input.slice(0, match.index) +
|
||||
match.input.slice(match.index + match[0].length + 1, match.input.length)
|
||||
}
|
||||
return [result, text]
|
||||
}
|
||||
return [result, text];
|
||||
};
|
||||
|
||||
const MULTILINE_WARNING_REGEX = /^Warning--(.+)\n--line (\d+) of file (.+)$/m;
|
||||
const SINGLELINE_WARNING_REGEX = /^Warning--(.+)$/m;
|
||||
const MULTILINE_ERROR_REGEX = /^(.*)---line (\d+) of file (.*)\n([^]+?)\nI'm skipping whatever remains of this entry$/m;
|
||||
const BAD_CROSS_REFERENCE_REGEX = /^(A bad cross reference---entry ".+?"\nrefers to entry.+?, which doesn't exist)$/m;
|
||||
const MULTILINE_COMMAND_ERROR_REGEX = /^(.*)\n?---line (\d+) of file (.*)\n([^]+?)\nI'm skipping whatever remains of this command$/m;
|
||||
const MULTILINE_WARNING_REGEX = /^Warning--(.+)\n--line (\d+) of file (.+)$/m
|
||||
const SINGLELINE_WARNING_REGEX = /^Warning--(.+)$/m
|
||||
const MULTILINE_ERROR_REGEX =
|
||||
/^(.*)---line (\d+) of file (.*)\n([^]+?)\nI'm skipping whatever remains of this entry$/m
|
||||
const BAD_CROSS_REFERENCE_REGEX =
|
||||
/^(A bad cross reference---entry ".+?"\nrefers to entry.+?, which doesn't exist)$/m
|
||||
const MULTILINE_COMMAND_ERROR_REGEX =
|
||||
/^(.*)\n?---line (\d+) of file (.*)\n([^]+?)\nI'm skipping whatever remains of this command$/m
|
||||
// Errors hit in BST file have a slightly different format
|
||||
const BST_ERROR_REGEX = /^(.*?)\nwhile executing---line (\d+) of file (.*)/m;
|
||||
const BST_ERROR_REGEX = /^(.*?)\nwhile executing---line (\d+) of file (.*)/m
|
||||
|
||||
// each parser is a pair of [regex, processFunction], where processFunction
|
||||
// describes how to transform the regex mactch into a log entry object.
|
||||
const warningParsers = [
|
||||
[
|
||||
MULTILINE_WARNING_REGEX,
|
||||
function(match) {
|
||||
const [fullMatch, message, lineNumber, fileName] = match;
|
||||
function (match) {
|
||||
const [fullMatch, message, lineNumber, fileName] = match
|
||||
return {
|
||||
file: fileName,
|
||||
level: "warning",
|
||||
level: 'warning',
|
||||
message,
|
||||
line: lineNumber,
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
SINGLELINE_WARNING_REGEX,
|
||||
function(match) {
|
||||
const [fullMatch, message] = match;
|
||||
function (match) {
|
||||
const [fullMatch, message] = match
|
||||
return {
|
||||
file: '',
|
||||
level: "warning",
|
||||
level: 'warning',
|
||||
message,
|
||||
line: '',
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
},
|
||||
],
|
||||
]
|
||||
];
|
||||
const errorParsers = [
|
||||
[
|
||||
MULTILINE_ERROR_REGEX,
|
||||
function(match) {
|
||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] = match;
|
||||
function (match) {
|
||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] =
|
||||
match
|
||||
return {
|
||||
file: fileName,
|
||||
level: "error",
|
||||
level: 'error',
|
||||
message: firstMessage + '\n' + secondMessage,
|
||||
line: lineNumber,
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
BAD_CROSS_REFERENCE_REGEX,
|
||||
function(match) {
|
||||
const [fullMatch, message] = match;
|
||||
function (match) {
|
||||
const [fullMatch, message] = match
|
||||
return {
|
||||
file: '',
|
||||
level: "error",
|
||||
level: 'error',
|
||||
message,
|
||||
line: '',
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
},
|
||||
],
|
||||
[
|
||||
MULTILINE_COMMAND_ERROR_REGEX,
|
||||
function(match) {
|
||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] = match;
|
||||
function (match) {
|
||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] =
|
||||
match
|
||||
return {
|
||||
file: fileName,
|
||||
level: "error",
|
||||
level: 'error',
|
||||
message: firstMessage + '\n' + secondMessage,
|
||||
line: lineNumber,
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
],[
|
||||
BST_ERROR_REGEX, function(match) {
|
||||
var fileName, firstMessage, fullMatch, lineNumber, secondMessage;
|
||||
fullMatch = match[0], firstMessage = match[1], lineNumber = match[2], fileName = match[3];
|
||||
},
|
||||
],
|
||||
[
|
||||
BST_ERROR_REGEX,
|
||||
function (match) {
|
||||
var fileName, firstMessage, fullMatch, lineNumber, secondMessage
|
||||
;(fullMatch = match[0]),
|
||||
(firstMessage = match[1]),
|
||||
(lineNumber = match[2]),
|
||||
(fileName = match[3])
|
||||
return {
|
||||
file: fileName,
|
||||
level: "error",
|
||||
level: 'error',
|
||||
message: firstMessage,
|
||||
line: lineNumber,
|
||||
raw: fullMatch
|
||||
};
|
||||
raw: fullMatch,
|
||||
}
|
||||
},
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
(function() {
|
||||
this.parseBibtex = function() {
|
||||
let allErrors;
|
||||
;(function () {
|
||||
this.parseBibtex = function () {
|
||||
let allErrors
|
||||
const result = {
|
||||
all: [],
|
||||
errors: [],
|
||||
warnings: [],
|
||||
files: [], // not used
|
||||
typesetting: [] // not used
|
||||
};
|
||||
typesetting: [], // not used
|
||||
}
|
||||
// reduce over the parsers, starting with the log text,
|
||||
let [allWarnings, remainingText] = warningParsers.reduce(
|
||||
function(accumulator, parser) {
|
||||
const [currentWarnings, text] = accumulator;
|
||||
const [regex, process] = parser;
|
||||
const [warnings, _remainingText] = consume(text, regex, process);
|
||||
return [currentWarnings.concat(warnings), _remainingText];
|
||||
}
|
||||
, [[], this.text]
|
||||
);
|
||||
[allErrors, remainingText] = errorParsers.reduce(
|
||||
function(accumulator, parser) {
|
||||
const [currentErrors, text] = accumulator;
|
||||
const [regex, process] = parser;
|
||||
const [errors, _remainingText] = consume(text, regex, process);
|
||||
return [currentErrors.concat(errors), _remainingText];
|
||||
}
|
||||
, [[], remainingText]
|
||||
);
|
||||
result.warnings = allWarnings;
|
||||
result.errors = allErrors;
|
||||
result.all = allWarnings.concat(allErrors);
|
||||
return result;
|
||||
function (accumulator, parser) {
|
||||
const [currentWarnings, text] = accumulator
|
||||
const [regex, process] = parser
|
||||
const [warnings, _remainingText] = consume(text, regex, process)
|
||||
return [currentWarnings.concat(warnings), _remainingText]
|
||||
},
|
||||
[[], this.text]
|
||||
)
|
||||
;[allErrors, remainingText] = errorParsers.reduce(
|
||||
function (accumulator, parser) {
|
||||
const [currentErrors, text] = accumulator
|
||||
const [regex, process] = parser
|
||||
const [errors, _remainingText] = consume(text, regex, process)
|
||||
return [currentErrors.concat(errors), _remainingText]
|
||||
},
|
||||
[[], remainingText]
|
||||
)
|
||||
result.warnings = allWarnings
|
||||
result.errors = allErrors
|
||||
result.all = allWarnings.concat(allErrors)
|
||||
return result
|
||||
}
|
||||
|
||||
this.parseBiber = function() {
|
||||
this.parseBiber = function () {
|
||||
const result = {
|
||||
all: [],
|
||||
errors: [],
|
||||
warnings: [],
|
||||
files: [], // not used
|
||||
typesetting: [] // not used
|
||||
};
|
||||
this.lines.forEach(function(line) {
|
||||
const match = line.match(LINE_SPLITTER_REGEX);
|
||||
typesetting: [], // not used
|
||||
}
|
||||
this.lines.forEach(function (line) {
|
||||
const match = line.match(LINE_SPLITTER_REGEX)
|
||||
if (match) {
|
||||
let [fullLine, lineNumber, messageType, message] = match;
|
||||
let [fullLine, lineNumber, messageType, message] = match
|
||||
const newEntry = {
|
||||
file: '',
|
||||
level: MESSAGE_LEVELS[messageType] || "INFO",
|
||||
level: MESSAGE_LEVELS[messageType] || 'INFO',
|
||||
message,
|
||||
line: '',
|
||||
raw: fullLine
|
||||
};
|
||||
raw: fullLine,
|
||||
}
|
||||
// try extract file, line-number and the 'real' message from lines like:
|
||||
// BibTeX subsystem: /.../original.bib_123.utf8, line 8, syntax error: it's bad
|
||||
const lineMatch = newEntry.message.match(/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/);
|
||||
if (lineMatch && (lineMatch.length === 4)) {
|
||||
let _, fileName, realMessage;
|
||||
[_, fileName, lineNumber, realMessage] = lineMatch;
|
||||
newEntry.file = fileName;
|
||||
newEntry.line = lineNumber;
|
||||
newEntry.message = realMessage;
|
||||
const lineMatch = newEntry.message.match(
|
||||
/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/
|
||||
)
|
||||
if (lineMatch && lineMatch.length === 4) {
|
||||
let _, fileName, realMessage
|
||||
;[_, fileName, lineNumber, realMessage] = lineMatch
|
||||
newEntry.file = fileName
|
||||
newEntry.line = lineNumber
|
||||
newEntry.message = realMessage
|
||||
}
|
||||
result.all.push(newEntry);
|
||||
result.all.push(newEntry)
|
||||
switch (newEntry.level) {
|
||||
case 'error': return result.errors.push(newEntry);
|
||||
case 'warning': return result.warnings.push(newEntry);
|
||||
case 'error':
|
||||
return result.errors.push(newEntry)
|
||||
case 'warning':
|
||||
return result.warnings.push(newEntry)
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
return this.parse = function() {
|
||||
const firstLine = this.lines[0];
|
||||
return (this.parse = function () {
|
||||
const firstLine = this.lines[0]
|
||||
if (firstLine.match(/^.*INFO - This is Biber.*$/)) {
|
||||
return this.parseBiber();
|
||||
return this.parseBiber()
|
||||
} else if (firstLine.match(/^This is BibTeX, Version.+$/)) {
|
||||
return this.parseBibtex();
|
||||
return this.parseBibtex()
|
||||
} else {
|
||||
throw new Error("BibLogParser Error: cannot determine whether text is biber or bibtex output");
|
||||
throw new Error(
|
||||
'BibLogParser Error: cannot determine whether text is biber or bibtex output'
|
||||
)
|
||||
}
|
||||
};
|
||||
})
|
||||
}.call(BibLogParser.prototype))
|
||||
|
||||
}).call(BibLogParser.prototype);
|
||||
BibLogParser.parse = (text, options) =>
|
||||
new BibLogParser(text, options).parse()
|
||||
|
||||
BibLogParser.parse = (text, options) => new BibLogParser(text, options).parse();
|
||||
|
||||
return BibLogParser;
|
||||
});
|
||||
return BibLogParser
|
||||
})
|
||||
|
|
|
@ -1,264 +1,280 @@
|
|||
define(function() {
|
||||
define(function () {
|
||||
// Define some constants
|
||||
const LOG_WRAP_LIMIT = 79;
|
||||
const LATEX_WARNING_REGEX = /^LaTeX Warning: (.*)$/;
|
||||
const HBOX_WARNING_REGEX = /^(Over|Under)full \\(v|h)box/;
|
||||
const PACKAGE_WARNING_REGEX = /^(Package \b.+\b Warning:.*)$/;
|
||||
const LOG_WRAP_LIMIT = 79
|
||||
const LATEX_WARNING_REGEX = /^LaTeX Warning: (.*)$/
|
||||
const HBOX_WARNING_REGEX = /^(Over|Under)full \\(v|h)box/
|
||||
const PACKAGE_WARNING_REGEX = /^(Package \b.+\b Warning:.*)$/
|
||||
// This is used to parse the line number from common latex warnings
|
||||
const LINES_REGEX = /lines? ([0-9]+)/;
|
||||
const LINES_REGEX = /lines? ([0-9]+)/
|
||||
// This is used to parse the package name from the package warnings
|
||||
const PACKAGE_REGEX = /^Package (\b.+\b) Warning/;
|
||||
const PACKAGE_REGEX = /^Package (\b.+\b) Warning/
|
||||
|
||||
const LogText = function(text) {
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n');
|
||||
const LogText = function (text) {
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n')
|
||||
// Join any lines which look like they have wrapped.
|
||||
const wrappedLines = this.text.split('\n');
|
||||
this.lines = [ wrappedLines[0] ];
|
||||
let i = 1;
|
||||
const wrappedLines = this.text.split('\n')
|
||||
this.lines = [wrappedLines[0]]
|
||||
let i = 1
|
||||
while (i < wrappedLines.length) {
|
||||
// If the previous line is as long as the wrap limit then
|
||||
// append this line to it.
|
||||
// Some lines end with ... when LaTeX knows it's hit the limit
|
||||
// These shouldn't be wrapped.
|
||||
if ((wrappedLines[i - 1].length === LOG_WRAP_LIMIT) && (wrappedLines[i - 1].slice(-3) !== '...')) {
|
||||
this.lines[this.lines.length - 1] += wrappedLines[i];
|
||||
if (
|
||||
wrappedLines[i - 1].length === LOG_WRAP_LIMIT &&
|
||||
wrappedLines[i - 1].slice(-3) !== '...'
|
||||
) {
|
||||
this.lines[this.lines.length - 1] += wrappedLines[i]
|
||||
} else {
|
||||
this.lines.push(wrappedLines[i]);
|
||||
this.lines.push(wrappedLines[i])
|
||||
}
|
||||
i++;
|
||||
i++
|
||||
}
|
||||
this.row = 0
|
||||
}
|
||||
this.row = 0;
|
||||
};
|
||||
|
||||
(function() {
|
||||
this.nextLine = function() {
|
||||
this.row++;
|
||||
;(function () {
|
||||
this.nextLine = function () {
|
||||
this.row++
|
||||
if (this.row >= this.lines.length) {
|
||||
return false;
|
||||
return false
|
||||
} else {
|
||||
return this.lines[this.row];
|
||||
return this.lines[this.row]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.rewindLine = function() {
|
||||
this.row--;
|
||||
};
|
||||
this.rewindLine = function () {
|
||||
this.row--
|
||||
}
|
||||
|
||||
this.linesUpToNextWhitespaceLine = function() {
|
||||
return this.linesUpToNextMatchingLine(/^ *$/);
|
||||
};
|
||||
this.linesUpToNextWhitespaceLine = function () {
|
||||
return this.linesUpToNextMatchingLine(/^ *$/)
|
||||
}
|
||||
|
||||
this.linesUpToNextMatchingLine = function(match) {
|
||||
const lines = [];
|
||||
let nextLine = this.nextLine();
|
||||
this.linesUpToNextMatchingLine = function (match) {
|
||||
const lines = []
|
||||
let nextLine = this.nextLine()
|
||||
if (nextLine !== false) {
|
||||
lines.push(nextLine);
|
||||
lines.push(nextLine)
|
||||
}
|
||||
while ((nextLine !== false) && !nextLine.match(match) && (nextLine !== false)) {
|
||||
nextLine = this.nextLine();
|
||||
while (
|
||||
nextLine !== false &&
|
||||
!nextLine.match(match) &&
|
||||
nextLine !== false
|
||||
) {
|
||||
nextLine = this.nextLine()
|
||||
if (nextLine !== false) {
|
||||
lines.push(nextLine);
|
||||
lines.push(nextLine)
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
|
||||
}).call(LogText.prototype);
|
||||
return lines
|
||||
}
|
||||
}.call(LogText.prototype))
|
||||
|
||||
const state = {
|
||||
NORMAL: 0,
|
||||
ERROR: 1
|
||||
};
|
||||
ERROR: 1,
|
||||
}
|
||||
|
||||
const LatexParser = function(text, options) {
|
||||
this.log = new LogText(text);
|
||||
this.state = state.NORMAL;
|
||||
options = options || {};
|
||||
this.fileBaseNames = options.fileBaseNames || [
|
||||
/compiles/,
|
||||
/\/usr\/local/
|
||||
];
|
||||
this.ignoreDuplicates = options.ignoreDuplicates;
|
||||
this.data = [];
|
||||
this.fileStack = [];
|
||||
this.currentFileList = (this.rootFileList = []);
|
||||
this.openParens = 0;
|
||||
};
|
||||
const LatexParser = function (text, options) {
|
||||
this.log = new LogText(text)
|
||||
this.state = state.NORMAL
|
||||
options = options || {}
|
||||
this.fileBaseNames = options.fileBaseNames || [/compiles/, /\/usr\/local/]
|
||||
this.ignoreDuplicates = options.ignoreDuplicates
|
||||
this.data = []
|
||||
this.fileStack = []
|
||||
this.currentFileList = this.rootFileList = []
|
||||
this.openParens = 0
|
||||
}
|
||||
|
||||
(function() {
|
||||
this.parse = function() {
|
||||
;(function () {
|
||||
this.parse = function () {
|
||||
while ((this.currentLine = this.log.nextLine()) !== false) {
|
||||
if (this.state === state.NORMAL) {
|
||||
if (this.currentLineIsError()) {
|
||||
this.state = state.ERROR;
|
||||
this.state = state.ERROR
|
||||
this.currentError = {
|
||||
line: null,
|
||||
file: this.currentFilePath,
|
||||
level: 'error',
|
||||
message: this.currentLine.slice(2),
|
||||
content: '',
|
||||
raw: this.currentLine + '\n'
|
||||
};
|
||||
raw: this.currentLine + '\n',
|
||||
}
|
||||
} else if (this.currentLineIsRunawayArgument()) {
|
||||
this.parseRunawayArgumentError();
|
||||
this.parseRunawayArgumentError()
|
||||
} else if (this.currentLineIsWarning()) {
|
||||
this.parseSingleWarningLine(LATEX_WARNING_REGEX);
|
||||
this.parseSingleWarningLine(LATEX_WARNING_REGEX)
|
||||
} else if (this.currentLineIsHboxWarning()) {
|
||||
this.parseHboxLine();
|
||||
this.parseHboxLine()
|
||||
} else if (this.currentLineIsPackageWarning()) {
|
||||
this.parseMultipleWarningLine();
|
||||
this.parseMultipleWarningLine()
|
||||
} else {
|
||||
this.parseParensForFilenames();
|
||||
this.parseParensForFilenames()
|
||||
}
|
||||
}
|
||||
if (this.state === state.ERROR) {
|
||||
this.currentError.content += this.log.linesUpToNextMatchingLine(/^l\.[0-9]+/).join('\n');
|
||||
this.currentError.content += '\n';
|
||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
||||
this.currentError.content += '\n';
|
||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
||||
this.currentError.raw += this.currentError.content;
|
||||
const lineNo = this.currentError.raw.match(/l\.([0-9]+)/);
|
||||
this.currentError.content += this.log
|
||||
.linesUpToNextMatchingLine(/^l\.[0-9]+/)
|
||||
.join('\n')
|
||||
this.currentError.content += '\n'
|
||||
this.currentError.content += this.log
|
||||
.linesUpToNextWhitespaceLine()
|
||||
.join('\n')
|
||||
this.currentError.content += '\n'
|
||||
this.currentError.content += this.log
|
||||
.linesUpToNextWhitespaceLine()
|
||||
.join('\n')
|
||||
this.currentError.raw += this.currentError.content
|
||||
const lineNo = this.currentError.raw.match(/l\.([0-9]+)/)
|
||||
if (lineNo) {
|
||||
this.currentError.line = parseInt(lineNo[1], 10);
|
||||
this.currentError.line = parseInt(lineNo[1], 10)
|
||||
}
|
||||
this.data.push(this.currentError);
|
||||
this.state = state.NORMAL;
|
||||
this.data.push(this.currentError)
|
||||
this.state = state.NORMAL
|
||||
}
|
||||
}
|
||||
return this.postProcess(this.data);
|
||||
};
|
||||
return this.postProcess(this.data)
|
||||
}
|
||||
|
||||
this.currentLineIsError = function() {
|
||||
return this.currentLine[0] === '!';
|
||||
};
|
||||
this.currentLineIsError = function () {
|
||||
return this.currentLine[0] === '!'
|
||||
}
|
||||
|
||||
this.currentLineIsRunawayArgument = function() {
|
||||
return this.currentLine.match(/^Runaway argument/);
|
||||
};
|
||||
this.currentLineIsRunawayArgument = function () {
|
||||
return this.currentLine.match(/^Runaway argument/)
|
||||
}
|
||||
|
||||
this.currentLineIsWarning = function() {
|
||||
return !!this.currentLine.match(LATEX_WARNING_REGEX);
|
||||
};
|
||||
this.currentLineIsWarning = function () {
|
||||
return !!this.currentLine.match(LATEX_WARNING_REGEX)
|
||||
}
|
||||
|
||||
this.currentLineIsPackageWarning = function() {
|
||||
return !!this.currentLine.match(PACKAGE_WARNING_REGEX);
|
||||
};
|
||||
this.currentLineIsPackageWarning = function () {
|
||||
return !!this.currentLine.match(PACKAGE_WARNING_REGEX)
|
||||
}
|
||||
|
||||
this.currentLineIsHboxWarning = function() {
|
||||
return !!this.currentLine.match(HBOX_WARNING_REGEX);
|
||||
};
|
||||
this.currentLineIsHboxWarning = function () {
|
||||
return !!this.currentLine.match(HBOX_WARNING_REGEX)
|
||||
}
|
||||
|
||||
this.parseRunawayArgumentError = function() {
|
||||
this.parseRunawayArgumentError = function () {
|
||||
this.currentError = {
|
||||
line: null,
|
||||
file: this.currentFilePath,
|
||||
level: 'error',
|
||||
message: this.currentLine,
|
||||
content: '',
|
||||
raw: this.currentLine + '\n'
|
||||
};
|
||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
||||
this.currentError.content += '\n';
|
||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
||||
this.currentError.raw += this.currentError.content;
|
||||
const lineNo = this.currentError.raw.match(/l\.([0-9]+)/);
|
||||
raw: this.currentLine + '\n',
|
||||
}
|
||||
this.currentError.content += this.log
|
||||
.linesUpToNextWhitespaceLine()
|
||||
.join('\n')
|
||||
this.currentError.content += '\n'
|
||||
this.currentError.content += this.log
|
||||
.linesUpToNextWhitespaceLine()
|
||||
.join('\n')
|
||||
this.currentError.raw += this.currentError.content
|
||||
const lineNo = this.currentError.raw.match(/l\.([0-9]+)/)
|
||||
if (lineNo) {
|
||||
this.currentError.line = parseInt(lineNo[1], 10);
|
||||
this.currentError.line = parseInt(lineNo[1], 10)
|
||||
}
|
||||
return this.data.push(this.currentError)
|
||||
}
|
||||
return this.data.push(this.currentError);
|
||||
};
|
||||
|
||||
this.parseSingleWarningLine = function(prefix_regex) {
|
||||
const warningMatch = this.currentLine.match(prefix_regex);
|
||||
this.parseSingleWarningLine = function (prefix_regex) {
|
||||
const warningMatch = this.currentLine.match(prefix_regex)
|
||||
if (!warningMatch) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
const warning = warningMatch[1];
|
||||
const lineMatch = warning.match(LINES_REGEX);
|
||||
const line = lineMatch ? parseInt(lineMatch[1], 10) : null;
|
||||
const warning = warningMatch[1]
|
||||
const lineMatch = warning.match(LINES_REGEX)
|
||||
const line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||
this.data.push({
|
||||
line,
|
||||
file: this.currentFilePath,
|
||||
level: 'warning',
|
||||
message: warning,
|
||||
raw: warning
|
||||
});
|
||||
};
|
||||
raw: warning,
|
||||
})
|
||||
}
|
||||
|
||||
this.parseMultipleWarningLine = function() {
|
||||
this.parseMultipleWarningLine = function () {
|
||||
// Some package warnings are multiple lines, let's parse the first line
|
||||
let warningMatch = this.currentLine.match(PACKAGE_WARNING_REGEX);
|
||||
let warningMatch = this.currentLine.match(PACKAGE_WARNING_REGEX)
|
||||
if (!warningMatch) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
// Something strange happened, return early
|
||||
const warning_lines = [ warningMatch[1] ];
|
||||
let lineMatch = this.currentLine.match(LINES_REGEX);
|
||||
let line = lineMatch ? parseInt(lineMatch[1], 10) : null;
|
||||
const packageMatch = this.currentLine.match(PACKAGE_REGEX);
|
||||
const packageName = packageMatch[1];
|
||||
const warning_lines = [warningMatch[1]]
|
||||
let lineMatch = this.currentLine.match(LINES_REGEX)
|
||||
let line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||
const packageMatch = this.currentLine.match(PACKAGE_REGEX)
|
||||
const packageName = packageMatch[1]
|
||||
// Regex to get rid of the unnecesary (packagename) prefix in most multi-line warnings
|
||||
const prefixRegex = new RegExp('(?:\\(' + packageName + '\\))*[\\s]*(.*)', 'i');
|
||||
const prefixRegex = new RegExp(
|
||||
'(?:\\(' + packageName + '\\))*[\\s]*(.*)',
|
||||
'i'
|
||||
)
|
||||
// After every warning message there's a blank line, let's use it
|
||||
while (!!(this.currentLine = this.log.nextLine())) {
|
||||
lineMatch = this.currentLine.match(LINES_REGEX);
|
||||
line = lineMatch ? parseInt(lineMatch[1], 10) : line;
|
||||
warningMatch = this.currentLine.match(prefixRegex);
|
||||
warning_lines.push(warningMatch[1]);
|
||||
lineMatch = this.currentLine.match(LINES_REGEX)
|
||||
line = lineMatch ? parseInt(lineMatch[1], 10) : line
|
||||
warningMatch = this.currentLine.match(prefixRegex)
|
||||
warning_lines.push(warningMatch[1])
|
||||
}
|
||||
const raw_message = warning_lines.join(' ');
|
||||
const raw_message = warning_lines.join(' ')
|
||||
this.data.push({
|
||||
line,
|
||||
file: this.currentFilePath,
|
||||
level: 'warning',
|
||||
message: raw_message,
|
||||
raw: raw_message
|
||||
});
|
||||
};
|
||||
raw: raw_message,
|
||||
})
|
||||
}
|
||||
|
||||
this.parseHboxLine = function() {
|
||||
const lineMatch = this.currentLine.match(LINES_REGEX);
|
||||
const line = lineMatch ? parseInt(lineMatch[1], 10) : null;
|
||||
this.parseHboxLine = function () {
|
||||
const lineMatch = this.currentLine.match(LINES_REGEX)
|
||||
const line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||
this.data.push({
|
||||
line,
|
||||
file: this.currentFilePath,
|
||||
level: 'typesetting',
|
||||
message: this.currentLine,
|
||||
raw: this.currentLine
|
||||
});
|
||||
};
|
||||
raw: this.currentLine,
|
||||
})
|
||||
}
|
||||
|
||||
// Check if we're entering or leaving a new file in this line
|
||||
|
||||
this.parseParensForFilenames = function() {
|
||||
const pos = this.currentLine.search(/\(|\)/);
|
||||
this.parseParensForFilenames = function () {
|
||||
const pos = this.currentLine.search(/\(|\)/)
|
||||
if (pos !== -1) {
|
||||
const token = this.currentLine[pos];
|
||||
this.currentLine = this.currentLine.slice(pos + 1);
|
||||
const token = this.currentLine[pos]
|
||||
this.currentLine = this.currentLine.slice(pos + 1)
|
||||
if (token === '(') {
|
||||
const filePath = this.consumeFilePath();
|
||||
const filePath = this.consumeFilePath()
|
||||
if (filePath) {
|
||||
this.currentFilePath = filePath;
|
||||
this.currentFilePath = filePath
|
||||
const newFile = {
|
||||
path: filePath,
|
||||
files: []
|
||||
};
|
||||
this.fileStack.push(newFile);
|
||||
this.currentFileList.push(newFile);
|
||||
this.currentFileList = newFile.files;
|
||||
files: [],
|
||||
}
|
||||
this.fileStack.push(newFile)
|
||||
this.currentFileList.push(newFile)
|
||||
this.currentFileList = newFile.files
|
||||
} else {
|
||||
this.openParens++;
|
||||
this.openParens++
|
||||
}
|
||||
} else if (token === ')') {
|
||||
if (this.openParens > 0) {
|
||||
this.openParens--;
|
||||
this.openParens--
|
||||
} else {
|
||||
if (this.fileStack.length > 1) {
|
||||
this.fileStack.pop();
|
||||
const previousFile = this.fileStack[this.fileStack.length - 1];
|
||||
this.currentFilePath = previousFile.path;
|
||||
this.currentFileList = previousFile.files;
|
||||
this.fileStack.pop()
|
||||
const previousFile = this.fileStack[this.fileStack.length - 1]
|
||||
this.currentFilePath = previousFile.path
|
||||
this.currentFileList = previousFile.files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -266,67 +282,66 @@ define(function() {
|
|||
// Something has gone wrong but all we can do now is ignore it :(
|
||||
// }
|
||||
// Process the rest of the line
|
||||
this.parseParensForFilenames();
|
||||
this.parseParensForFilenames()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.consumeFilePath = function() {
|
||||
this.consumeFilePath = function () {
|
||||
// Our heuristic for detecting file names are rather crude
|
||||
// A file may not contain a space, or ) in it
|
||||
// To be a file path it must have at least one /
|
||||
if (!this.currentLine.match(/^\/?([^ \)]+\/)+/)) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
const endOfFilePath = this.currentLine.search(RegExp(' |\\)'));
|
||||
let path = undefined;
|
||||
const endOfFilePath = this.currentLine.search(RegExp(' |\\)'))
|
||||
let path = undefined
|
||||
if (endOfFilePath === -1) {
|
||||
path = this.currentLine;
|
||||
this.currentLine = '';
|
||||
path = this.currentLine
|
||||
this.currentLine = ''
|
||||
} else {
|
||||
path = this.currentLine.slice(0, endOfFilePath);
|
||||
this.currentLine = this.currentLine.slice(endOfFilePath);
|
||||
path = this.currentLine.slice(0, endOfFilePath)
|
||||
this.currentLine = this.currentLine.slice(endOfFilePath)
|
||||
}
|
||||
return path
|
||||
}
|
||||
return path;
|
||||
};
|
||||
|
||||
this.postProcess = function(data) {
|
||||
const all = [];
|
||||
const errors = [];
|
||||
const warnings = [];
|
||||
const typesetting = [];
|
||||
const hashes = [];
|
||||
this.postProcess = function (data) {
|
||||
const all = []
|
||||
const errors = []
|
||||
const warnings = []
|
||||
const typesetting = []
|
||||
const hashes = []
|
||||
|
||||
const hashEntry = entry => entry.raw;
|
||||
const hashEntry = entry => entry.raw
|
||||
|
||||
let i = 0;
|
||||
let i = 0
|
||||
while (i < data.length) {
|
||||
if (this.ignoreDuplicates && (hashes.indexOf(hashEntry(data[i])) > -1)) {
|
||||
i++;
|
||||
continue;
|
||||
if (this.ignoreDuplicates && hashes.indexOf(hashEntry(data[i])) > -1) {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (data[i].level === 'error') {
|
||||
errors.push(data[i]);
|
||||
errors.push(data[i])
|
||||
} else if (data[i].level === 'typesetting') {
|
||||
typesetting.push(data[i]);
|
||||
typesetting.push(data[i])
|
||||
} else if (data[i].level === 'warning') {
|
||||
warnings.push(data[i]);
|
||||
warnings.push(data[i])
|
||||
}
|
||||
all.push(data[i]);
|
||||
hashes.push(hashEntry(data[i]));
|
||||
i++;
|
||||
all.push(data[i])
|
||||
hashes.push(hashEntry(data[i]))
|
||||
i++
|
||||
}
|
||||
return {
|
||||
errors,
|
||||
warnings,
|
||||
typesetting,
|
||||
all,
|
||||
files: this.rootFileList
|
||||
};
|
||||
};
|
||||
files: this.rootFileList,
|
||||
}
|
||||
}
|
||||
}.call(LatexParser.prototype))
|
||||
|
||||
}).call(LatexParser.prototype);
|
||||
LatexParser.parse = (text, options) => new LatexParser(text, options).parse()
|
||||
|
||||
LatexParser.parse = (text, options) => new LatexParser(text, options).parse();
|
||||
|
||||
return LatexParser;
|
||||
});
|
||||
return LatexParser
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue