From b36728df104520611cd99a2af6d110535525e6ab Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 26 Feb 2013 14:30:11 -0600 Subject: [PATCH] Update build message processing for the ANTLR 4 message formatting --- .../Antlr4ClassGenerationTask.cs | 2 +- .../CSharp/Antlr4BuildTasks/BuildMessage.cs | 52 ++++++++++++------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs index 8d289b3d5..eeb5bf5d4 100644 --- a/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs +++ b/runtime/CSharp/Antlr4BuildTasks/Antlr4ClassGenerationTask.cs @@ -304,7 +304,7 @@ namespace Antlr4.Build.Tasks return wrapper; } - private static bool IsFatalException(Exception exception) + internal static bool IsFatalException(Exception exception) { while (exception != null) { diff --git a/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs b/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs index 75a9ea4d2..fb0f876b5 100644 --- a/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs +++ b/runtime/CSharp/Antlr4BuildTasks/BuildMessage.cs @@ -35,33 +35,45 @@ namespace Antlr4.Build.Tasks [Serializable] internal struct BuildMessage { - private static readonly Regex BuildMessageFormat = new Regex(@"^\s*(?.*)\((?[0-9]+),(?[0-9]+)\) : (?[a-z]+)\s*(?[0-9]+) : (?.*)$", RegexOptions.Compiled); + private static readonly Regex BuildMessageFormat = new Regex(@"^\s*(?[a-z]+)\((?[0-9]+)\):\s*((?.*):(?[0-9]+):(?[0-9]+):)?\s*(?:syntax error:\s*)?(?.*)$", RegexOptions.Compiled); public BuildMessage(string message) : this(TraceLevel.Error, message, null, 0, 0) { - Match match = BuildMessageFormat.Match(message); - if (match.Success) + try { - FileName = match.Groups["FILE"].Value; - LineNumber = int.Parse(match.Groups["LINE"].Value); - ColumnNumber = int.Parse(match.Groups["COLUMN"].Value); - - switch (match.Groups["SEVERITY"].Value) + Match match = BuildMessageFormat.Match(message); + if (match.Success) { - case "warning": - Severity = TraceLevel.Warning; - break; - case "error": - Severity = TraceLevel.Error; - break; - default: - Severity = TraceLevel.Info; - break; - } + FileName = match.Groups["FILE"].Length > 0 ? match.Groups["FILE"].Value : ""; + LineNumber = match.Groups["LINE"].Length > 0 ? int.Parse(match.Groups["LINE"].Value) : 0; + ColumnNumber = match.Groups["COLUMN"].Length > 0 ? int.Parse(match.Groups["COLUMN"].Value) + 1 : 0; - int code = int.Parse(match.Groups["CODE"].Value); - Message = string.Format("AC{0:0000}: {1}", code, match.Groups["MESSAGE"].Value); + switch (match.Groups["SEVERITY"].Value) + { + case "warning": + Severity = TraceLevel.Warning; + break; + case "error": + Severity = TraceLevel.Error; + break; + default: + Severity = TraceLevel.Info; + break; + } + + int code = int.Parse(match.Groups["CODE"].Value); + Message = string.Format("AC{0:0000}: {1}", code, match.Groups["MESSAGE"].Value); + } + else + { + Message = message; + } + } + catch (Exception ex) + { + if (Antlr4ClassGenerationTask.IsFatalException(ex)) + throw; } }