Exemplo n.º 1
0
        internal IExecutableQuery Compile(
            TextReader inputQuery,
            IQueryErrorListener queryErrorListener,
            QueryCompilationParameters parameters)
        {
            // create all necessary components to parse a query
            var input = new AntlrInputStream(inputQuery);
            var lexer = new QueryLexer(input);

            lexer.AddErrorListener(new LexerErrorListener(queryErrorListener));

            var compiler = new QueryCompilationListener(
                _queryFactory,
                this,
                queryErrorListener,
                _runtime,
                parameters);

            var tokenStream   = new CommonTokenStream(lexer);
            var errorListener = new ParserErrorListener(queryErrorListener);
            var parser        = new QueryParser(tokenStream);

            parser.AddErrorListener(errorListener);

            // parse and compile the query
            if (!parameters.IsRecursiveCall)
            {
                queryErrorListener.BeforeCompilation();
            }

            IQuery result;

            try
            {
                var tree = parser.entry();
                ParseTreeWalker.Default.Walk(compiler, tree);
                result = compiler.Finish();

                if (result == null)
                {
                    return(null);
                }

                result = result.WithText(input.ToString());
            }
            catch (ParseCanceledException)
            {
                // an error has already been reported
                return(null);
            }
            finally
            {
                if (!parameters.IsRecursiveCall)
                {
                    queryErrorListener.AfterCompilation();
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 public QueryCompilationListener(
     IQueryFactory queryFactory,
     QueryCompiler compiler,
     IQueryErrorListener errorListener,
     IRuntime runtime,
     QueryCompilationParameters parameters)
 {
     _queryFactory  = queryFactory;
     _compiler      = compiler;
     _errorListener = errorListener;
     _runtime       = runtime;
     _parameters    = parameters;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new parameters for recursive compilation of <paramref name="newViewName"/>
        /// </summary>
        /// <param name="newViewName">
        /// Name of the view which will be compiled using these parameters.
        /// </param>
        /// <returns></returns>
        public QueryCompilationParameters Create(string newViewName)
        {
            if (ViewName != null)
            {
                Parent[ViewName] = newViewName;
            }

            var result = new QueryCompilationParameters
            {
                ViewName = newViewName,
                Parent   = Parent
            };

            return(result);
        }