예제 #1
0
        public static SelectStmtInfo ParseSQL(string sql)
        {
            Antlr4.Runtime.AntlrInputStream input = new Antlr4.Runtime.AntlrInputStream(sql);
            SelectSQLLexer lexer = new SelectSQLLexer(input);

            Antlr4.Runtime.UnbufferedTokenStream tokens = new Antlr4.Runtime.UnbufferedTokenStream(lexer);
            SelectSQLParser parser = new SelectSQLParser(tokens);

            var tree = parser.compileUnit();

            ParseTreeWalker walker = new ParseTreeWalker();

            SelectSQLTreeListener lsn = new SelectSQLTreeListener();

            walker.Walk(lsn, tree);

            return lsn.SelectStmt;
        }
        public static ParseResult Parse(string sentence)
        {
            Antlr4.Runtime.AntlrInputStream input = new Antlr4.Runtime.AntlrInputStream(sentence);
            WeatherRuleLexer lexer = new WeatherRuleLexer(input);

            Antlr4.Runtime.UnbufferedTokenStream tokens = new Antlr4.Runtime.UnbufferedTokenStream(lexer);
            WeatherRuleParser parser = new WeatherRuleParser(tokens);
            parser.RemoveErrorListeners();

            var tree = parser.compileUnit();

            ParseTreeWalker walker = new ParseTreeWalker();

            WeatherListener lsn = new WeatherListener();

            walker.Walk(lsn, tree);

            return lsn.Result;
        }
예제 #3
0
        public static SelectStmtInfo ParseSQL(string sql)
        {
            Antlr4.Runtime.AntlrInputStream input = new Antlr4.Runtime.AntlrInputStream(sql);
            SelectSQLLexer lexer = new SelectSQLLexer(input);

            ErrorListener errorListner = new ErrorListener();

            Antlr4.Runtime.UnbufferedTokenStream tokens = new Antlr4.Runtime.UnbufferedTokenStream(lexer);
            SelectSQLParser parser = new SelectSQLParser(tokens);

            parser.AddErrorListener(errorListner);

            var tree = parser.compileUnit();

            ParseTreeWalker walker = new ParseTreeWalker();

            SelectSQLTreeListener lsn = new SelectSQLTreeListener();

            walker.Walk(lsn, tree);

            return(lsn.SelectStmt);
        }
예제 #4
0
        public static string GenerateStringView(string template, Dictionary<string, object> variables)
        {
            Antlr4.Runtime.AntlrInputStream input = new Antlr4.Runtime.AntlrInputStream(template);
            TemplateLexer lexer = new TemplateLexer(input);

            Antlr4.Runtime.UnbufferedTokenStream tokens = new Antlr4.Runtime.UnbufferedTokenStream(lexer);
            TemplateParser parser = new TemplateParser(tokens);

            SimpleTemplateErrorListener errorLsn=new SimpleTemplateErrorListener();

            parser.AddErrorListener(errorLsn);

            var tree = parser.parse();

            if (errorLsn.ErrorType != ParseErrorType.Successful)
                throw new Exception(errorLsn.ErrorType.ToString());

            SimpleTemplateVisitor visitor = new SimpleTemplateVisitor(variables);

            string result=(string)visitor.Visit(tree);

            return result;
        }