/// <summary> /// Parses a compiler error or warning message into a more structured format. /// </summary> /// <param name="messageText">Text of the error or warning message.</param> /// <param name="message">Parsed structured version of the message.</param> /// <returns>True if the parsing was completed successfully, false otherwise.</returns> private bool TryParseCompilerMessage(string messageText, out CompilerMessage message) { message = new CompilerMessage(); Match matchCompile = compileErrorRegex.Match(messageText); if (matchCompile.Success) { message.file = matchCompile.Groups["file"].Value; message.line = Int32.Parse(matchCompile.Groups["line"].Value); message.column = Int32.Parse(matchCompile.Groups["column"].Value); message.type = matchCompile.Groups["type"].Value == "error" ? CompilerMessageType.Error : CompilerMessageType.Warning; message.message = matchCompile.Groups["message"].Value; return(true); } Match matchCompiler = compilerErrorRegex.Match(messageText); if (matchCompiler.Success) { message.file = ""; message.line = 0; message.column = 0; message.type = CompilerMessageType.Error; message.message = matchCompiler.Groups["message"].Value; return(true); } return(false); }
/// <summary> /// Converts data reported by the compiler into a readable string. /// </summary> /// <param name="msg">Message data as reported by the compiler.</param> /// <returns>Readable message string.</returns> private string FormMessage(CompilerMessage msg) { StringBuilder sb = new StringBuilder(); if (msg.type == CompilerMessageType.Error) { sb.AppendLine("Compiler error: " + msg.message); } else { sb.AppendLine("Compiler warning: " + msg.message); } sb.AppendLine("\tin " + msg.file + "[" + msg.line + ":" + msg.column + "]"); return(sb.ToString()); }