Пример #1
0
        /// <summary>
        /// Gets the Query for the given Expression.
        /// </summary>
        /// <param name="expression">
        /// The Expression to get the Query for.
        /// </param>
        /// <returns>
        /// An instance of Query.
        /// </returns>
        public Query GetQuery(Expression expression)
        {
            QueryVisitor visitor = new QueryVisitor(this);

            return(visitor.GetQuery(expression));
        }
Пример #2
0
        /// <summary>
        /// Parst den übergeben String und gibt das Ergebnis als HttpQuery Objekt mit den Ergebnissen wieder zurück.
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public static HttpQuery Query(string query)
        {
            AntlrInputStream input = new AntlrInputStream(query);
            var lexer = new HttpQueryLexer(input);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            var parser = new HttpQueryParser(tokens);
            var context = parser.init();

            if (context.exception == null && parser.NumberOfSyntaxErrors == 0)
            {
                var visitor = new QueryVisitor<object>();

                visitor.Visit(context);
                return visitor.GetQuery();
            }
            else
            {
                return new HttpQuery() { Exception = new Exception("Syntax Error") };
            }
        }