public string ReportPosition() { DslScript dslScript; int position; if (PositionInTokenList < _tokenList.Count()) { dslScript = CurrentToken.DslScript; position = CurrentToken.PositionInDslScript; } else if (_tokenList.Count > 0) { dslScript = _tokenList.Last().DslScript; position = dslScript.Script.Length; } else { dslScript = new DslScript { Script = "", Name = "", Path = "" }; position = 0; } return(ScriptPositionReporting.ReportPosition(dslScript.Script, position, dslScript.Path)); }
public string ReportPosition(int index) { if (index < 0 || index > Script.Length) { throw new FrameworkException("Error in DSL script parser. Provided position in script is out of range. Position: " + index + "."); } return(ScriptPositionReporting.ReportPosition(Script, index, Path)); }
private void FailOnCompilerErrors(CompilerResults compilerResults, string sourceCode, string sourcePath) { if (compilerResults.Errors.HasErrors) { var errors = (from System.CodeDom.Compiler.CompilerError error in compilerResults.Errors where !error.IsWarning select error).ToList(); var report = new StringBuilder(); report.Append(errors.Count + " errors while compiling '" + Path.GetFileName(sourcePath) + "'"); if (errors.Count > _errorReportLimit.Value) { report.AppendLine(". The first " + _errorReportLimit.Value + " errors:"); } else { report.AppendLine(":"); } foreach (var error in errors.Take(_errorReportLimit.Value)) { report.AppendLine(); report.AppendLine(error.ErrorText); if (error.Line > 0 || error.Column > 0) { report.AppendLine(ScriptPositionReporting.ReportPosition(sourceCode, error.Line, error.Column, sourcePath)); } } if (errors.Count() > _errorReportLimit.Value) { report.AppendLine(); report.AppendLine("..."); } throw new FrameworkException(report.ToString().Trim()); } }
private string ReportErrors(CompilerResults results, string generatedCode, string filePath) { var errors = (from System.CodeDom.Compiler.CompilerError error in results.Errors where !error.IsWarning select error).ToList(); var report = new StringBuilder(); report.Append(errors.Count + " errors while compiling '" + Path.GetFileName(filePath) + "'"); if (errors.Count > _errorReportLimit.Value) { report.AppendLine(". The first " + _errorReportLimit.Value + " errors:"); } else { report.AppendLine(":"); } foreach (var error in errors.Take(_errorReportLimit.Value)) { report.AppendLine(); report.AppendLine(error.ErrorText); if (error.Line > 0 || error.Column > 0) { report.AppendLine(ScriptPositionReporting.ReportPosition(generatedCode, error.Line, error.Column, filePath)); } } if (errors.Count() > _errorReportLimit.Value) { report.AppendLine(); report.AppendLine("..."); } return(report.ToString().Trim()); }
public string ReportPosition() { var(dslScript, position) = GetPositionInScript(); return(ScriptPositionReporting.ReportPosition(dslScript.Script, position, dslScript.Path)); }
public void ReportPosition() { Assert.AreEqual("At line 1, column 6,\r\n after: \"01234\",\r\n before: \"56789\".", ScriptPositionReporting.ReportPosition("0123456789", 5)); Assert.AreEqual("At line 1, column 6, file 'abc.txt',\r\n after: \"01234\",\r\n before: \"56789\".", ScriptPositionReporting.ReportPosition("0123456789", 5, "abc.txt")); }