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));
        }
 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));
 }
		private static MainFunctions Compile(string codePath, TextWriter output)
		{
			var stream = new AntlrFileStream(codePath);
			var lexer = new AdamantLexer(stream);
			var tokens = new CommonTokenStream(lexer);
			var parser = new AdamantParser(tokens) { BuildParseTree = true };
			var tree = parser.compilationUnit();
			var syntaxCheck = new SyntaxCheckVisitor();
			tree.Accept(syntaxCheck);
			//var buildAst = new BuildAstVisitor();
			//var ast = (Assemblage)tree.Accept(buildAst);
			//var borrowChecker = new BorrowChecker();
			//borrowChecker.Check(ast);
			var cSharpGenerator = new CSharpGenerator(output);
			return tree.Accept(cSharpGenerator);
		}
		private static void PrintTree(string codePath, string outputPath)
		{
			var output = outputPath != null ? File.CreateText(outputPath) : Console.Out;
			var stream = new AntlrFileStream(codePath);
			var lexer = new AdamantLexer(stream);
			var tokens = new CommonTokenStream(lexer);

			var parser = new AdamantParser(tokens) { BuildParseTree = true };
			var tree = parser.compilationUnit();
			var syntaxCheck = new SyntaxCheckVisitor();
			tree.Accept(syntaxCheck);
			output.WriteLine(tree.ToStringTree(parser));
		}