/// <summary> /// Validates the code content of a TextReader and returns the top of the compilation unit syntax tree. /// If parsing resulted in syntax errors the result will be <c>null</c>. /// </summary> /// <param name="stream">The TextReader to parse code from.</param> /// <returns>Top level node of an LSL syntax tree.</returns> /// <exception cref="ArgumentNullException"><paramref name="stream"/> is <c>null</c>.</exception> public ILSLCompilationUnitNode Validate(TextReader stream) { if (stream == null) { throw new ArgumentNullException("stream"); } HasSyntaxErrors = false; var inputStream = new AntlrInputStream(stream); var lexer = new LSLLexer(inputStream); lexer.RemoveErrorListeners(); var tokenStream = new CommonTokenStream(lexer); var parser = new LSLParser(tokenStream); parser.RemoveErrorListeners(); parser.AddErrorListener(_antlrParserErrorHandler); var parseTree = parser.compilationUnit(); if (parser.NumberOfSyntaxErrors > 0) { HasSyntaxErrors = true; return(null); } try { var tree = _validatorVisitor.ValidateAndBuildTree(parseTree, lexer.Comments); if (_validatorVisitor.HasSyntaxWarnings) { HasSyntaxWarnings = true; } if (tree.HasErrors) { HasSyntaxErrors = true; return(null); } return(tree); } finally { _validatorVisitor.Reset(); } }