This is an ANTLRInputStream that is loaded from a file all at once when you construct the object.
This is an ANTLRInputStream that is loaded from a file all at once when you construct the object. This is a special case since we know the exact size of the object to load. We can avoid lots of data copying.
Наследование: AntlrInputStream
Пример #1
0
        public static App ReadApp(string filename)
        {
            var input = new Antlr4.Runtime.AntlrFileStream(filename);
            var app   = GestureAppFromAntlrInput(input);

            return(app);
        }
Пример #2
0
        public static App ReadApp(string filename)
        {
            var input = new Antlr4.Runtime.AntlrFileStream(filename);    //"..\\..\\Tests\\simple.app"
            //var input = new Antlr4.Runtime.AntlrInputStream(inputString);    //"..\\..\\Tests\\simple.app"
            var lexer = new PreposeGesturesLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new PreposeGesturesParser(tokens);
            var tree = parser.app(); // parse
            var visitor = new AppConverter();
            var app = (App)visitor.Visit(tree);

            return app;
        }
Пример #3
0
        public static App ReadApp(string filename)
        {
            var input = new Antlr4.Runtime.AntlrFileStream(filename);                //"..\\..\\Tests\\simple.app"
            //var input = new Antlr4.Runtime.AntlrInputStream(inputString);    //"..\\..\\Tests\\simple.app"
            var lexer   = new PreposeGesturesLexer(input);
            var tokens  = new CommonTokenStream(lexer);
            var parser  = new PreposeGesturesParser(tokens);
            var tree    = parser.app();          // parse
            var visitor = new AppConverter();
            var app     = (App)visitor.Visit(tree);

            return(app);
        }
        private IList<FilePath> GenerateCodeBehindForHeader(ProjectTypeCache cache, CodeBehindWriter writer, FilePath file)
        {
            IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- Parsing {0}", file);

            // Parse and collect information from the document
            AntlrFileStream stream = new AntlrFileStream (file);
            ObjCLexer lexer = new ObjCLexer (stream);
            CommonTokenStream tokenStream = new CommonTokenStream (lexer);
            ObjCParser parser = new ObjCParser (tokenStream);

            ObjCParser.Translation_unitContext context = parser.translation_unit ();
            NativeClassDescriptionCollector<int> visitor = new NativeClassDescriptionCollector<int> ();
            context.Accept (visitor);

            /*
            IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- Dump classes");
            foreach (NativeClassDescriptor classDescriptor in visitor.Descriptors) {
                IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- ClassName={0}", classDescriptor.ClassName);
                IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- SuperClassName={0}", classDescriptor.SuperClassName);
                foreach (NativeMethodDescriptor descriptor in classDescriptor.Methods) {
                    IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- {0}", descriptor);
                }
                foreach (NativeInstanceVariableDescriptor descriptor in classDescriptor.InstanceVariables) {
                    IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- {0}", descriptor);
                }
            }
            */

            List<FilePath> designerFiles = new List<FilePath> ();
            foreach (NativeClassDescriptor classDescriptor in visitor.Descriptors) {
                // Check if the class should be generated
                if (!ShouldGenerateForHeader (classDescriptor)) {
                    IDELogger.Log ("CodeBehindHandler::GenerateCodeBehindForHeader -- Skipping {0} (no outlets or no actions)", classDescriptor.ClassName);
                    continue;
                }

                // Generate the designer part
                FilePath designerFile = this.CodeGenerator.GenerateCodeBehindCode (cache, writer, classDescriptor.ClassName, new []{ classDescriptor });
                if (designerFile != FilePath.Null) {
                    designerFiles.Add (designerFile);
                }
            }

            return designerFiles;
        }
		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));
		}
		private static void Tokenize(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);
			tokens.Fill();
			foreach(var token in tokens.GetTokens())
				output.WriteLine(Format(token));
		}