public CompilationUnitSyntax Parse(PackageSyntax package, SourceText sourceText)
        {
            // TODO make use of the package.  We don't currently use the package, but we
            // are taking it as an argument becuase we should be for things like:
            //   * Language Version
            //   * Dependency Names
            //   * Defined Preprocessor Symbols
            var builder = new ParseDiagnosticsBuilder(sourceText);
            var parser = sourceText.NewParser();
            // Stupid ANTLR makes it difficult to do this in the constructor
            parser.RemoveErrorListeners();
            var errorsListener = new GatherErrorsListener(builder);
            parser.AddErrorListener(errorsListener);
            parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;

            var tree = parser.compilationUnit();
            var syntaxCheck = new SyntaxCheckVisitor(builder);
            tree.Accept(syntaxCheck);

            var diagnostics = builder.Complete();
            if(diagnostics.Any())
                return new CompilationUnitSyntax(sourceText, Enumerable.Empty<UsingSyntax>(), Enumerable.Empty<DeclarationSyntax>(), diagnostics);

            var compilationUnitBuilder = new CompilationUnitBuilder(sourceText, diagnostics);
            return tree.Accept(compilationUnitBuilder);
        }
        public CompilationUnitSyntax Parse(PackageSyntax package, SourceText sourceText)
        {
            // TODO make use of the package.  We don't currently use the package, but we
            // are taking it as an argument becuase we should be for things like:
            //   * Language Version
            //   * Dependency Names
            //   * Defined Preprocessor Symbols
            var builder = new ParseDiagnosticsBuilder(sourceText);
            var parser  = sourceText.NewParser();

            // Stupid ANTLR makes it difficult to do this in the constructor
            parser.RemoveErrorListeners();
            var errorsListener = new GatherErrorsListener(builder);

            parser.AddErrorListener(errorsListener);
            parser.Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;

            var tree        = parser.compilationUnit();
            var syntaxCheck = new SyntaxCheckVisitor(builder);

            tree.Accept(syntaxCheck);

            var diagnostics = builder.Complete();

            if (diagnostics.Any())
            {
                return(new CompilationUnitSyntax(sourceText, Enumerable.Empty <UsingSyntax>(), Enumerable.Empty <DeclarationSyntax>(), diagnostics));
            }

            var compilationUnitBuilder = new CompilationUnitBuilder(sourceText, diagnostics);

            return(tree.Accept(compilationUnitBuilder));
        }
        private static void PrintTree(string codePath, TextWriter output)
        {
            var parser = new AdamantParser(codePath)
            {
                BuildParseTree = true
            };
            var tree        = parser.compilationUnit();
            var diagnostics = new ParseDiagnosticsBuilder(new SourceFile(new FileInfo(codePath)));
            var syntaxCheck = new SyntaxCheckVisitor(diagnostics);

            tree.Accept(syntaxCheck);
            // TODO print syntax check errors
            output.WriteLine(tree.ToStringTree(parser));
        }
		public GatherErrorsListener(ParseDiagnosticsBuilder diagnostics)
		{
			this.diagnostics = diagnostics;
		}
 private static void PrintTree(string codePath, TextWriter output)
 {
     var parser = new AdamantParser(codePath) { BuildParseTree = true };
     var tree = parser.compilationUnit();
     var diagnostics = new ParseDiagnosticsBuilder(new SourceFile(new FileInfo(codePath)));
     var syntaxCheck = new SyntaxCheckVisitor(diagnostics);
     tree.Accept(syntaxCheck);
     // TODO print syntax check errors
     output.WriteLine(tree.ToStringTree(parser));
 }
 public SyntaxCheckVisitor(ParseDiagnosticsBuilder diagnostics)
 {
     this.diagnostics = diagnostics;
 }