Esempio n. 1
0
        private void ParseJson(string input)
        {
            AntlrInputStream stream = new AntlrInputStream(input);
            ITokenSource     lexer  = new JSONLexer(stream);
            ITokenStream     tokens = new CommonTokenStream(lexer);
            JSONParser       parser = new JSONParser(tokens);

            parser.BuildParseTree = true;
            JSONParser.JsonContext tree = parser.json();
            if (tree != null)
            {
                var builder = new TreeBuilder(parser, tree, treeModel);
                builder.Build();
            }
        }
Esempio n. 2
0
        private void ParseJava(string input)
        {
            AntlrInputStream stream = new AntlrInputStream(input);
            ITokenSource     lexer  = new JavaLexer(stream);
            ITokenStream     tokens = new CommonTokenStream(lexer);
            JavaParser       parser = new JavaParser(tokens);

            parser.BuildParseTree = true;
            JavaParser.CompilationUnitContext tree = parser.compilationUnit();
            if (tree != null)
            {
                var builder = new TreeBuilder(parser, tree, treeModel);
                builder.Build();
            }
        }
Esempio n. 3
0
        private void ParseCpp(string input)
        {
            AntlrInputStream stream = new AntlrInputStream(input);
            ITokenSource     lexer  = new CPP14Lexer(stream);
            ITokenStream     tokens = new CommonTokenStream(lexer);
            CPP14Parser      parser = new CPP14Parser(tokens);

            parser.BuildParseTree = true;
            CPP14Parser.TranslationunitContext tree = parser.translationunit();
            if (tree != null)
            {
                var builder = new TreeBuilder(parser, tree, treeModel);
                builder.Build();
            }
        }
Esempio n. 4
0
        private void ParseCSharp(string input)
        {
            Lexer preprocessorLexer = new CSharpLexer(new AntlrInputStream(input));
            // Collect all tokens with lexer (CSharpLexer.g4).
            var tokens = preprocessorLexer.GetAllTokens();
            //TODO: handle preprocessor tokens
            var          codeTokenSource = new ListTokenSource(tokens);
            var          codeTokenStream = new CommonTokenStream(codeTokenSource);
            CSharpParser parser          = new CSharpParser(codeTokenStream);
            // Parse syntax tree (CSharpParser.g4)
            var tree = parser.compilation_unit();

            if (tree != null)
            {
                var builder = new TreeBuilder(parser, tree, treeModel);
                builder.Build();
            }
        }