Ejemplo n.º 1
0
        public void TokenizerEOFTest()
        {
            var tokenizer = new ConditionTokenizer(string.Empty);

            tokenizer.GetNextToken();
        }
        public static TriggerState GetConditionTriggerState(
            string expression,
            char typedChar, out int triggerLength, out ExpressionNode triggerExpression,
            out IReadOnlyList <ExpressionNode> comparandValues
            )
        {
            triggerLength     = 0;
            triggerExpression = null;
            comparandValues   = null;

            if (expression.Length == 0 || (expression.Length == 0 && expression[0] == '\''))
            {
                triggerExpression = new ExpressionText(0, "", true);
                return(TriggerState.Value);
            }

            if (expression.Length == 1)
            {
                triggerExpression = new ExpressionText(0, expression, true);
                triggerLength     = 1;
                return(TriggerState.Value);
            }

            var tokens    = new List <Token> ();
            var tokenizer = new ConditionTokenizer();

            tokenizer.Tokenize(expression);

            int lastExpressionStart = 0;

            while (tokenizer.Token.Type != TokenType.EOF)
            {
                switch (tokenizer.Token.Type)
                {
                case TokenType.And:
                case TokenType.Or:
                    lastExpressionStart = tokenizer.Token.Position + tokenizer.Token.Value.Length;
                    break;
                }
                tokens.Add(tokenizer.Token);
                tokenizer.GetNextToken();
            }

            int last = tokens.Count - 1;

            if (last >= 2 && TokenIsCondition(tokens[last - 1].Type))
            {
                var lt = tokens[last];
                if (lt.Type == TokenType.Apostrophe || (lt.Type == TokenType.String && (expression[lt.Position + lt.Value.Length] != '\'')))
                {
                    lastExpressionStart = lt.Position;
                    comparandValues     = ReadPrecedingComparandVariables(tokens, last - 2);
                }
                else
                {
                    triggerLength     = 0;
                    triggerExpression = null;
                    return(TriggerState.None);
                }
            }

            var subexpr = expression.Substring(lastExpressionStart);

            return(GetTriggerState(subexpr, typedChar, out triggerLength, out triggerExpression, out _));
        }
Ejemplo n.º 3
0
        public void TokenizerEOFTest()
        {
            var tokenizer = new ConditionTokenizer(new SimpleStringReader(string.Empty));

            Assert.Throws <ConditionParseException>(() => tokenizer.GetNextToken());
        }
Ejemplo n.º 4
0
        public void TokenizerEOFTest()
        {
            var tokenizer = new ConditionTokenizer(new SimpleStringReader(string.Empty));

            tokenizer.GetNextToken();
        }