public static void AreEqual(CompilationError[] expectedCompilationErrors, CompilationErrorCollection actualCompilationErrors) { if (expectedCompilationErrors == null && actualCompilationErrors != null) Assert.Fail("No errors expected, but errors occured during query execution.\r\nActual errors:\r\n\r\n{0}", GetErrors(actualCompilationErrors)); if (expectedCompilationErrors != null && actualCompilationErrors == null) Assert.Fail("Expected errors, but no errors occured during query execution.\r\nExpected errors:\r\n\r\n{0}", GetErrors(expectedCompilationErrors)); try { if (expectedCompilationErrors == null) return; Assert.AreEqual(expectedCompilationErrors.Length, actualCompilationErrors.Count); for (int i = 0; i < expectedCompilationErrors.Length; i++) { Assert.AreEqual(expectedCompilationErrors[i].Id, actualCompilationErrors[i].Id, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length); Assert.AreEqual(expectedCompilationErrors[i].Text, actualCompilationErrors[i].Text, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length); } } catch (AssertFailedException ex) { string msg = String.Format("Expected query errors do not match actual query errors. See inner exception for first mismatch.\r\nActual errors:\r\n\r\n{0}\r\nExpected errors:\r\n\r\n{1}", GetErrors(actualCompilationErrors), GetErrors(expectedCompilationErrors)); throw new Exception(msg, ex); } }
private void outBox_DoubleClick(object sender, EventArgs e) { SendKeys.Send("{HOME}+{END}"); SendKeys.Flush(); int lineIndex = this.outBox.GetLineFromCharIndex(this.outBox.SelectionStart); if (lineIndex < Workspace.Compilation.Result.Errors.Count) { CompilationError error = Workspace.Compilation.Result.Errors[lineIndex]; if (File.Exists(error.FilePath) == true) { Workspace.OpenFile(error.FilePath, true); } Workspace.SetActiveEditor(error.FilePath, true); // Focus on the error line. int line = error.Line; Workspace.CurrentEditor.TextEditor.ScrollToLine(line); Workspace.CurrentEditor.TextEditor.TextArea.Caret.Line = line; Workspace.CurrentEditor.TextEditor.TextArea.Caret.BringCaretToView(); Workspace.CurrentEditor.TextEditor.TextArea.Caret.Show(); } }
private void GotoError(CompilationError compilationError) { if (compilationError.SourceRange != SourceRange.None) { TextRange offsetAndLength = _actiproLink.GetTextRange(compilationError.SourceRange); syntaxEditor.SelectedView.Selection.SelectRange(offsetAndLength.StartOffset, offsetAndLength.Length); syntaxEditor.Focus(); } }
private void errorListView_DoubleClick(object sender, EventArgs e) { if (errorsListView.FocusedItem != null) { CompilationError compilationError = errorsListView.FocusedItem.Tag as CompilationError; if (compilationError != null) { GotoError(compilationError); } } }
internal static void Internal_OnCompileEvent(string message, string file, int line, bool isError) { if (isError) { CompilationError?.Invoke(message, file, line); } else { CompilationWarning?.Invoke(message, file, line); } }
public void TestSyntaxErrorExtraParensFunc() { string condition = "as_number(\"2\")) = 24"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint>()); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error: unmatched closing ')'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 15), new ErrorPosition(1, 16)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestArgumentError() { string condition = "as_number(true) = true"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint>()); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Invalid arguments to built-in function 'as_number': as_number(bool)", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 10)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestSyntaxErrorMissingParens() { string condition = "(2 + 22 = 24"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new HashSet <Endpoint>()); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(1, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error: missing closing ')'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 2)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestSyntaxErrorExtraParens() { string condition = "(2 + 22 )) = 24"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error: unmatched closing ')'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 10), new ErrorPosition(1, 11)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public static TestDefinition FromXml(XmlDocument xmlDocument) { TestDefinition result = new TestDefinition(); result.CommandText = xmlDocument.SelectSingleNode("/test/sql").InnerText; XmlNode expectedRuntimeErrorNode = xmlDocument.SelectSingleNode("/test/expectedRuntimeError"); if (expectedRuntimeErrorNode != null) { result.ExpectedRuntimeError = expectedRuntimeErrorNode.InnerText; } XmlNode expectedErrorsNode = xmlDocument.SelectSingleNode("/test/expectedErrors"); if (expectedErrorsNode != null) { List <CompilationError> errorList = new List <CompilationError>(); foreach (XmlNode expectedErrorNode in expectedErrorsNode.SelectNodes("expectedError")) { ErrorId errorId = (ErrorId)Enum.Parse(typeof(ErrorId), expectedErrorNode.Attributes["id"].Value); string errorText = expectedErrorNode.Attributes["text"].Value; CompilationError compilationError = new CompilationError(SourceRange.Empty, errorId, errorText); errorList.Add(compilationError); } result.ExpectedCompilationErrors = errorList.ToArray(); } XmlNode expectedResultsNode = xmlDocument.SelectSingleNode("/test/expectedResults"); if (expectedResultsNode != null) { using (StringReader stringReader = new StringReader(expectedResultsNode.InnerXml)) { DataSet dataSet = new DataSet(); dataSet.ReadXml(stringReader); result.ExpectedResults = dataSet.Tables[0]; } } XmlNode expectedPlanNode = xmlDocument.SelectSingleNode("/test/expectedPlan"); if (expectedPlanNode != null) { result.ExpectedPlan = ShowPlan.FromXml(expectedPlanNode); } return(result); }
public void TestSyntaxErrorUnterminatedString() { string condition = "\"2 = 24"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(1, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error: unterminated string", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 8)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestSyntaxErrorUnrecognizedSymbol() { string condition = "3 = @ 3"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error: invalid symbol '@'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 5), new ErrorPosition(1, 6)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestOperandError() { string condition = "3 + '4' = 7"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Invalid operands to binary operator '+': have 'number' and 'string', expected 'number' and 'number'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 3), new ErrorPosition(1, 4)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestInvalidBuiltinError() { string condition = "nope(true) = true"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(2, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Invalid built-in function 'nope'", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 5)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void TestSyntaxErrorMissingParensFunc() { string condition = "as_number(\"2\" = 24"; var route = new Route("id", condition, "hub", TelemetryMessageSource.Instance, new Mock <Endpoint>("id1").Object, 0, 0); var exception = Assert.Throws <RouteCompilationException>(() => RouteCompiler.Instance.Compile(route)); Assert.Equal(1, exception.Errors.Count); CompilationError error1 = exception.Errors.First(); Assert.Equal("Syntax error.", error1.Message); Assert.Equal(new ErrorRange(new ErrorPosition(1, 19), new ErrorPosition(1, 20)), error1.Location); Assert.Equal(ErrorSeverity.Error, error1.Severity); }
public void SmokeTest() { var start = new ErrorPosition(2, 2); var end = new ErrorPosition(2, 3); var range = new ErrorRange(start, end); var error = new CompilationError(ErrorSeverity.Warning, "message", range); Assert.Equal("message", error.Message); Assert.Equal(ErrorSeverity.Warning, error.Severity); Assert.Equal(new ErrorPosition(2, 2), error.Location.Start); Assert.Equal(new ErrorPosition(2, 3), error.Location.End); Assert.Throws <ArgumentException>(() => new CompilationError(ErrorSeverity.Error, "message", new ErrorRange(end, start))); }
private LexicalItem BuildLexicalItem(Token token, CompilationError error) { if (error == null) { return(new LexicalItem() { Token = token, Error = null }); } return(new LexicalItem() { Error = error }); }
public ShaderProgram BuildShaderProgram(string[] shaderNames) { ReloadShaders(); ShaderProgram output = new ShaderProgram(shaderNames); if (output.HasCompilationError) { infoLog.Clear(); infoLog.Append(output.InfoLog); CompilationError?.Invoke(this, EventArgs.Empty); return(null); } else { CompilationSuccess?.Invoke(this, EventArgs.Empty); return(output); } }
public static TestDefinition FromXml(XmlDocument xmlDocument) { TestDefinition result = new TestDefinition(); result.CommandText = xmlDocument.SelectSingleNode("/test/sql").InnerText; XmlNode expectedRuntimeErrorNode = xmlDocument.SelectSingleNode("/test/expectedRuntimeError"); if (expectedRuntimeErrorNode != null) result.ExpectedRuntimeError = expectedRuntimeErrorNode.InnerText; XmlNode expectedErrorsNode = xmlDocument.SelectSingleNode("/test/expectedErrors"); if (expectedErrorsNode != null) { List<CompilationError> errorList = new List<CompilationError>(); foreach (XmlNode expectedErrorNode in expectedErrorsNode.SelectNodes("expectedError")) { ErrorId errorId = (ErrorId) Enum.Parse(typeof(ErrorId), expectedErrorNode.Attributes["id"].Value); string errorText = expectedErrorNode.Attributes["text"].Value; CompilationError compilationError = new CompilationError(SourceRange.Empty, errorId, errorText); errorList.Add(compilationError); } result.ExpectedCompilationErrors = errorList.ToArray(); } XmlNode expectedResultsNode = xmlDocument.SelectSingleNode("/test/expectedResults"); if (expectedResultsNode != null) { using (StringReader stringReader = new StringReader(expectedResultsNode.InnerXml)) { DataSet dataSet = new DataSet(); dataSet.ReadXml(stringReader); result.ExpectedResults = dataSet.Tables[0]; } } XmlNode expectedPlanNode = xmlDocument.SelectSingleNode("/test/expectedPlan"); if (expectedPlanNode != null) { result.ExpectedPlan = ShowPlan.FromXml(expectedPlanNode); } return result; }
public void TestEquals() { var error1 = new CompilationError(ErrorSeverity.Error, "message", new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 2))); var error2 = new CompilationError(ErrorSeverity.Error, "message", new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 2))); var error3 = new CompilationError(ErrorSeverity.Warning, "message", new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 2))); var error4 = new CompilationError(ErrorSeverity.Error, "different", new ErrorRange(new ErrorPosition(1, 1), new ErrorPosition(1, 2))); var error5 = new CompilationError(ErrorSeverity.Error, "message", new ErrorRange(new ErrorPosition(1, 2), new ErrorPosition(1, 3))); Assert.Equal(error1, error2); Assert.NotEqual(error1, error3); Assert.NotEqual(error1, error4); Assert.NotEqual(error1, error5); Assert.Equal(error1.GetHashCode(), error2.GetHashCode()); Assert.NotEqual(error1.GetHashCode(), error3.GetHashCode()); // ReSharper disable once EqualExpressionComparison Assert.True(error1.Equals(error1)); Assert.False(error1.Equals(null)); Assert.False(error1.Equals(new object())); }
public override async Task MapReaderData(OracleDataReader reader, CancellationToken cancellationToken) { while (await reader.ReadAsynchronous(cancellationToken)) { var error = new CompilationError { Owner = _owner, ObjectName = _objectName, ObjectType = (string)reader["TYPE"], Line = Convert.ToInt32(reader["LINE"]) - 1, Column = Convert.ToInt32(reader["POSITION"]), Message = (string)reader["TEXT"], Severity = (string)reader["ATTRIBUTE"], Code = Convert.ToInt32(reader["MESSAGE_NUMBER"]), Statement = _statement }; _errors.Add(error); } }
void Error(IToken offendingSymbol, string message) { // A couple things to note about the start and end column range: // 1. line and column numbers are zero based from the lexer but one based for our API // 2. error ranges are start inclusive but end exclusive [start, end). string input = offendingSymbol.InputStream.ToString(); string[] lines = input.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None); int line = offendingSymbol.Line; int column = offendingSymbol.Column + 1; int tokenLength = offendingSymbol.Text.Length; int lineLength = lines[line - 1].Length; var start = new ErrorPosition(line, column); // Set the end column to the minimum of column + token length or line length + 2 (one based and exclusive end column, see note above) int endColumn = Math.Min(column + tokenLength, lineLength + 2); var end = new ErrorPosition(line, endColumn); var error = new CompilationError(ErrorSeverity.Error, message, new ErrorRange(start, end)); this.errors.Add(error); }
public virtual Parser HandleParseError(Parser parser, CompilationError<ParseError> error) { return parser; }
public Parser OnError(Parser parser, CompilationError<ParseError> error) { return compilationContext.HandleParseError(parser, error); }
public Tokenizer OnError(Tokenizer tokenizer, CompilationError<TokenizationError> error) { return compilationContext.HandleTokenError(tokenizer, error); }
public CompilationErrorEventArgs(CompilationError Error) { this.error = Error; }
public ParseResult(Node node, CompilationError error) { Node = node; Error = error; }
protected Parser ParseInterpolatedStringLiteral(Func<IEnumerable<Source>> interpolatedExpressions, Region region, CompilationError<ParseError> error) { return ParseToken( nextParser => nextParser.ParseInterpolatedStringLiteral(interpolatedExpressions, region, error), error); }
public override Parser HandleParseError(Parser parser, CompilationError<ParseError> error) { return ParentContext.HandleParseError(parser, error); }
protected Parser ParsePlus(Location location, CompilationError<ParseError> error) { return ParseToken(nextParser => nextParser.ParsePlus(location, error), error); }
protected Parser ParseNumberLiteral(Func<double> number, Region region, CompilationError<ParseError> error) { return ParseToken(nextParser => nextParser.ParseNumberLiteral(number, region, error), error); }
protected Parser ParseForwardSlash(Location location, CompilationError<ParseError> error) { return ParseToken(nextParser => nextParser.ParseForwardSlash(location, error), error); }
public virtual void HandleSyntaxError(CompilationError<SyntaxError> error) { }
private void ImportTestDefinition() { if (openTestDefinitionFileDialog.ShowDialog() == DialogResult.OK) { Text = String.Format("NQuery - [{0}]", Path.GetFileName(openTestDefinitionFileDialog.FileName)); saveTestDefinitionFileDialog.FileName = openTestDefinitionFileDialog.FileName; string query; List <CompilationError> errorList = new List <CompilationError>(); string runtimeError = null; DataSet dataSet = null; ShowPlan showPlan = null; #region XML Handling XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(openTestDefinitionFileDialog.FileName); query = xmlDocument.SelectSingleNode("/test/sql").InnerText; XmlNode expectedRuntimeErrorNode = xmlDocument.SelectSingleNode("/test/expectedRuntimeError"); if (expectedRuntimeErrorNode != null) { runtimeError = expectedRuntimeErrorNode.InnerText; } XmlNode expectedErrorsNode = xmlDocument.SelectSingleNode("/test/expectedErrors"); if (expectedErrorsNode != null) { foreach (XmlNode expectedErrorNode in expectedErrorsNode.SelectNodes("expectedError")) { ErrorId errorId = (ErrorId)Enum.Parse(typeof(ErrorId), expectedErrorNode.Attributes["id"].Value); string errorText = expectedErrorNode.Attributes["text"].Value; CompilationError compilationError = new CompilationError(SourceRange.Empty, errorId, errorText); errorList.Add(compilationError); } } XmlNode expectedResultsNode = xmlDocument.SelectSingleNode("/test/expectedResults"); if (expectedResultsNode != null) { dataSet = new DataSet(); using (StringReader stringReader = new StringReader(expectedResultsNode.InnerXml)) { dataSet.ReadXml(stringReader); } } XmlNode expectedPlanNode = xmlDocument.SelectSingleNode("/test/expectedPlan"); if (expectedPlanNode != null) { showPlan = ShowPlan.FromXml(expectedPlanNode); } #endregion ClearErrors(); resultsDataGridView.DataSource = null; showPlanControl.ShowPlan = null; syntaxEditor.Text = query; if (runtimeError != null) { LoadErrors(runtimeError); } LoadErrors(errorList); if (dataSet != null) { LoadResults(dataSet.Tables[0]); } if (showPlan != null) { showPlanControl.ShowPlan = showPlan; } } }
public virtual Tokenizer HandleTokenError(Tokenizer tokenizer, CompilationError<TokenizationError> error) { return tokenizer; }
protected Tokenizer OnError(CompilationError<TokenizationError> error) { return RootTokenizer.OnError(this, error); }
public void AddError(CompilationError e) { Errors.Add(e); }
public override Tokenizer HandleTokenError(Tokenizer tokenizer, CompilationError<TokenizationError> error) { if(error.Error == TokenizationError.UnexpectedRightCurlyBracket) { interpolationTokenizer.endColumn = error.Location.Column; interpolationTokenizer.justUninterpolated = true; tokenizer.OnDone(); return interpolationTokenizer; } else { return ParentContext.HandleTokenError(tokenizer, error); } }
public override void HandleSyntaxError(CompilationError<SyntaxError> error) { ParentContext.HandleSyntaxError (error); }
internal TypeSymbol ThrowError(CompilationError e) { throw e; }
protected Parser ParseStringLiteral(Func<string> @string, Region region, CompilationError<ParseError> error) { return ParseToken(nextParser => nextParser.ParseStringLiteral(@string, region, error), error); }
protected Parser ParseIdentifier(Func<string> identifier, Region region, CompilationError<ParseError> error) { return ParseToken(nextParser => nextParser.ParseStringLiteral(identifier, region, error), error); }
Parser ParseToken(Func<BaseParser, Parser> nextParser, CompilationError<ParseError> error) { if(NextParser != null) { return nextParser(NextParser); } else { return ErrorConsumer(this, error); } }
public InterpreterResult(dynamic result, CompilationError error) { Result = result; Error = error; }