Exemple #1
0
        private static IExpression ParseInFirstValueState(TokenConsumer tokenConsumer)
        {
            var valueToken = tokenConsumer.EatToken <ValueToken>();

            if (!tokenConsumer.HasNextToken)
            {
                return(new ExistsExpression(valueToken.Value));
            }

            var secondToken = tokenConsumer.PeekToken();

            switch (secondToken.TokenType)
            {
            case TokenType.Equal:
                return(ParseEqualExpression(tokenConsumer, valueToken));

            case TokenType.ExclamationEqual:
                return(ParseNotEqualExpression(tokenConsumer, valueToken));

            case TokenType.In:
                return(ParseInExpression(tokenConsumer, valueToken));

            case TokenType.NotIn:
                return(ParseNotInExpression(tokenConsumer, valueToken));

            case TokenType.Comma:
                tokenConsumer.EatToken(TokenType.Comma);
                return(new ExistsExpression(valueToken.Value));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        private static IExpression ParseNotExistsExpression(TokenConsumer tokenConsumer)
        {
            tokenConsumer.EatToken(TokenType.Exclamation);
            var valueToken = tokenConsumer.EatToken <ValueToken>();

            return(new NotExistsExpression(valueToken.Value));
        }
Exemple #3
0
        private static NotEqualExpression ParseNotEqualExpression(TokenConsumer tokenConsumer, ValueToken keyToken)
        {
            tokenConsumer.EatToken <ExclamationEqualToken>();
            var valueToken = tokenConsumer.EatToken <ValueToken>();

            return(new NotEqualExpression(
                       keyToken.Value,
                       valueToken.Value));
        }
Exemple #4
0
        private static IEnumerable <IExpression> Parse(TokenConsumer tokenConsumer)
        {
            while (tokenConsumer.HasToken)
            {
                var firstToken = tokenConsumer.PeekToken();

                switch (firstToken.TokenType)
                {
                case TokenType.Value:
                    yield return(ParseInFirstValueState(tokenConsumer));

                    break;

                case TokenType.Exclamation:
                    yield return(ParseNotExistsExpression(tokenConsumer));

                    break;

                case TokenType.Comma:
                    tokenConsumer.EatToken(TokenType.Comma);
                    break;

                default:
                    throw new Exception($"Not expected token {firstToken.TokenType}");
                }
            }
        }
Exemple #5
0
        private static NotInExpression ParseNotInExpression(TokenConsumer tokenConsumer, ValueToken valueToken)
        {
            tokenConsumer.EatToken(TokenType.NotIn);

            var arraySyntax = ParseArraySyntax(tokenConsumer);

            return(new NotInExpression(
                       valueToken.Value,
                       arraySyntax.Values.Select(value => value.Value)));
        }
Exemple #6
0
        private static ArraySyntax ParseArraySyntax(TokenConsumer tokenConsumer)
        {
            tokenConsumer.EatToken(TokenType.OpenParentheses);

            var valueTokens = new List <ValueToken>();

            while (true)
            {
                var valueToken = tokenConsumer.EatToken <ValueToken>();
                valueTokens.Add(valueToken);

                if (tokenConsumer.PeekToken().TokenType == TokenType.CloseParentheses)
                {
                    break;
                }

                tokenConsumer.EatToken(TokenType.Comma);
            }

            tokenConsumer.EatToken(TokenType.CloseParentheses);

            return(new ArraySyntax(valueTokens));
        }