/// <summary> /// Executa o parser na consulta. /// </summary> /// <param name="query"></param> /// <returns></returns> public ParseMessage Parse(string query) { using (var parser = new CQLParser("Colosoft.Caching.Resources.cql.cgt", _logger)) { using (var source = new System.IO.StringReader(query)) { ParseMessage message = parser.Parse(source, true); _currentReduction = parser.CurrentReduction; return(message); } } }
private static void AddErrorListener(this CQLParser parser, IErrorListener errorListener) { if (errorListener != null) { parser.AddErrorListener(errorListener); } else { errorListener = new ErrorListener(); errorListener.ErrorDetected += (sender, ex) => { throw ex; }; parser.AddErrorListener(errorListener); } }
/// <summary> /// Parses a user query (without validating it). You practically only get the syntax tree. /// </summary> /// <param name="text"></param> /// <param name="errorListener"></param> /// <returns></returns> public static Query ParseForSyntaxOnly(string text, IErrorListener errorListener = null) { var inputStream = new AntlrInputStream(text); var speakLexer = new CQLLexer(inputStream); var commonTokenStream = new CommonTokenStream(speakLexer); var parser = new CQLParser(commonTokenStream); AddErrorListener(parser, errorListener); var parseContext = parser.query(); var visitor = new QueryVisitor(); return(visitor.Visit(parseContext)); }