private static LocalizedString FormatErrorCode(ParserErrorCode errorCode)
        {
            switch (errorCode)
            {
            case ParserErrorCode.InvalidKindFormat:
                return(ServerStrings.InvalidKindFormat);

            case ParserErrorCode.InvalidDateTimeFormat:
                return(ServerStrings.InvalidDateTimeFormat);

            case ParserErrorCode.InvalidDateTimeRange:
                return(ServerStrings.InvalidDateTimeRange);

            case ParserErrorCode.InvalidPropertyKey:
                return(ServerStrings.InvalidPropertyKey);

            case ParserErrorCode.MissingPropertyValue:
                return(ServerStrings.MissingPropertyValue);

            case ParserErrorCode.MissingOperand:
                return(ServerStrings.MissingOperand);

            case ParserErrorCode.InvalidOperator:
                return(ServerStrings.InvalidOperator);

            case ParserErrorCode.UnbalancedQuote:
                return(ServerStrings.UnbalancedQuote);

            case ParserErrorCode.UnbalancedParenthesis:
                return(ServerStrings.UnbalancedParenthesis);

            case ParserErrorCode.SuffixMatchNotSupported:
                return(ServerStrings.SuffixMatchNotSupported);

            case ParserErrorCode.UnexpectedToken:
                return(ServerStrings.UnexpectedToken);

            case ParserErrorCode.InvalidModifier:
                return(ServerStrings.InvalidModifier);

            case ParserErrorCode.StructuredQueryException:
                return(ServerStrings.StructuredQueryException);

            case ParserErrorCode.KqlParseException:
                return(ServerStrings.KqlParseException);

            case ParserErrorCode.ParserError:
                return(ServerStrings.InternalParserError);

            default:
                return(default(LocalizedString));
            }
        }
        private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3, string message4)
        {
            string errorMessage = "Unknown error";
            int    errorCode    = (int)code;

            if (errorCode < errorsList.Length)
            {
                errorMessage = string.Format(errorsList[errorCode], message1, message2, message3, message4);
            }
            string             fullMessage = "Parser error: " + errorMessage;
            StiParserException ex          = new StiParserException(fullMessage);

            ex.BaseMessage = errorMessage;
            if (token != null)
            {
                ex.Position = expressionPosition + token.Position;
                ex.Length   = token.Length;
            }
            throw ex;
        }
        private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3, string message4)
        {
            string errorMessage = "Неизвестная ошибка";
            int    errorCode    = (int)code;

            if (errorCode < errorsList.Length)
            {
                errorMessage = string.Format(errorsList[errorCode], message1, message2, message3, message4);
            }
            var fullMessage = "Ошибка парсера: " + errorMessage;
            var ex          = new StiParserException(fullMessage)
            {
                BaseMessage = errorMessage
            };

            if (token == null)
            {
                throw ex;
            }
            ex.Position = expressionPosition + token.Position;
            ex.Length   = token.Length;
            throw ex;
        }
 internal ParserErrorInfo(ParserErrorCode errorCode, LocalizedString message, TokenInfo errorToken)
 {
     this.ErrorCode  = errorCode;
     this.Message    = message;
     this.ErrorToken = errorToken;
 }
 internal ParserErrorInfo(ParserErrorCode errorCode, TokenInfo errorToken) : this(errorCode, ParserErrorInfo.FormatErrorCode(errorCode), errorToken)
 {
 }
 internal ParserErrorInfo(ParserErrorCode errorCode) : this(errorCode, null)
 {
 }
 private void ThrowError(ParserErrorCode code, string message1)
 {
     ThrowError(code, null, message1, string.Empty, string.Empty, string.Empty);
 }
 // Отображение сообщения о синтаксической ошибке
 private void ThrowError(ParserErrorCode code)
 {
     ThrowError(code, null, string.Empty, string.Empty, string.Empty, string.Empty);
 }
 private void ThrowError(ParserErrorCode code, StiToken token, string message1, string message2, string message3)
 {
     ThrowError(code, token, message1, message2, message3, string.Empty);
 }
 private void ThrowError(ParserErrorCode code, StiToken token)
 {
     ThrowError(code, token, string.Empty, string.Empty, string.Empty, string.Empty);
 }
 private void ThrowError(ParserErrorCode code, string message1, string message2, string message3, string message4)
 {
     ThrowError(code, null, message1, message2, message3, message4);
 }
