mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
63 lines
2.1 KiB
JavaScript
63 lines
2.1 KiB
JavaScript
// Generated by CoffeeScript 1.10.0
|
|
define(function() {
|
|
var BibLogParser, LINE_SPLITTER_REGEX, MESSAGE_LEVELS;
|
|
LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/;
|
|
MESSAGE_LEVELS = {
|
|
"INFO": "info",
|
|
"WARN": "warning",
|
|
"ERROR": "error"
|
|
};
|
|
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');
|
|
};
|
|
(function() {
|
|
return this.parse = function() {
|
|
var result;
|
|
result = {
|
|
all: [],
|
|
errors: [],
|
|
warnings: [],
|
|
files: [],
|
|
typesetting: []
|
|
};
|
|
this.lines.forEach(function(line) {
|
|
var _, fileName, fullLine, lineMatch, lineNumber, match, message, messageType, newEntry, realMessage;
|
|
match = line.match(LINE_SPLITTER_REGEX);
|
|
if (match) {
|
|
fullLine = match[0], lineNumber = match[1], messageType = match[2], message = match[3];
|
|
newEntry = {
|
|
file: null,
|
|
level: MESSAGE_LEVELS[messageType] || "INFO",
|
|
message: message,
|
|
line: null,
|
|
raw: fullLine
|
|
};
|
|
lineMatch = newEntry.message.match(/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/);
|
|
if (lineMatch && lineMatch.length === 4) {
|
|
_ = lineMatch[0], fileName = lineMatch[1], lineNumber = lineMatch[2], realMessage = lineMatch[3];
|
|
newEntry.file = fileName;
|
|
newEntry.line = lineNumber;
|
|
newEntry.message = realMessage;
|
|
}
|
|
result.all.push(newEntry);
|
|
switch (newEntry.level) {
|
|
case 'error':
|
|
return result.errors.push(newEntry);
|
|
case 'warning':
|
|
return result.warnings.push(newEntry);
|
|
}
|
|
}
|
|
});
|
|
return result;
|
|
};
|
|
}).call(BibLogParser.prototype);
|
|
BibLogParser.parse = function(text, options) {
|
|
return new BibLogParser(text, options).parse();
|
|
};
|
|
return BibLogParser;
|
|
});
|