|
|
@@ -18,32 +18,21 @@ const MESSAGE_LEVELS = {
|
|
|
ERROR: 'error',
|
|
|
}
|
|
|
|
|
|
-const parserReducer = function (maxErrors, buildMaxErrorsReachedMessage) {
|
|
|
+const parserReducer = function (maxErrors) {
|
|
|
return function (accumulator, parser) {
|
|
|
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
|
|
|
+
|
|
|
+ while ((match = regex.exec(text))) {
|
|
|
+ iterationCount++
|
|
|
const newEntry = process(match)
|
|
|
|
|
|
// Too many log entries can cause browser crashes
|
|
|
// Construct a too many files error from the last match
|
|
|
if (maxErrors != null && iterationCount >= maxErrors) {
|
|
|
- if (buildMaxErrorsReachedMessage) {
|
|
|
- const level = newEntry.level + 's'
|
|
|
- newEntry.message = [
|
|
|
- 'Over',
|
|
|
- maxErrors,
|
|
|
- level,
|
|
|
- 'returned. Download raw logs to see full list',
|
|
|
- ].join(' ')
|
|
|
- newEntry.line = undefined
|
|
|
- result.unshift(newEntry)
|
|
|
- }
|
|
|
return [result, '']
|
|
|
}
|
|
|
|
|
|
@@ -55,6 +44,7 @@ const parserReducer = function (maxErrors, buildMaxErrorsReachedMessage) {
|
|
|
match.input.length
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
return [result, text]
|
|
|
}
|
|
|
|
|
|
@@ -66,12 +56,12 @@ const parserReducer = function (maxErrors, buildMaxErrorsReachedMessage) {
|
|
|
}
|
|
|
|
|
|
export default class BibLogParser {
|
|
|
- constructor(text, options) {
|
|
|
+ constructor(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.options = options
|
|
|
this.lines = text.split('\n')
|
|
|
|
|
|
// each parser is a pair of [regex, processFunction], where processFunction
|
|
|
@@ -163,33 +153,23 @@ export default class BibLogParser {
|
|
|
}
|
|
|
|
|
|
parseBibtex() {
|
|
|
- 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] = this.warningParsers.reduce(
|
|
|
- parserReducer(
|
|
|
- this.options.maxErrors,
|
|
|
- this.options.buildMaxErrorsReachedMessage
|
|
|
- ),
|
|
|
+ const [allWarnings, remainingText] = this.warningParsers.reduce(
|
|
|
+ parserReducer(this.options.maxErrors),
|
|
|
[[], this.text]
|
|
|
)
|
|
|
- ;[allErrors, remainingText] = this.errorParsers.reduce(
|
|
|
- parserReducer(
|
|
|
- this.options.maxErrors,
|
|
|
- this.options.buildMaxErrorsReachedMessage
|
|
|
- ),
|
|
|
+ const [allErrors] = this.errorParsers.reduce(
|
|
|
+ parserReducer(this.options.maxErrors),
|
|
|
[[], remainingText]
|
|
|
)
|
|
|
- result.warnings = allWarnings
|
|
|
- result.errors = allErrors
|
|
|
- result.all = allWarnings.concat(allErrors)
|
|
|
- return result
|
|
|
+
|
|
|
+ return {
|
|
|
+ all: allWarnings.concat(allErrors),
|
|
|
+ errors: allErrors,
|
|
|
+ warnings: allWarnings,
|
|
|
+ files: [], // not used
|
|
|
+ typesetting: [], // not used
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
parseBiber() {
|
|
|
@@ -203,9 +183,7 @@ export default class BibLogParser {
|
|
|
this.lines.forEach(function (line) {
|
|
|
const match = line.match(LINE_SPLITTER_REGEX)
|
|
|
if (match) {
|
|
|
- const fullLine = match[0]
|
|
|
- const messageType = match[2]
|
|
|
- const message = match[3]
|
|
|
+ const [fullLine, , messageType, message] = match
|
|
|
const newEntry = {
|
|
|
file: '',
|
|
|
level: MESSAGE_LEVELS[messageType] || 'INFO',
|
|
|
@@ -218,10 +196,8 @@ export default class BibLogParser {
|
|
|
const lineMatch = newEntry.message.match(
|
|
|
/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/
|
|
|
)
|
|
|
- if (lineMatch && lineMatch.length === 4) {
|
|
|
- const fileName = lineMatch[1]
|
|
|
- const lineNumber = lineMatch[2]
|
|
|
- const realMessage = lineMatch[3]
|
|
|
+ if (lineMatch) {
|
|
|
+ const [, fileName, lineNumber, realMessage] = lineMatch
|
|
|
newEntry.file = fileName
|
|
|
newEntry.line = lineNumber
|
|
|
newEntry.message = realMessage
|