StringBuilder toolOutput;
bool typeLoadException;
- static Regex regex;
-
protected ToolTask ()
: this (null, null)
{
this.environmentOverride = new SCS.ProcessStringDictionary ();
}
- static ToolTask ()
- {
- regex = new Regex (
- @"^\s*"
- + @"(((?<ORIGIN>(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)"
- + "|())"
- + "(?<SUBCATEGORY>(()|([^:]*? )))"
- + "(?<CATEGORY>(error|warning)) "
- + "(?<CODE>[^:]*):"
- + "(?<TEXT>.*)$",
- RegexOptions.IgnoreCase);
- }
-
[MonoTODO]
protected virtual bool CallHostObjectToExecute ()
{
singleLine.StartsWith ("Compilation failed"))
return;
- string filename, origin, category, code, subcategory, text;
- int lineNumber, columnNumber, endLineNumber, endColumnNumber;
-
- Match m = regex.Match (singleLine);
- origin = m.Groups [regex.GroupNumberFromName ("ORIGIN")].Value;
- category = m.Groups [regex.GroupNumberFromName ("CATEGORY")].Value;
- code = m.Groups [regex.GroupNumberFromName ("CODE")].Value;
- subcategory = m.Groups [regex.GroupNumberFromName ("SUBCATEGORY")].Value;
- text = m.Groups [regex.GroupNumberFromName ("TEXT")].Value;
-
- ParseOrigin (origin, out filename, out lineNumber, out columnNumber, out endLineNumber, out endColumnNumber);
-
- if (category == "warning") {
- Log.LogWarning (subcategory, code, null, filename, lineNumber, columnNumber, endLineNumber,
- endColumnNumber, text, null);
- } else if (category == "error") {
- Log.LogError (subcategory, code, null, filename, lineNumber, columnNumber, endLineNumber,
- endColumnNumber, text, null);
+ Match match = CscErrorRegex.Match (singleLine);
+ if (!match.Success)
+ return;
+
+ string filename = match.Result ("${file}") ?? "";
+ string line = match.Result ("${line}");
+ int lineNumber = !string.IsNullOrEmpty (line) ? Int32.Parse (line) : 0;
+
+ string col = match.Result ("${column}");
+ int columnNumber = 0;
+ if (!string.IsNullOrEmpty (col))
+ columnNumber = col == "255+" ? -1 : Int32.Parse (col);
+
+ string category = match.Result ("${level}");
+ string code = match.Result ("${number}");
+ string text = match.Result ("${message}");
+
+ if (String.Compare (category, "warning", StringComparison.OrdinalIgnoreCase) == 0) {
+ Log.LogWarning (null, code, null, filename, lineNumber, columnNumber, -1,
+ -1, text, null);
+ } else if (String.Compare (category, "error", StringComparison.OrdinalIgnoreCase) == 0) {
+ Log.LogError (null, code, null, filename, lineNumber, columnNumber, -1,
+ -1, text, null);
} else {
Log.LogMessage (importance, singleLine);
}
}
-
- private void ParseOrigin (string origin, out string filename,
- out int lineNumber, out int columnNumber,
- out int endLineNumber, out int endColumnNumber)
- {
- int lParen;
- string[] temp;
- string[] left, right;
-
- if (origin.IndexOf ('(') != -1 ) {
- lParen = origin.IndexOf ('(');
- filename = origin.Substring (0, lParen);
- temp = origin.Substring (lParen + 1, origin.Length - lParen - 2).Split (',');
- if (temp.Length == 1) {
- left = temp [0].Split ('-');
- if (left.Length == 1) {
- lineNumber = Int32.Parse (left [0]);
- columnNumber = 0;
- endLineNumber = 0;
- endColumnNumber = 0;
- } else if (left.Length == 2) {
- lineNumber = Int32.Parse (left [0]);
- columnNumber = 0;
- endLineNumber = Int32.Parse (left [1]);
- endColumnNumber = 0;
- } else
- throw new Exception ("Invalid line/column format.");
- } else if (temp.Length == 2) {
- right = temp [1].Split ('-');
- lineNumber = Int32.Parse (temp [0]);
- endLineNumber = 0;
- if (right.Length == 1) {
- columnNumber = Int32.Parse (right [0]);
- endColumnNumber = 0;
- } else if (right.Length == 2) {
- columnNumber = Int32.Parse (right [0]);
- endColumnNumber = Int32.Parse (right [0]);
- } else
- throw new Exception ("Invalid line/column format.");
- } else if (temp.Length == 4) {
- lineNumber = Int32.Parse (temp [0]);
- endLineNumber = Int32.Parse (temp [2]);
- columnNumber = Int32.Parse (temp [1]);
- endColumnNumber = Int32.Parse (temp [3]);
- } else
- throw new Exception ("Invalid line/column format.");
- } else {
- filename = origin;
- lineNumber = 0;
- columnNumber = 0;
- endLineNumber = 0;
- endColumnNumber = 0;
- }
- }
protected virtual string GenerateCommandLineCommands ()
{
toolPath = value;
}
}
+
+ // Snatched from our codedom code, with some changes to make it compatible with csc
+ // (the line+column group is optional is csc)
+ static Regex errorRegex;
+ static Regex CscErrorRegex {
+ get {
+ if (errorRegex == null)
+ errorRegex = new Regex (@"^(\s*(?<file>[^\(]+)(\((?<line>\d*)(,(?<column>\d*[\+]*))?\))?:\s+)*(?<level>\w+)\s+(?<number>.*\d):\s*(?<message>.*)", RegexOptions.Compiled | RegexOptions.ExplicitCapture);
+ return errorRegex;
+ }
+ }
}
}