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; }
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); }
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; }