示例#1
0
            public ConditionParser(string condition, FullTextSearchOptions options)
            {
                ConditionStream stream = new ConditionStream(condition, options);

                this.options = options;

                RootExpression    = new ConditionExpression(options);
                currentExpression = RootExpression;

                Reset();

                while (stream.Read())
                {
                    if (ConditionOperator.IsSymbol(stream.Current))
                    {
                        PutToken();
                        SetToken(stream.Current);
                        PutToken();
                        continue;
                    }
                    switch (stream.Current)
                    {
                    case ' ':
                        PutToken();
                        continue;

                    case '(':
                        PushExpression();
                        continue;

                    case ')':
                        PopExpression();
                        continue;

                    case '"':
                        PutToken();
                        inQuotes = true;
                        SetToken(stream.ReadQuote());
                        PutToken();
                        inQuotes = false;
                        continue;
                    }
                    AddToken(stream.Current);
                }
                PutToken();

                if (!ReferenceEquals(RootExpression, currentExpression))
                {
                    if ((options & FullTextSearchOptions.ThrowOnUnbalancedParens) != 0)
                    {
                        throw new InvalidOperationException("Unbalanced parentheses.");
                    }
                }
            }
            public string ReadQuote()
            {
                StringBuilder sb = new StringBuilder();

                while (Read())
                {
                    if (Current.Equals('"'))
                    {
                        if ((index + 1) == condition.Length)
                        {
                            index = condition.Length;
                            return(sb.ToString());
                        }
                        char peek = condition[index + 1];
                        if ((peek == ' ') || (peek == ')') || (peek == '(') || (ConditionOperator.IsSymbol(peek)))
                        {
                            return(sb.ToString());
                        }
                        if (peek == '"')
                        {
                            index += 1;
                        }
                        else
                        {
                            if ((options & FullTextSearchOptions.ThrowOnUnbalancedQuotes) != 0)
                            {
                                return(sb.ToString());
                            }
                        }
                    }
                    sb.Append(Current);
                }
                if ((options & FullTextSearchOptions.ThrowOnUnbalancedQuotes) != 0)
                {
                    throw new InvalidOperationException("Unbalanced quotes.");
                }
                return(sb.ToString());
            }