biber-log-parser.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Generated by CoffeeScript 1.10.0
  2. define(function() {
  3. var BiberLogParser, LINE_SPLITTER_REGEX, MESSAGE_LEVELS;
  4. LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/;
  5. MESSAGE_LEVELS = {
  6. "INFO": "info",
  7. "WARN": "warning",
  8. "ERROR": "error"
  9. };
  10. BiberLogParser = function(text, options) {
  11. if (typeof text !== 'string') {
  12. throw new Error("BiberLogParser Error: text parameter must be a string");
  13. }
  14. this.text = text.replace(/(\r\n)|\r/g, '\n');
  15. this.options = options || {};
  16. this.lines = text.split('\n');
  17. };
  18. (function() {
  19. return this.parse = function() {
  20. var result;
  21. result = {
  22. all: [],
  23. errors: [],
  24. warnings: [],
  25. files: [],
  26. typesetting: []
  27. };
  28. this.lines.forEach(function(line) {
  29. var _, fileName, fullLine, lineMatch, lineNumber, match, message, messageType, newEntry, realMessage;
  30. match = line.match(LINE_SPLITTER_REGEX);
  31. if (match) {
  32. fullLine = match[0], lineNumber = match[1], messageType = match[2], message = match[3];
  33. newEntry = {
  34. file: null,
  35. level: MESSAGE_LEVELS[messageType] || "INFO",
  36. message: message,
  37. line: null,
  38. raw: fullLine
  39. };
  40. lineMatch = newEntry.message.match(/^BibTeX subsystem: \/.+\/(\w+\.\w+)_.+, line (\d+), (.+)$/);
  41. if (lineMatch && lineMatch.length === 4) {
  42. _ = lineMatch[0], fileName = lineMatch[1], lineNumber = lineMatch[2], realMessage = lineMatch[3];
  43. newEntry.file = fileName;
  44. newEntry.line = lineNumber;
  45. newEntry.message = realMessage;
  46. }
  47. result.all.push(newEntry);
  48. switch (newEntry.level) {
  49. case 'error':
  50. return result.errors.push(newEntry);
  51. case 'warning':
  52. return result.warnings.push(newEntry);
  53. }
  54. }
  55. });
  56. return result;
  57. };
  58. }).call(BiberLogParser.prototype);
  59. BiberLogParser.parse = function(text, options) {
  60. return new BiberLogParser(text, options).parse();
  61. };
  62. return BiberLogParser;
  63. });