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",
|
"version": "2.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "echo noop",
|
"lint": "eslint --max-warnings 0 --format unix src || /bin/true",
|
||||||
"format": "echo noop",
|
"lint:fix": "eslint --fix src",
|
||||||
"test:ci": "echo noop",
|
"format": "prettier --list-different $PWD/src/'**/*.js'",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"format:fix": "prettier --write $PWD/src/'**/*.js'",
|
||||||
"compile": "sh ./bin/compile.sh"
|
"test:ci": "echo ci tests not implemented"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"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(.*)$/
|
||||||
|
|
||||||
// [fullLine, lineNumber, messageType, message]
|
const MESSAGE_LEVELS = {
|
||||||
const LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/;
|
INFO: 'info',
|
||||||
|
WARN: 'warning',
|
||||||
|
ERROR: 'error',
|
||||||
|
}
|
||||||
|
|
||||||
const MESSAGE_LEVELS = {
|
const BibLogParser = function (text, options) {
|
||||||
"INFO": "info",
|
if (typeof text !== 'string') {
|
||||||
"WARN": "warning",
|
throw new Error('BibLogParser Error: text parameter must be a string')
|
||||||
"ERROR": "error"
|
}
|
||||||
};
|
this.text = text.replace(/(\r\n)|\r/g, '\n')
|
||||||
|
this.options = options || {}
|
||||||
|
this.lines = text.split('\n')
|
||||||
|
}
|
||||||
|
|
||||||
const BibLogParser = function(text, options) {
|
const consume = function (logText, regex, process) {
|
||||||
if (typeof text !== 'string') {
|
let match
|
||||||
throw new Error("BibLogParser Error: text parameter must be a string");
|
let text = logText
|
||||||
}
|
const result = []
|
||||||
this.text = text.replace(/(\r\n)|\r/g, '\n');
|
const re = regex
|
||||||
this.options = options || {};
|
let iterationCount = 0
|
||||||
this.lines = text.split('\n');
|
while ((match = re.exec(text))) {
|
||||||
};
|
iterationCount += 1
|
||||||
|
const newEntry = process(match)
|
||||||
|
|
||||||
const consume = function(logText, regex, process) {
|
// Too many log entries can cause browser crashes
|
||||||
let match;
|
// Construct a too many files error from the last match
|
||||||
let text = logText;
|
var maxErrors = 100
|
||||||
const result = [];
|
if (iterationCount >= maxErrors) {
|
||||||
const re = regex;
|
var level = newEntry.level + 's'
|
||||||
let iterationCount = 0;
|
newEntry.message = [
|
||||||
while ((match = re.exec(text))) {
|
'Over',
|
||||||
iterationCount += 1;
|
maxErrors,
|
||||||
const newEntry = process(match);
|
level,
|
||||||
|
'returned. Download raw logs to see full list',
|
||||||
|
].join(' ')
|
||||||
|
newEntry.line = undefined
|
||||||
|
result.unshift(newEntry)
|
||||||
|
return [result, '']
|
||||||
|
}
|
||||||
|
|
||||||
// Too many log entries can cause browser crashes
|
result.push(newEntry)
|
||||||
// Construct a too many files error from the last match
|
text =
|
||||||
var maxErrors = 100;
|
match.input.slice(0, match.index) +
|
||||||
if (iterationCount >= maxErrors) {
|
match.input.slice(match.index + match[0].length + 1, match.input.length)
|
||||||
var level = newEntry.level + "s";
|
}
|
||||||
newEntry.message = [
|
return [result, text]
|
||||||
"Over",
|
}
|
||||||
maxErrors,
|
|
||||||
level,
|
|
||||||
"returned. Download raw logs to see full list"
|
|
||||||
].join(" ");
|
|
||||||
newEntry.line = undefined;
|
|
||||||
result.unshift(newEntry);
|
|
||||||
return [result, ""];
|
|
||||||
}
|
|
||||||
|
|
||||||
result.push(newEntry);
|
const MULTILINE_WARNING_REGEX = /^Warning--(.+)\n--line (\d+) of file (.+)$/m
|
||||||
text = (
|
const SINGLELINE_WARNING_REGEX = /^Warning--(.+)$/m
|
||||||
(match.input.slice(0, match.index)) +
|
const MULTILINE_ERROR_REGEX =
|
||||||
(match.input.slice(match.index+match[0].length+1, match.input.length))
|
/^(.*)---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
|
||||||
return [result, text];
|
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 MULTILINE_WARNING_REGEX = /^Warning--(.+)\n--line (\d+) of file (.+)$/m;
|
// each parser is a pair of [regex, processFunction], where processFunction
|
||||||
const SINGLELINE_WARNING_REGEX = /^Warning--(.+)$/m;
|
// describes how to transform the regex mactch into a log entry object.
|
||||||
const MULTILINE_ERROR_REGEX = /^(.*)---line (\d+) of file (.*)\n([^]+?)\nI'm skipping whatever remains of this entry$/m;
|
const warningParsers = [
|
||||||
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;
|
MULTILINE_WARNING_REGEX,
|
||||||
// Errors hit in BST file have a slightly different format
|
function (match) {
|
||||||
const BST_ERROR_REGEX = /^(.*?)\nwhile executing---line (\d+) of file (.*)/m;
|
const [fullMatch, message, lineNumber, fileName] = match
|
||||||
|
return {
|
||||||
|
file: fileName,
|
||||||
|
level: 'warning',
|
||||||
|
message,
|
||||||
|
line: lineNumber,
|
||||||
|
raw: fullMatch,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
SINGLELINE_WARNING_REGEX,
|
||||||
|
function (match) {
|
||||||
|
const [fullMatch, message] = match
|
||||||
|
return {
|
||||||
|
file: '',
|
||||||
|
level: 'warning',
|
||||||
|
message,
|
||||||
|
line: '',
|
||||||
|
raw: fullMatch,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
const errorParsers = [
|
||||||
|
[
|
||||||
|
MULTILINE_ERROR_REGEX,
|
||||||
|
function (match) {
|
||||||
|
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] =
|
||||||
|
match
|
||||||
|
return {
|
||||||
|
file: fileName,
|
||||||
|
level: 'error',
|
||||||
|
message: firstMessage + '\n' + secondMessage,
|
||||||
|
line: lineNumber,
|
||||||
|
raw: fullMatch,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
BAD_CROSS_REFERENCE_REGEX,
|
||||||
|
function (match) {
|
||||||
|
const [fullMatch, message] = match
|
||||||
|
return {
|
||||||
|
file: '',
|
||||||
|
level: 'error',
|
||||||
|
message,
|
||||||
|
line: '',
|
||||||
|
raw: fullMatch,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
MULTILINE_COMMAND_ERROR_REGEX,
|
||||||
|
function (match) {
|
||||||
|
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] =
|
||||||
|
match
|
||||||
|
return {
|
||||||
|
file: fileName,
|
||||||
|
level: 'error',
|
||||||
|
message: firstMessage + '\n' + secondMessage,
|
||||||
|
line: lineNumber,
|
||||||
|
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])
|
||||||
|
return {
|
||||||
|
file: fileName,
|
||||||
|
level: 'error',
|
||||||
|
message: firstMessage,
|
||||||
|
line: lineNumber,
|
||||||
|
raw: fullMatch,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
// each parser is a pair of [regex, processFunction], where processFunction
|
;(function () {
|
||||||
// describes how to transform the regex mactch into a log entry object.
|
this.parseBibtex = function () {
|
||||||
const warningParsers = [
|
let allErrors
|
||||||
[
|
const result = {
|
||||||
MULTILINE_WARNING_REGEX,
|
all: [],
|
||||||
function(match) {
|
errors: [],
|
||||||
const [fullMatch, message, lineNumber, fileName] = match;
|
warnings: [],
|
||||||
return {
|
files: [], // not used
|
||||||
file: fileName,
|
typesetting: [], // not used
|
||||||
level: "warning",
|
}
|
||||||
message,
|
// reduce over the parsers, starting with the log text,
|
||||||
line: lineNumber,
|
let [allWarnings, remainingText] = warningParsers.reduce(
|
||||||
raw: fullMatch
|
function (accumulator, parser) {
|
||||||
};
|
const [currentWarnings, text] = accumulator
|
||||||
}
|
const [regex, process] = parser
|
||||||
],
|
const [warnings, _remainingText] = consume(text, regex, process)
|
||||||
[
|
return [currentWarnings.concat(warnings), _remainingText]
|
||||||
SINGLELINE_WARNING_REGEX,
|
},
|
||||||
function(match) {
|
[[], this.text]
|
||||||
const [fullMatch, message] = match;
|
)
|
||||||
return {
|
;[allErrors, remainingText] = errorParsers.reduce(
|
||||||
file: '',
|
function (accumulator, parser) {
|
||||||
level: "warning",
|
const [currentErrors, text] = accumulator
|
||||||
message,
|
const [regex, process] = parser
|
||||||
line: '',
|
const [errors, _remainingText] = consume(text, regex, process)
|
||||||
raw: fullMatch
|
return [currentErrors.concat(errors), _remainingText]
|
||||||
};
|
},
|
||||||
}
|
[[], remainingText]
|
||||||
]
|
)
|
||||||
];
|
result.warnings = allWarnings
|
||||||
const errorParsers = [
|
result.errors = allErrors
|
||||||
[
|
result.all = allWarnings.concat(allErrors)
|
||||||
MULTILINE_ERROR_REGEX,
|
return result
|
||||||
function(match) {
|
|
||||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] = match;
|
|
||||||
return {
|
|
||||||
file: fileName,
|
|
||||||
level: "error",
|
|
||||||
message: firstMessage + '\n' + secondMessage,
|
|
||||||
line: lineNumber,
|
|
||||||
raw: fullMatch
|
|
||||||
};
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
BAD_CROSS_REFERENCE_REGEX,
|
|
||||||
function(match) {
|
|
||||||
const [fullMatch, message] = match;
|
|
||||||
return {
|
|
||||||
file: '',
|
|
||||||
level: "error",
|
|
||||||
message,
|
|
||||||
line: '',
|
|
||||||
raw: fullMatch
|
|
||||||
};
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
MULTILINE_COMMAND_ERROR_REGEX,
|
|
||||||
function(match) {
|
|
||||||
const [fullMatch, firstMessage, lineNumber, fileName, secondMessage] = match;
|
|
||||||
return {
|
|
||||||
file: fileName,
|
|
||||||
level: "error",
|
|
||||||
message: firstMessage + '\n' + secondMessage,
|
|
||||||
line: lineNumber,
|
|
||||||
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];
|
|
||||||
return {
|
|
||||||
file: fileName,
|
|
||||||
level: "error",
|
|
||||||
message: firstMessage,
|
|
||||||
line: lineNumber,
|
|
||||||
raw: fullMatch
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
this.parseBibtex = function() {
|
|
||||||
let allErrors;
|
|
||||||
const result = {
|
|
||||||
all: [],
|
|
||||||
errors: [],
|
|
||||||
warnings: [],
|
|
||||||
files: [], // 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parseBiber = function() {
|
this.parseBiber = function () {
|
||||||
const result = {
|
const result = {
|
||||||
all: [],
|
all: [],
|
||||||
errors: [],
|
errors: [],
|
||||||
warnings: [],
|
warnings: [],
|
||||||
files: [], // not used
|
files: [], // not used
|
||||||
typesetting: [] // not used
|
typesetting: [], // not used
|
||||||
};
|
}
|
||||||
this.lines.forEach(function(line) {
|
this.lines.forEach(function (line) {
|
||||||
const match = line.match(LINE_SPLITTER_REGEX);
|
const match = line.match(LINE_SPLITTER_REGEX)
|
||||||
if (match) {
|
if (match) {
|
||||||
let [fullLine, lineNumber, messageType, message] = match;
|
let [fullLine, lineNumber, messageType, message] = match
|
||||||
const newEntry = {
|
const newEntry = {
|
||||||
file: '',
|
file: '',
|
||||||
level: MESSAGE_LEVELS[messageType] || "INFO",
|
level: MESSAGE_LEVELS[messageType] || 'INFO',
|
||||||
message,
|
message,
|
||||||
line: '',
|
line: '',
|
||||||
raw: fullLine
|
raw: fullLine,
|
||||||
};
|
}
|
||||||
// try extract file, line-number and the 'real' message from lines like:
|
// 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
|
// BibTeX subsystem: /.../original.bib_123.utf8, line 8, syntax error: it's bad
|
||||||
const lineMatch = newEntry.message.match(/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/);
|
const lineMatch = newEntry.message.match(
|
||||||
if (lineMatch && (lineMatch.length === 4)) {
|
/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/
|
||||||
let _, fileName, realMessage;
|
)
|
||||||
[_, fileName, lineNumber, realMessage] = lineMatch;
|
if (lineMatch && lineMatch.length === 4) {
|
||||||
newEntry.file = fileName;
|
let _, fileName, realMessage
|
||||||
newEntry.line = lineNumber;
|
;[_, fileName, lineNumber, realMessage] = lineMatch
|
||||||
newEntry.message = realMessage;
|
newEntry.file = fileName
|
||||||
}
|
newEntry.line = lineNumber
|
||||||
result.all.push(newEntry);
|
newEntry.message = realMessage
|
||||||
switch (newEntry.level) {
|
}
|
||||||
case 'error': return result.errors.push(newEntry);
|
result.all.push(newEntry)
|
||||||
case 'warning': return result.warnings.push(newEntry);
|
switch (newEntry.level) {
|
||||||
}
|
case 'error':
|
||||||
}
|
return result.errors.push(newEntry)
|
||||||
});
|
case 'warning':
|
||||||
return result;
|
return result.warnings.push(newEntry)
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
return this.parse = function() {
|
return (this.parse = function () {
|
||||||
const firstLine = this.lines[0];
|
const firstLine = this.lines[0]
|
||||||
if (firstLine.match(/^.*INFO - This is Biber.*$/)) {
|
if (firstLine.match(/^.*INFO - This is Biber.*$/)) {
|
||||||
return this.parseBiber();
|
return this.parseBiber()
|
||||||
} else if (firstLine.match(/^This is BibTeX, Version.+$/)) {
|
} else if (firstLine.match(/^This is BibTeX, Version.+$/)) {
|
||||||
return this.parseBibtex();
|
return this.parseBibtex()
|
||||||
} else {
|
} 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,332 +1,347 @@
|
||||||
define(function() {
|
define(function () {
|
||||||
// Define some constants
|
// Define some constants
|
||||||
const LOG_WRAP_LIMIT = 79;
|
const LOG_WRAP_LIMIT = 79
|
||||||
const LATEX_WARNING_REGEX = /^LaTeX Warning: (.*)$/;
|
const LATEX_WARNING_REGEX = /^LaTeX Warning: (.*)$/
|
||||||
const HBOX_WARNING_REGEX = /^(Over|Under)full \\(v|h)box/;
|
const HBOX_WARNING_REGEX = /^(Over|Under)full \\(v|h)box/
|
||||||
const PACKAGE_WARNING_REGEX = /^(Package \b.+\b Warning:.*)$/;
|
const PACKAGE_WARNING_REGEX = /^(Package \b.+\b Warning:.*)$/
|
||||||
// This is used to parse the line number from common latex warnings
|
// 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
|
// 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) {
|
const LogText = function (text) {
|
||||||
this.text = text.replace(/(\r\n)|\r/g, '\n');
|
this.text = text.replace(/(\r\n)|\r/g, '\n')
|
||||||
// Join any lines which look like they have wrapped.
|
// Join any lines which look like they have wrapped.
|
||||||
const wrappedLines = this.text.split('\n');
|
const wrappedLines = this.text.split('\n')
|
||||||
this.lines = [ wrappedLines[0] ];
|
this.lines = [wrappedLines[0]]
|
||||||
let i = 1;
|
let i = 1
|
||||||
while (i < wrappedLines.length) {
|
while (i < wrappedLines.length) {
|
||||||
// If the previous line is as long as the wrap limit then
|
// If the previous line is as long as the wrap limit then
|
||||||
// append this line to it.
|
// append this line to it.
|
||||||
// Some lines end with ... when LaTeX knows it's hit the limit
|
// Some lines end with ... when LaTeX knows it's hit the limit
|
||||||
// These shouldn't be wrapped.
|
// These shouldn't be wrapped.
|
||||||
if ((wrappedLines[i - 1].length === LOG_WRAP_LIMIT) && (wrappedLines[i - 1].slice(-3) !== '...')) {
|
if (
|
||||||
this.lines[this.lines.length - 1] += wrappedLines[i];
|
wrappedLines[i - 1].length === LOG_WRAP_LIMIT &&
|
||||||
} else {
|
wrappedLines[i - 1].slice(-3) !== '...'
|
||||||
this.lines.push(wrappedLines[i]);
|
) {
|
||||||
}
|
this.lines[this.lines.length - 1] += wrappedLines[i]
|
||||||
i++;
|
} else {
|
||||||
}
|
this.lines.push(wrappedLines[i])
|
||||||
this.row = 0;
|
}
|
||||||
};
|
i++
|
||||||
|
}
|
||||||
|
this.row = 0
|
||||||
|
}
|
||||||
|
|
||||||
(function() {
|
;(function () {
|
||||||
this.nextLine = function() {
|
this.nextLine = function () {
|
||||||
this.row++;
|
this.row++
|
||||||
if (this.row >= this.lines.length) {
|
if (this.row >= this.lines.length) {
|
||||||
return false;
|
return false
|
||||||
} else {
|
} else {
|
||||||
return this.lines[this.row];
|
return this.lines[this.row]
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
this.rewindLine = function() {
|
this.rewindLine = function () {
|
||||||
this.row--;
|
this.row--
|
||||||
};
|
}
|
||||||
|
|
||||||
this.linesUpToNextWhitespaceLine = function() {
|
this.linesUpToNextWhitespaceLine = function () {
|
||||||
return this.linesUpToNextMatchingLine(/^ *$/);
|
return this.linesUpToNextMatchingLine(/^ *$/)
|
||||||
};
|
}
|
||||||
|
|
||||||
this.linesUpToNextMatchingLine = function(match) {
|
this.linesUpToNextMatchingLine = function (match) {
|
||||||
const lines = [];
|
const lines = []
|
||||||
let nextLine = this.nextLine();
|
let nextLine = this.nextLine()
|
||||||
if (nextLine !== false) {
|
if (nextLine !== false) {
|
||||||
lines.push(nextLine);
|
lines.push(nextLine)
|
||||||
}
|
}
|
||||||
while ((nextLine !== false) && !nextLine.match(match) && (nextLine !== false)) {
|
while (
|
||||||
nextLine = this.nextLine();
|
nextLine !== false &&
|
||||||
if (nextLine !== false) {
|
!nextLine.match(match) &&
|
||||||
lines.push(nextLine);
|
nextLine !== false
|
||||||
}
|
) {
|
||||||
}
|
nextLine = this.nextLine()
|
||||||
return lines;
|
if (nextLine !== false) {
|
||||||
};
|
lines.push(nextLine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
}.call(LogText.prototype))
|
||||||
|
|
||||||
}).call(LogText.prototype);
|
const state = {
|
||||||
|
NORMAL: 0,
|
||||||
|
ERROR: 1,
|
||||||
|
}
|
||||||
|
|
||||||
const state = {
|
const LatexParser = function (text, options) {
|
||||||
NORMAL: 0,
|
this.log = new LogText(text)
|
||||||
ERROR: 1
|
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) {
|
;(function () {
|
||||||
this.log = new LogText(text);
|
this.parse = function () {
|
||||||
this.state = state.NORMAL;
|
while ((this.currentLine = this.log.nextLine()) !== false) {
|
||||||
options = options || {};
|
if (this.state === state.NORMAL) {
|
||||||
this.fileBaseNames = options.fileBaseNames || [
|
if (this.currentLineIsError()) {
|
||||||
/compiles/,
|
this.state = state.ERROR
|
||||||
/\/usr\/local/
|
this.currentError = {
|
||||||
];
|
line: null,
|
||||||
this.ignoreDuplicates = options.ignoreDuplicates;
|
file: this.currentFilePath,
|
||||||
this.data = [];
|
level: 'error',
|
||||||
this.fileStack = [];
|
message: this.currentLine.slice(2),
|
||||||
this.currentFileList = (this.rootFileList = []);
|
content: '',
|
||||||
this.openParens = 0;
|
raw: this.currentLine + '\n',
|
||||||
};
|
}
|
||||||
|
} else if (this.currentLineIsRunawayArgument()) {
|
||||||
|
this.parseRunawayArgumentError()
|
||||||
|
} else if (this.currentLineIsWarning()) {
|
||||||
|
this.parseSingleWarningLine(LATEX_WARNING_REGEX)
|
||||||
|
} else if (this.currentLineIsHboxWarning()) {
|
||||||
|
this.parseHboxLine()
|
||||||
|
} else if (this.currentLineIsPackageWarning()) {
|
||||||
|
this.parseMultipleWarningLine()
|
||||||
|
} else {
|
||||||
|
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]+)/)
|
||||||
|
if (lineNo) {
|
||||||
|
this.currentError.line = parseInt(lineNo[1], 10)
|
||||||
|
}
|
||||||
|
this.data.push(this.currentError)
|
||||||
|
this.state = state.NORMAL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.postProcess(this.data)
|
||||||
|
}
|
||||||
|
|
||||||
(function() {
|
this.currentLineIsError = function () {
|
||||||
this.parse = function() {
|
return this.currentLine[0] === '!'
|
||||||
while ((this.currentLine = this.log.nextLine()) !== false) {
|
}
|
||||||
if (this.state === state.NORMAL) {
|
|
||||||
if (this.currentLineIsError()) {
|
|
||||||
this.state = state.ERROR;
|
|
||||||
this.currentError = {
|
|
||||||
line: null,
|
|
||||||
file: this.currentFilePath,
|
|
||||||
level: 'error',
|
|
||||||
message: this.currentLine.slice(2),
|
|
||||||
content: '',
|
|
||||||
raw: this.currentLine + '\n'
|
|
||||||
};
|
|
||||||
} else if (this.currentLineIsRunawayArgument()) {
|
|
||||||
this.parseRunawayArgumentError();
|
|
||||||
} else if (this.currentLineIsWarning()) {
|
|
||||||
this.parseSingleWarningLine(LATEX_WARNING_REGEX);
|
|
||||||
} else if (this.currentLineIsHboxWarning()) {
|
|
||||||
this.parseHboxLine();
|
|
||||||
} else if (this.currentLineIsPackageWarning()) {
|
|
||||||
this.parseMultipleWarningLine();
|
|
||||||
} else {
|
|
||||||
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]+)/);
|
|
||||||
if (lineNo) {
|
|
||||||
this.currentError.line = parseInt(lineNo[1], 10);
|
|
||||||
}
|
|
||||||
this.data.push(this.currentError);
|
|
||||||
this.state = state.NORMAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this.postProcess(this.data);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.currentLineIsError = function() {
|
this.currentLineIsRunawayArgument = function () {
|
||||||
return this.currentLine[0] === '!';
|
return this.currentLine.match(/^Runaway argument/)
|
||||||
};
|
}
|
||||||
|
|
||||||
this.currentLineIsRunawayArgument = function() {
|
this.currentLineIsWarning = function () {
|
||||||
return this.currentLine.match(/^Runaway argument/);
|
return !!this.currentLine.match(LATEX_WARNING_REGEX)
|
||||||
};
|
}
|
||||||
|
|
||||||
this.currentLineIsWarning = function() {
|
this.currentLineIsPackageWarning = function () {
|
||||||
return !!this.currentLine.match(LATEX_WARNING_REGEX);
|
return !!this.currentLine.match(PACKAGE_WARNING_REGEX)
|
||||||
};
|
}
|
||||||
|
|
||||||
this.currentLineIsPackageWarning = function() {
|
this.currentLineIsHboxWarning = function () {
|
||||||
return !!this.currentLine.match(PACKAGE_WARNING_REGEX);
|
return !!this.currentLine.match(HBOX_WARNING_REGEX)
|
||||||
};
|
}
|
||||||
|
|
||||||
this.currentLineIsHboxWarning = function() {
|
this.parseRunawayArgumentError = function () {
|
||||||
return !!this.currentLine.match(HBOX_WARNING_REGEX);
|
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]+)/)
|
||||||
|
if (lineNo) {
|
||||||
|
this.currentError.line = parseInt(lineNo[1], 10)
|
||||||
|
}
|
||||||
|
return this.data.push(this.currentError)
|
||||||
|
}
|
||||||
|
|
||||||
this.parseRunawayArgumentError = function() {
|
this.parseSingleWarningLine = function (prefix_regex) {
|
||||||
this.currentError = {
|
const warningMatch = this.currentLine.match(prefix_regex)
|
||||||
line: null,
|
if (!warningMatch) {
|
||||||
file: this.currentFilePath,
|
return
|
||||||
level: 'error',
|
}
|
||||||
message: this.currentLine,
|
const warning = warningMatch[1]
|
||||||
content: '',
|
const lineMatch = warning.match(LINES_REGEX)
|
||||||
raw: this.currentLine + '\n'
|
const line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||||
};
|
this.data.push({
|
||||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
line,
|
||||||
this.currentError.content += '\n';
|
file: this.currentFilePath,
|
||||||
this.currentError.content += this.log.linesUpToNextWhitespaceLine().join('\n');
|
level: 'warning',
|
||||||
this.currentError.raw += this.currentError.content;
|
message: warning,
|
||||||
const lineNo = this.currentError.raw.match(/l\.([0-9]+)/);
|
raw: warning,
|
||||||
if (lineNo) {
|
})
|
||||||
this.currentError.line = parseInt(lineNo[1], 10);
|
}
|
||||||
}
|
|
||||||
return this.data.push(this.currentError);
|
|
||||||
};
|
|
||||||
|
|
||||||
this.parseSingleWarningLine = function(prefix_regex) {
|
this.parseMultipleWarningLine = function () {
|
||||||
const warningMatch = this.currentLine.match(prefix_regex);
|
// Some package warnings are multiple lines, let's parse the first line
|
||||||
if (!warningMatch) {
|
let warningMatch = this.currentLine.match(PACKAGE_WARNING_REGEX)
|
||||||
return;
|
if (!warningMatch) {
|
||||||
}
|
return
|
||||||
const warning = warningMatch[1];
|
}
|
||||||
const lineMatch = warning.match(LINES_REGEX);
|
// Something strange happened, return early
|
||||||
const line = lineMatch ? parseInt(lineMatch[1], 10) : null;
|
const warning_lines = [warningMatch[1]]
|
||||||
this.data.push({
|
let lineMatch = this.currentLine.match(LINES_REGEX)
|
||||||
line,
|
let line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||||
file: this.currentFilePath,
|
const packageMatch = this.currentLine.match(PACKAGE_REGEX)
|
||||||
level: 'warning',
|
const packageName = packageMatch[1]
|
||||||
message: warning,
|
// Regex to get rid of the unnecesary (packagename) prefix in most multi-line warnings
|
||||||
raw: warning
|
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])
|
||||||
|
}
|
||||||
|
const raw_message = warning_lines.join(' ')
|
||||||
|
this.data.push({
|
||||||
|
line,
|
||||||
|
file: this.currentFilePath,
|
||||||
|
level: 'warning',
|
||||||
|
message: raw_message,
|
||||||
|
raw: raw_message,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.parseMultipleWarningLine = function() {
|
this.parseHboxLine = function () {
|
||||||
// Some package warnings are multiple lines, let's parse the first line
|
const lineMatch = this.currentLine.match(LINES_REGEX)
|
||||||
let warningMatch = this.currentLine.match(PACKAGE_WARNING_REGEX);
|
const line = lineMatch ? parseInt(lineMatch[1], 10) : null
|
||||||
if (!warningMatch) {
|
this.data.push({
|
||||||
return;
|
line,
|
||||||
}
|
file: this.currentFilePath,
|
||||||
// Something strange happened, return early
|
level: 'typesetting',
|
||||||
const warning_lines = [ warningMatch[1] ];
|
message: this.currentLine,
|
||||||
let lineMatch = this.currentLine.match(LINES_REGEX);
|
raw: this.currentLine,
|
||||||
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');
|
|
||||||
// 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]);
|
|
||||||
}
|
|
||||||
const raw_message = warning_lines.join(' ');
|
|
||||||
this.data.push({
|
|
||||||
line,
|
|
||||||
file: this.currentFilePath,
|
|
||||||
level: 'warning',
|
|
||||||
message: raw_message,
|
|
||||||
raw: raw_message
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
this.parseHboxLine = function() {
|
// Check if we're entering or leaving a new file in this line
|
||||||
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
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check if we're entering or leaving a new file in this line
|
this.parseParensForFilenames = function () {
|
||||||
|
const pos = this.currentLine.search(/\(|\)/)
|
||||||
|
if (pos !== -1) {
|
||||||
|
const token = this.currentLine[pos]
|
||||||
|
this.currentLine = this.currentLine.slice(pos + 1)
|
||||||
|
if (token === '(') {
|
||||||
|
const filePath = this.consumeFilePath()
|
||||||
|
if (filePath) {
|
||||||
|
this.currentFilePath = filePath
|
||||||
|
const newFile = {
|
||||||
|
path: filePath,
|
||||||
|
files: [],
|
||||||
|
}
|
||||||
|
this.fileStack.push(newFile)
|
||||||
|
this.currentFileList.push(newFile)
|
||||||
|
this.currentFileList = newFile.files
|
||||||
|
} else {
|
||||||
|
this.openParens++
|
||||||
|
}
|
||||||
|
} else if (token === ')') {
|
||||||
|
if (this.openParens > 0) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// else {
|
||||||
|
// Something has gone wrong but all we can do now is ignore it :(
|
||||||
|
// }
|
||||||
|
// Process the rest of the line
|
||||||
|
this.parseParensForFilenames()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.parseParensForFilenames = function() {
|
this.consumeFilePath = function () {
|
||||||
const pos = this.currentLine.search(/\(|\)/);
|
// Our heuristic for detecting file names are rather crude
|
||||||
if (pos !== -1) {
|
// A file may not contain a space, or ) in it
|
||||||
const token = this.currentLine[pos];
|
// To be a file path it must have at least one /
|
||||||
this.currentLine = this.currentLine.slice(pos + 1);
|
if (!this.currentLine.match(/^\/?([^ \)]+\/)+/)) {
|
||||||
if (token === '(') {
|
return false
|
||||||
const filePath = this.consumeFilePath();
|
}
|
||||||
if (filePath) {
|
const endOfFilePath = this.currentLine.search(RegExp(' |\\)'))
|
||||||
this.currentFilePath = filePath;
|
let path = undefined
|
||||||
const newFile = {
|
if (endOfFilePath === -1) {
|
||||||
path: filePath,
|
path = this.currentLine
|
||||||
files: []
|
this.currentLine = ''
|
||||||
};
|
} else {
|
||||||
this.fileStack.push(newFile);
|
path = this.currentLine.slice(0, endOfFilePath)
|
||||||
this.currentFileList.push(newFile);
|
this.currentLine = this.currentLine.slice(endOfFilePath)
|
||||||
this.currentFileList = newFile.files;
|
}
|
||||||
} else {
|
return path
|
||||||
this.openParens++;
|
}
|
||||||
}
|
|
||||||
} else if (token === ')') {
|
|
||||||
if (this.openParens > 0) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// else {
|
|
||||||
// Something has gone wrong but all we can do now is ignore it :(
|
|
||||||
// }
|
|
||||||
// Process the rest of the line
|
|
||||||
this.parseParensForFilenames();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.consumeFilePath = function() {
|
this.postProcess = function (data) {
|
||||||
// Our heuristic for detecting file names are rather crude
|
const all = []
|
||||||
// A file may not contain a space, or ) in it
|
const errors = []
|
||||||
// To be a file path it must have at least one /
|
const warnings = []
|
||||||
if (!this.currentLine.match(/^\/?([^ \)]+\/)+/)) {
|
const typesetting = []
|
||||||
return false;
|
const hashes = []
|
||||||
}
|
|
||||||
const endOfFilePath = this.currentLine.search(RegExp(' |\\)'));
|
|
||||||
let path = undefined;
|
|
||||||
if (endOfFilePath === -1) {
|
|
||||||
path = this.currentLine;
|
|
||||||
this.currentLine = '';
|
|
||||||
} else {
|
|
||||||
path = this.currentLine.slice(0, endOfFilePath);
|
|
||||||
this.currentLine = this.currentLine.slice(endOfFilePath);
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.postProcess = function(data) {
|
const hashEntry = entry => entry.raw
|
||||||
const all = [];
|
|
||||||
const errors = [];
|
|
||||||
const warnings = [];
|
|
||||||
const typesetting = [];
|
|
||||||
const hashes = [];
|
|
||||||
|
|
||||||
const hashEntry = entry => entry.raw;
|
let i = 0
|
||||||
|
while (i < data.length) {
|
||||||
|
if (this.ignoreDuplicates && hashes.indexOf(hashEntry(data[i])) > -1) {
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (data[i].level === 'error') {
|
||||||
|
errors.push(data[i])
|
||||||
|
} else if (data[i].level === 'typesetting') {
|
||||||
|
typesetting.push(data[i])
|
||||||
|
} else if (data[i].level === 'warning') {
|
||||||
|
warnings.push(data[i])
|
||||||
|
}
|
||||||
|
all.push(data[i])
|
||||||
|
hashes.push(hashEntry(data[i]))
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
errors,
|
||||||
|
warnings,
|
||||||
|
typesetting,
|
||||||
|
all,
|
||||||
|
files: this.rootFileList,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.call(LatexParser.prototype))
|
||||||
|
|
||||||
let i = 0;
|
LatexParser.parse = (text, options) => new LatexParser(text, options).parse()
|
||||||
while (i < data.length) {
|
|
||||||
if (this.ignoreDuplicates && (hashes.indexOf(hashEntry(data[i])) > -1)) {
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (data[i].level === 'error') {
|
|
||||||
errors.push(data[i]);
|
|
||||||
} else if (data[i].level === 'typesetting') {
|
|
||||||
typesetting.push(data[i]);
|
|
||||||
} else if (data[i].level === 'warning') {
|
|
||||||
warnings.push(data[i]);
|
|
||||||
}
|
|
||||||
all.push(data[i]);
|
|
||||||
hashes.push(hashEntry(data[i]));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
errors,
|
|
||||||
warnings,
|
|
||||||
typesetting,
|
|
||||||
all,
|
|
||||||
files: this.rootFileList
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(LatexParser.prototype);
|
return LatexParser
|
||||||
|
})
|
||||||
LatexParser.parse = (text, options) => new LatexParser(text, options).parse();
|
|
||||||
|
|
||||||
return LatexParser;
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue