コード例 #1
0
        private static bool TryTakeOperator(TokenKeeper tokenKeeper, out Token op)
        {
            if (tokenKeeper.Next.IsOperator())
            {
                op = tokenKeeper.Take();
                return(true);
            }

            op = new Token(TokenType.Error, null);
            return(false);
        }
コード例 #2
0
        private static bool TryTakeData(TokenKeeper tokenKeeper, out Token data)
        {
            if (tokenKeeper.Next.IsData())
            {
                data = tokenKeeper.Take();
                return(true);
            }

            data = new Token(TokenType.Error, null);
            return(false);
        }
コード例 #3
0
        public void Swap(TokenKeeper tokenKeeper)
        {
            var oldTokens = _tokens;

            _tokens = tokenKeeper._tokens;

            var oldIndex = _index;

            _index = tokenKeeper._index;

            tokenKeeper._tokens = oldTokens;
            tokenKeeper._index  = oldIndex;
        }
コード例 #4
0
        private static FilterClause TakeClause(TokenKeeper tokenKeeper)
        {
            FilterClause clause;

            if (TryTakeExpression(tokenKeeper, out clause))
            {
                if (tokenKeeper.Finished || TryTakeRelOp(tokenKeeper, ref clause))
                {
                    return(clause);
                }
            }

            return(new ErrorClause("Unable to parse filter string."));
        }
コード例 #5
0
        private static bool TryTakeExpression(TokenKeeper tokenKeeper, out FilterClause clause)
        {
            if (TryTakeParenExpression(tokenKeeper, out clause) ||
                TryTakeComparison(tokenKeeper, out clause))
            {
                var work = new TokenKeeper(tokenKeeper);
                if (TryTakeRelOp(work, ref clause))
                {
                    tokenKeeper.Swap(work);
                }
                return(true);
            }

            clause = null;
            return(false);
        }
コード例 #6
0
        private static FilterClause PerformParse(IEnumerable <Token> tokens, out string error)
        {
            var tokenKeeper = new TokenKeeper(tokens.ToList());
            var clause      = TakeClause(tokenKeeper);

            if (clause is ErrorClause errorClause)
            {
                error = errorClause.Error;
            }
            else
            {
                error = null;
            }

            return(clause);
        }
コード例 #7
0
        private static bool TryTakeComparison(TokenKeeper tokenKeeper, out FilterClause clause)
        {
            Token left, right, op;
            var   work = new TokenKeeper(tokenKeeper);

            if (TryTakeData(work, out left) && TryTakeOperator(work, out op) &&
                TryTakeData(work, out right))
            {
                tokenKeeper.Swap(work);
                clause = new ComparisonClause(left, op, right);
                return(true);
            }

            clause = null;
            return(false);
        }
コード例 #8
0
        private static bool TryTakeRelOp(TokenKeeper tokenKeeper, ref FilterClause clause)
        {
            if (tokenKeeper.Next.IsRelop())
            {
                var work = new TokenKeeper(tokenKeeper);
                var op   = work.Take();

                FilterClause rhs;
                if (TryTakeExpression(work, out rhs))
                {
                    var relOpClause = new RelOpClause(clause, op, rhs);
                    tokenKeeper.Swap(work);
                    clause = relOpClause;
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
        private static bool TryTakeParenExpression(TokenKeeper tokenKeeper, out FilterClause clause)
        {
            if (tokenKeeper.Next.TokenType == TokenType.OpenParen)
            {
                var work = new TokenKeeper(tokenKeeper);
                work.Take();
                FilterClause expression;
                if (TryTakeExpression(work, out expression) && work.Next.TokenType == TokenType.CloseParen)
                {
                    work.Take();
                    clause = new ParenClause(expression);
                    tokenKeeper.Swap(work);
                    return(true);
                }
            }

            clause = null;
            return(false);
        }
コード例 #10
0
 public TokenKeeper(TokenKeeper tokenKeeper)
 {
     _tokens = tokenKeeper._tokens;
     _index  = tokenKeeper._index;
 }