Beispiel #12
0
        private void ValidatePredicate(Solution solution, LeafCondition leaf, List <ParserErrorInfo> errors, bool postResolving)
        {
            this.ValidatePredicateOperator(solution, leaf, errors);
            TokenInfo       errorToken = (leaf.PropertyTermInfo == null) ? null : new TokenInfo(solution.Tokens[leaf.PropertyTermInfo.FirstToken]);
            PropertyKeyword propertyKeyword;

            if (postResolving)
            {
                if (!AqsParser.PropertyKeywordMap.TryGetValue(leaf.PropertyName, out propertyKeyword))
                {
                    propertyKeyword = PropertyKeyword.All;
                }
            }
            else if (leaf.PropertyTermInfo != null)
            {
                if (!AqsParser.PropertyKeywordMap.TryGetValue(leaf.PropertyName, out propertyKeyword))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidPropertyKey, errorToken));
                    return;
                }
                if (!this.AllowedKeywords.Contains(propertyKeyword))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidPropertyKey, errorToken));
                    return;
                }
            }
            else
            {
                propertyKeyword = PropertyKeyword.All;
                if (leaf.ValueTermInfo == null)
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.UnexpectedToken));
                    return;
                }
            }
            if (!postResolving && leaf.ValueTermInfo == null)
            {
                ParserErrorCode parserErrorCode  = ParserErrorCode.MissingPropertyValue;
                PropertyKeyword propertyKeyword2 = propertyKeyword;
                switch (propertyKeyword2)
                {
                case PropertyKeyword.Sent:
                case PropertyKeyword.Received:
                    parserErrorCode = ParserErrorCode.InvalidDateTimeFormat;
                    break;

                default:
                    if (propertyKeyword2 == PropertyKeyword.Kind)
                    {
                        parserErrorCode = ParserErrorCode.InvalidKindFormat;
                    }
                    break;
                }
                if (parserErrorCode != ParserErrorCode.MissingPropertyValue)
                {
                    int num = leaf.PropertyTermInfo.FirstToken + leaf.PropertyTermInfo.Length + 1;
                    if (leaf.OperationTermInfo != null)
                    {
                        num += leaf.PropertyTermInfo.Length;
                    }
                    if (num < solution.Tokens.Count)
                    {
                        errorToken = new TokenInfo(solution.Tokens[num]);
                    }
                }
                errors.Add(new ParserErrorInfo(parserErrorCode, errorToken));
                return;
            }
            if (leaf.ValueTermInfo != null)
            {
                int firstChar = solution.Tokens[leaf.ValueTermInfo.FirstToken].FirstChar;
                errorToken = new TokenInfo(firstChar, leaf.ValueTermInfo.Text.Length);
            }
            if (propertyKeyword == PropertyKeyword.Kind)
            {
                if (!AqsParser.KindKeywordMap.ContainsKey((string)leaf.Value))
                {
                    errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidKindFormat, errorToken));
                    return;
                }
            }
            else
            {
                if (propertyKeyword == PropertyKeyword.Sent || propertyKeyword == PropertyKeyword.Received)
                {
                    if (postResolving || !(leaf.Value is string[]) || ((string[])leaf.Value).Length != 2)
                    {
                        return;
                    }
                    using (Condition condition = solution.Resolve(leaf, 0, (DateTime)ExDateTime.Now))
                    {
                        LeafCondition leafCondition  = (LeafCondition)((CompoundCondition)condition).Children[0];
                        LeafCondition leafCondition2 = (LeafCondition)((CompoundCondition)condition).Children[1];
                        ExDateTime    t  = (ExDateTime)((DateTime)leafCondition.Value);
                        ExDateTime    t2 = (ExDateTime)((DateTime)leafCondition2.Value);
                        if (t > t2)
                        {
                            errors.Add(new ParserErrorInfo(ParserErrorCode.InvalidDateTimeRange, errorToken));
                        }
                        return;
                    }
                }
                if (postResolving && leaf.Value is string)
                {
                    string text = (string)leaf.Value;
                    if (!AqsParser.ContainsAlphanumericChars(text))
                    {
                        errors.Add(new ParserErrorInfo(ParserErrorCode.UnexpectedToken, errorToken));
                    }
                    int num2 = text.IndexOf('*');
                    if (num2 >= 0)
                    {
                        string s = text.Substring(0, num2);
                        if (!AqsParser.ContainsAlphanumericChars(s))
                        {
                            errors.Add(new ParserErrorInfo(ParserErrorCode.SuffixMatchNotSupported, errorToken));
                        }
                    }
                }
            }
        }