///////////////////////////////////////////////////////////////////////////// //public ErrorItem ParseNmpError( string errStr ) //{ // // ****** // var errorParts = errStr.Split( ';' ); // if( errorParts.Length < 4 ) { // return null; // } // // ****** // var locationInfo = errorParts [ 2 ]; // var parts = locationInfo.Split( ',' ); // if( 3 != parts.Length ) { // return null; // } // // ****** // try { // // ****** // ErrorItem errorItem = new ErrorItem { }; // errorItem.Line = Int32.Parse( parts [ 0 ].Substring( parts [ 0 ].IndexOf( '=' ) + 1 ) ); // errorItem.Column = Int32.Parse( parts [ 1 ].Substring( parts [ 1 ].IndexOf( '=' ) + 1 ) ); // if( parts [ 2 ].Contains( "File" ) ) { // var fn = parts [ 2 ].Substring( parts [ 2 ].IndexOf( '"' ) ); // errorItem.FileName = fn.Substring( 1, fn.Length - 2 ); // } // else { // errorItem.FileName = parts [ 2 ]; // } // // ****** // errorItem.ErrorText = errStr; // // ****** // return errorItem; // } // catch { // return null; // } //} ///////////////////////////////////////////////////////////////////////////// /* Error: while handling a .net object; exception: unable to locate an implementation of "Replace" where arguments match (or can be converted from): "" (values passed: ) Tried matching: String.Replace( Char, Char ) String.Replace( String, String ); Line=7, Col=2, File "D:\Work\New 2014\Projects\gitsharper\Sharp-ToolRunner\UnitTests\Src\TestData\Nmp4\NmpError1.nmp4"; ------------------------------------------------------------ Error in: ------------------------------------------------------------ #fredIs.Replace() ------------------------------------------------------------ Context: ------------------------------------------------------------ #.popBuffer() #fredIs.Replace() ------------------------------------------------------------ Invocation stack: #fredIs Invocation stack ends */ public bool Split() { const string regExGetLineCol = @"Line=(\d*?)[, ]*?Col=(\d*?)\s*?,"; // ****** Regex rx = new Regex( regExGetLineCol ); Match match2 = rx.Match( errorString ); if( !match2.Success ) { return false; } var groups2 = match2.Groups; int line; if( !int.TryParse( groups2 [ 1 ].Value, out line ) ) { return false; } int col; if( !int.TryParse( groups2 [ 2 ].Value, out col ) ) { return false; } errorItem = new ErrorItem( false, -1 ) { FileName = filePath, ErrorText = errorString, Line = line, Column = col }; // ****** return true; }
///////////////////////////////////////////////////////////////////////////// /* ParseError: Unrecognised input in D:\Work\New 2014\Projects\gitsharper\Sharp-ToolRunner\UnitTests\Src\TestData\Less\tool-runner.in.txt on line 3, column 2: 2 background : blue; 3 @ @ 4 } ParseError: Unrecognised input in D:\Work\New 2014\Projects\gitsharper\Sharp-ToolRunner\UnitTests\Src\TestData\Less\tool-runner.in.txt on line 3, column 2: err type : err message with embeded/trailing line and column : block of code surrounding the error */ public bool Split() { const string regExSplitError = @"(?s)\A(.*?):(.*?)\n(.*$)"; const string regExGetLineCol = @"line\s*?(\d*?)[, ]*?column\s*?(\d*?)\s*?:"; // ****** Regex rx = new Regex( regExSplitError ); Match match = rx.Match( errorString ); // ****** // // only require first 3 matches if( !match.Success ) { return false; } // ****** // // group[0] represents the overall capture // group[1] error type // group[2] error explanation // group[3] file listing where error occurs // var groups = match.Groups; //var errorType = groups [ 1 ].Value.Trim(); var errorMsg = groups [ 2 ].Value.Trim(); //var remainder = groups [ 3 ].Value; // // ... runner.in.txt on line 3, column 2: // Regex rx2 = new Regex( regExGetLineCol ); Match match2 = rx2.Match( errorMsg ); if( !match2.Success ) { return false; } var groups2 = match2.Groups; int line; if( !int.TryParse( groups2 [ 1 ].Value, out line ) ) { return false; } int col; if( !int.TryParse( groups2 [ 2 ].Value, out col ) ) { return false; } errorItem = new ErrorItem( false, -1 ) { FileName = filePath, ErrorText = errorString, Line = line, Column = col }; // ****** return true; }