[System] Fix the CSharpCodeCompiler error parsing regex.
[mono.git] / mcs / class / System / Microsoft.CSharp / CSharpCodeCompiler.cs
index 26039bdd79b3de87fccd138b2345b4f809967f16..62b41de358d512f71d3fdaaa3985845ae2beb990 100644 (file)
@@ -395,6 +395,20 @@ namespace Mono.CSharp
                                args.AppendFormat("\"{0}\" ",source);
                        return args.ToString();
                }
+
+               // Keep in sync with mcs/class/Microsoft.Build.Utilities/Microsoft.Build.Utilities/ToolTask.cs
+               const string ErrorRegexPattern = @"
+                       ^
+                       (\s*(?<file>[^\(]+)                         # filename (optional)
+                        (\((?<line>\d*)(,(?<column>\d*[\+]*))?\))? # line+column (optional)
+                        :\s+)?
+                       (?<level>\w+)                               # error|warning
+                       \s+
+                       (?<number>[^:]*\d)                          # CS1234
+                       :
+                       \s*
+                       (?<message>.*)$";
+
                private static CompilerError CreateErrorFromString(string error_string)
                {
                        if (error_string.StartsWith ("BETA"))
@@ -404,8 +418,7 @@ namespace Mono.CSharp
                                return null;
 
                        CompilerError error=new CompilerError();
-                       Regex reg = new Regex (@"^(\s*(?<file>.*)\((?<line>\d*)(,(?<column>\d*))?\)(:)?\s+)*(?<level>\w+)\s*(?<number>.*):\s(?<message>.*)",
-                               RegexOptions.Compiled | RegexOptions.ExplicitCapture);
+                       Regex reg = new Regex (ErrorRegexPattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
                        Match match=reg.Match(error_string);
                        if (!match.Success) {
                                // We had some sort of runtime crash