Exemple #1
0
 private QueryParser(TextReader reader)
 {
     _scanner = new QueryScanner(reader);
     _scanner.Next();
 }
Exemple #2
0
        public IExpression ParseQuery(bool includeHintTerms)
        {
            if (_scanner.Current.Type == TokenType.End)
            {
                return(null);
            }

            List <IExpression> terms = new List <IExpression>();

            // Parse the first term
            IExpression term = ParseAndExpression(includeHintTerms);

            if (term == null)
            {
                return(null);
            }
            terms.Add(term);

            while (_scanner.Current.Type == TokenType.BooleanOperatorOr)
            {
                // If this is an 'Or', combine with the next expression
                string operatorText = _scanner.Current.Content;
                _scanner.Next();

                if (_scanner.Current.Type == TokenType.End && String.IsNullOrEmpty(_scanner.Current.Prefix) && operatorText == "|")
                {
                    // If '|' was typed and there's no follow space, keep suggesting '||'
                    if (includeHintTerms)
                    {
                        terms.Add(new TermExpression("")
                        {
                            Guidance = new IntelliSenseGuidance(operatorText, QueryTokenCategory.BooleanOperator)
                        });
                    }
                }
                else
                {
                    term = ParseAndExpression(includeHintTerms);
                    if (term == null && includeHintTerms)
                    {
                        term = new TermExpression("")
                        {
                            Guidance = new IntelliSenseGuidance("", QueryTokenCategory.Term)
                        }
                    }
                    ;
                    if (term != null)
                    {
                        terms.Add(term);
                    }
                }
            }

            // If there was something invalid at the end of the query, return a null result
            if (_scanner.Current.Type != TokenType.End && _scanner.Current.Type != TokenType.RightParen)
            {
                return(null);
            }

            if (terms.Count == 1)
            {
                return(terms[0]);
            }
            else
            {
                return(new OrExpression(terms.ToArray()));
            }
        }