Condition method invocation expression (represented by method(p1,p2,p3) syntax).
Inheritance: NLog.Conditions.ConditionExpression
示例#1
0
        private ConditionExpression ParseLiteralExpression()
        {
            if (tokenizer.IsToken(ConditionTokenType.LeftParen))
            {
                tokenizer.GetNextToken();
                ConditionExpression e = ParseExpression();
                tokenizer.Expect(ConditionTokenType.RightParen);
                return(e);
            }
            ;

            if (tokenizer.IsNumber())
            {
                string numberString = (string)tokenizer.TokenValue;
                tokenizer.GetNextToken();
                if (numberString.IndexOf('.') >= 0)
                {
                    return(new ConditionLiteralExpression(Double.Parse(numberString, CultureInfo.InvariantCulture)));
                }
                else
                {
                    return(new ConditionLiteralExpression(Int32.Parse(numberString, CultureInfo.InvariantCulture)));
                }
            }

            if (tokenizer.TokenType == ConditionTokenType.String)
            {
                ConditionExpression e = new ConditionLayoutExpression(tokenizer.StringTokenValue);
                tokenizer.GetNextToken();
                return(e);
            }

            if (tokenizer.TokenType == ConditionTokenType.Keyword)
            {
                string keyword = tokenizer.EatKeyword();

                if (0 == String.Compare(keyword, "level", true))
                {
                    return(new ConditionLevelExpression());
                }

                if (0 == String.Compare(keyword, "logger", true))
                {
                    return(new ConditionLoggerNameExpression());
                }

                if (0 == String.Compare(keyword, "message", true))
                {
                    return(new ConditionMessageExpression());
                }

                if (0 == String.Compare(keyword, "loglevel", true))
                {
                    tokenizer.Expect(ConditionTokenType.Dot);
                    return(new ConditionLiteralExpression(LogLevel.FromString(tokenizer.EatKeyword())));
                }

                if (0 == String.Compare(keyword, "true", true))
                {
                    return(new ConditionLiteralExpression(true));
                }

                if (0 == String.Compare(keyword, "false", true))
                {
                    return(new ConditionLiteralExpression(false));
                }

                if (tokenizer.TokenType == ConditionTokenType.LeftParen)
                {
                    tokenizer.GetNextToken();

                    ConditionMethodExpression predicateExpression = ParsePredicate(keyword);
                    return(predicateExpression);
                }
            }

            throw new ConditionParseException("Unexpected token: " + tokenizer.TokenValue);
        }
示例#2
0
        private ConditionExpression ParseLiteralExpression()
        {
            if (this.tokenizer.IsToken(ConditionTokenType.LeftParen))
            {
                this.tokenizer.GetNextToken();
                ConditionExpression e = this.ParseExpression();
                this.tokenizer.Expect(ConditionTokenType.RightParen);
                return(e);
            }

            if (this.tokenizer.IsToken(ConditionTokenType.Minus))
            {
                this.tokenizer.GetNextToken();
                if (!this.tokenizer.IsNumber())
                {
                    throw new ConditionParseException("Number expected, got " + this.tokenizer.TokenType);
                }

                string numberString = this.tokenizer.TokenValue;
                this.tokenizer.GetNextToken();
                if (numberString.IndexOf('.') >= 0)
                {
                    return(new ConditionLiteralExpression(-double.Parse(numberString, CultureInfo.InvariantCulture)));
                }

                return(new ConditionLiteralExpression(-int.Parse(numberString, CultureInfo.InvariantCulture)));
            }

            if (this.tokenizer.IsNumber())
            {
                string numberString = this.tokenizer.TokenValue;
                this.tokenizer.GetNextToken();
                if (numberString.IndexOf('.') >= 0)
                {
                    return(new ConditionLiteralExpression(double.Parse(numberString, CultureInfo.InvariantCulture)));
                }

                return(new ConditionLiteralExpression(int.Parse(numberString, CultureInfo.InvariantCulture)));
            }

            if (this.tokenizer.TokenType == ConditionTokenType.String)
            {
                ConditionExpression e = new ConditionLayoutExpression(Layout.FromString(this.tokenizer.StringTokenValue, this.configurationItemFactory));
                this.tokenizer.GetNextToken();
                return(e);
            }

            if (this.tokenizer.TokenType == ConditionTokenType.Keyword)
            {
                string keyword = this.tokenizer.EatKeyword();

                if (0 == string.Compare(keyword, "level", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionLevelExpression());
                }

                if (0 == string.Compare(keyword, "logger", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionLoggerNameExpression());
                }

                if (0 == string.Compare(keyword, "message", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionMessageExpression());
                }

                if (0 == string.Compare(keyword, "loglevel", StringComparison.OrdinalIgnoreCase))
                {
                    this.tokenizer.Expect(ConditionTokenType.Dot);
                    return(new ConditionLiteralExpression(LogLevel.FromString(this.tokenizer.EatKeyword())));
                }

                if (0 == string.Compare(keyword, "true", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionLiteralExpression(true));
                }

                if (0 == string.Compare(keyword, "false", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionLiteralExpression(false));
                }

                if (0 == string.Compare(keyword, "null", StringComparison.OrdinalIgnoreCase))
                {
                    return(new ConditionLiteralExpression(null));
                }

                if (this.tokenizer.TokenType == ConditionTokenType.LeftParen)
                {
                    this.tokenizer.GetNextToken();

                    ConditionMethodExpression predicateExpression = this.ParsePredicate(keyword);
                    return(predicateExpression);
                }
            }

            throw new ConditionParseException("Unexpected token: " + this.tokenizer.TokenValue);
        }