Source code for Ludum Dare 48: Deeper and Deeper entry.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. using System.Text.RegularExpressions;
  2. using Debug = UnityEngine.Debug;
  3. namespace Ink.UnityIntegration
  4. {
  5. [System.Serializable]
  6. public class InkCompilerLog {
  7. public Ink.ErrorType type;
  8. public string content;
  9. public string fileName;
  10. public int lineNumber;
  11. public InkCompilerLog (Ink.ErrorType type, string content, string fileName, int lineNumber = -1) {
  12. this.type = type;
  13. this.content = content;
  14. this.fileName = fileName;
  15. this.lineNumber = lineNumber;
  16. }
  17. public static bool TryParse (string rawLog, out InkCompilerLog log) {
  18. var match = _errorRegex.Match(rawLog);
  19. if (match.Success) {
  20. Ink.ErrorType errorType = Ink.ErrorType.Author;
  21. string filename = null;
  22. int lineNo = -1;
  23. string message = null;
  24. var errorTypeCapture = match.Groups["errorType"];
  25. if( errorTypeCapture != null ) {
  26. var errorTypeStr = errorTypeCapture.Value;
  27. if(errorTypeStr == "AUTHOR" || errorTypeStr == "TODO") errorType = Ink.ErrorType.Author;
  28. else if(errorTypeStr == "WARNING") errorType = Ink.ErrorType.Warning;
  29. else if(errorTypeStr == "ERROR") errorType = Ink.ErrorType.Error;
  30. else Debug.LogWarning("Could not parse error type from "+errorTypeStr);
  31. }
  32. var filenameCapture = match.Groups["filename"];
  33. if (filenameCapture != null)
  34. filename = filenameCapture.Value;
  35. var lineNoCapture = match.Groups["lineNo"];
  36. if (lineNoCapture != null)
  37. lineNo = int.Parse (lineNoCapture.Value);
  38. var messageCapture = match.Groups["message"];
  39. if (messageCapture != null)
  40. message = messageCapture.Value.Trim();
  41. log = new InkCompilerLog(errorType, message, filename, lineNo);
  42. return true;
  43. } else {
  44. Debug.LogWarning("Could not parse InkFileLog from log: "+rawLog);
  45. log = null;
  46. return false;
  47. }
  48. }
  49. private static Regex _errorRegex = new Regex(@"(?<errorType>ERROR|WARNING|TODO):(?:\s(?:'(?<filename>[^']*)'\s)?line (?<lineNo>\d+):)?(?<message>.*)");
  50. }
  51. }