Tup.Cobar4Net.Parser.Recognizer.Mysql.Syntax.MySqlExprParser.CaseWhenExpression C# (CSharp) Method

CaseWhenExpression() private method

first CASE has been consumed
private CaseWhenExpression ( ) : IExpression
return IExpression
        private IExpression CaseWhenExpression()
        {
            IExpression comparee = null;
            if (lexer.Token() != MySqlToken.KwWhen)
            {
                comparee = Expression();
            }
            IList<Pair<IExpression, IExpression>> list = new List<Pair<IExpression, IExpression>>();
            for (; lexer.Token() == MySqlToken.KwWhen;)
            {
                lexer.NextToken();
                var when = Expression();
                Match(MySqlToken.KwThen);
                var then = Expression();
                if (when == null || then == null)
                {
                    throw Err("when or then is null in CASE WHEN expression");
                }
                list.Add(new Pair<IExpression, IExpression>(when, then));
            }
            if (list.IsEmpty())
            {
                throw Err("at least one WHEN ... THEN branch for CASE ... WHEN syntax");
            }
            IExpression elseValue = null;
            switch (lexer.Token())
            {
                case MySqlToken.KwElse:
                {
                    lexer.NextToken();
                    elseValue = Expression();
                    goto default;
                }

                default:
                {
                    MatchIdentifier("END");
                    break;
                }
            }
            return new CaseWhenOperatorExpression(comparee, list, elseValue).SetCacheEvalRst(
                cacheEvalRst);
        }