public Expression GetNode(ExpressionParser parser)
        {
            var        collection = parser.Collection;
            Lexem      lex        = parser.Collection.CurrentLexem();
            bool       uniar      = parser.waitValue;
            Expression res        = null;

            if (lex.LexemType == LexType.Arfimetic)
            {
                switch (lex.LexemText)
                {
                case "+":
                    if (uniar)
                    {
                        res = new UniarPlus_BoolExpr();
                    }
                    else
                    {
                        res = new Plus_Arifmetic();
                    }
                    break;

                case "-":
                    if (uniar)
                    {
                        res = new UniarMinus_BoolExpr();
                    }
                    else
                    {
                        res = new Minus_Arifmetic();
                    }
                    break;

                case "*":
                    if (uniar)
                    {
                        res = new AllColumnExpr();
                    }
                    else
                    {
                        res = new Multi_Arifmetic();
                    }
                    break;

                case "/":
                    res = new Div_Arifmetic();
                    break;

                case "<":
                    res = new Less_CompExpr();
                    break;

                case "<=":
                    res = new LessOrEqual_CompExpr();
                    break;

                case ">=":
                    res = new GreatOrEqual_CompExpr();
                    break;

                case ">":
                    res = new Great_CompExpr();
                    break;

                case "=":
                    res = new Equal_CompExpr();
                    break;

                case "<>":
                case "!=":
                    res = new NotEqual_CompExpr();
                    break;
                }
            }
            if (lex.LexemType == LexType.Number)
            {
                res = new ConstExpr();
                if (lex.LexemText.Contains('.'))
                {
                    (res as ConstExpr).Init(lex.LexemText.ParseDouble(), SimpleTypes.Float);
                }
                else
                {
                    (res as ConstExpr).Init(long.Parse(lex.LexemText), SimpleTypes.Integer);
                }
            }
            if (lex.LexemType == LexType.Text)
            {
                if (lex.LexemText.StartsWith("'"))
                {
                    res = new ConstExpr();
                    (res as ConstExpr).Init(ParserUtils.StandartDecodeEscape(lex.LexemText), SimpleTypes.String);
                }
            }
            if (lex.LexemType == LexType.Command)
            {
                switch (lex.LexemText.ToLower())
                {
                case "not":
                    res = new Not_BoolExpr();
                    break;

                case "and":
                    res = new And_BoolExpr();
                    break;

                case "or":
                    res = new Or_BoolExpr();
                    break;

                case "true":
                    res = new ConstExpr();
                    (res as ConstExpr).Init(true, SimpleTypes.Boolean);
                    break;

                case "false":
                    res = new ConstExpr();
                    (res as ConstExpr).Init(false, SimpleTypes.Boolean);
                    break;

                case "date":
                    if (collection.GetNext() != null)
                    {
                        var c = collection.GetNext();
                        if (c.LexemType == LexType.Text && c.LexemText.StartsWith("'"))
                        {
                            res = new ConstExpr();
                            string s  = ParserUtils.StandartDecodeEscape(c.LexemText);
                            var    dt = CommonUtils.ParseDateTime(s);
                            if (dt != null)
                            {
                                collection.GotoNext();
                                ((ConstExpr)res).Init(dt.Value, SimpleTypes.Date);
                            }
                            else
                            {
                                collection.Error("Can not parse date lexem", lex);
                            }
                        }
                    }
                    break;

                case "datetime":
                case "timestamp":
                    if (collection.GetNext() != null)
                    {
                        var c = collection.GetNext();
                        if (c.LexemType == LexType.Text && c.LexemText.StartsWith("'"))
                        {
                            res = new ConstExpr();
                            string s  = ParserUtils.StandartDecodeEscape(c.LexemText);
                            var    dt = CommonUtils.ParseDateTime(s);
                            if (dt != null)
                            {
                                collection.GotoNext();
                                ((ConstExpr)res).Init(dt.Value, SimpleTypes.DateTime);
                            }
                            else
                            {
                                collection.Error("Can not parse datetime lexem", lex);
                            }
                        }
                    }
                    break;

                case "time":
                    if (collection.GetNext() != null)
                    {
                        var c = collection.GetNext();
                        if (c.LexemType == LexType.Text && c.LexemText.StartsWith("'"))
                        {
                            res = new ConstExpr();
                            string   s = ParserUtils.StandartDecodeEscape(c.LexemText);
                            DateTime dt;
                            var      r = CommonUtils.ParseDateTime(s, out dt);
                            if (r == ParserDateTimeStatus.Time)
                            {
                                collection.GotoNext();
                                ((ConstExpr)res).Init(dt.TimeOfDay, SimpleTypes.Time);
                            }
                            else
                            {
                                collection.Error("Can not parse time lexem", lex);
                            }
                        }
                    }
                    break;
                }
            }
            return(res);
        }
示例#2
0
        public Expression GetNode(ExpressionParser parser)
        {
            Lexem      lex   = parser.Collection.CurrentLexem();
            Expression ex    = null;
            bool       uniar = parser.waitValue;

            if (lex.LexemType == LexType.Arfimetic)
            {
                switch (lex.LexemText)
                {
                case "+":
                    if (uniar)
                    {
                        ex = new UniarPlus_BoolExpr();
                    }
                    else
                    {
                        ex = new Plus_Arifmetic();
                    }
                    break;

                case "-":
                    if (uniar)
                    {
                        ex = new UniarMinus_BoolExpr();
                    }
                    else
                    {
                        ex = new Minus_Arifmetic();
                    }
                    break;

                case "*":
                    if (uniar)
                    {
                        ex = new AllColumnExpr();
                    }
                    else
                    {
                        ex = new Multi_Arifmetic();
                    }
                    break;

                case "/":
                    ex = new Div_Arifmetic();
                    break;

                case "<":
                    ex = new Less_CompExpr();
                    break;

                case "<=":
                    ex = new LessOrEqual_CompExpr();
                    break;

                case ">=":
                    ex = new GreatOrEqual_CompExpr();
                    break;

                case ">":
                    ex = new Great_CompExpr();
                    break;

                case "=":
                    ex = new Equal_CompExpr();
                    break;

                case "<>":
                case "!=":
                    ex = new NotEqual_CompExpr();
                    break;
                }
            }
            if (lex.LexemType == LexType.Number)
            {
                ex = new ConstExpr();
                if (lex.LexemText.Contains('.'))
                {
                    (ex as ConstExpr).Init(lex.LexemText.ParseDouble(), SimpleTypes.Float);
                }
                else
                {
                    (ex as ConstExpr).Init(long.Parse(lex.LexemText), SimpleTypes.Integer);
                }
            }
            if (lex.LexemType == LexType.Text)
            {
                if (lex.LexemText.StartsWith("'"))
                {
                    ex = new ConstExpr();
                    (ex as ConstExpr).Init(ParserUtils.StandartDecodeEscape(lex.LexemText), SimpleTypes.String);
                }
            }
            Lexem n1;

            if (lex.LexemType == LexType.Command)
            {
                switch (lex.LexemText.ToLower())
                {
                case "not":
                    n1 = parser.Collection.GetNext();
                    if (n1 != null && n1.LexemType == LexType.Command && n1.LexemText.ToLower() == "in")
                    {
                        ex = new NotInExpr();
                        parser.Collection.GotoNext();
                        break;
                    }
                    ex = new Not_BoolExpr();
                    break;

                case "case":
                    ex = new CaseExpr();
                    break;

                case "contains":
                    ex = new Contains();
                    break;

                case "containsic":     //ic = ignore case
                case "containscase":
                    ex = new ContainsIgnoreCase();
                    break;

                case "startwith":
                case "startswith":
                    ex = new StartsWith();
                    break;

                case "endwith":
                case "endswith":
                    ex = new EndsWith();
                    break;
                }
                if (parser.Collection.GetNext() != null && parser.Collection.GetNext().IsSkobraOpen())
                {
                    switch (lex.LexemText.ToLower())
                    {
                    case "cast":
                        ex = new Cast();
                        break;

                    case "in":
                        ex = new InExpr();
                        break;

                    case "abs":
                        ex = new Abs();
                        break;

                    case "substring":
                        ex = new SubString();
                        break;

                    case "position":
                        ex = new Position();
                        break;

                    case "ltrim":
                        ex = new LTrim();
                        break;

                    case "rtrim":
                        ex = new RTrim();
                        break;

                    case "trim":
                        ex = new Trim();
                        break;

                    case "length":
                        ex = new Length();
                        break;

                    case "upper":
                        ex = new Upper_operation();
                        break;

                    case "lower":
                        ex = new Lower_operation();
                        break;

                    case "left":
                        ex = new Left();
                        break;

                    case "right":
                        ex = new Right();
                        break;

                    case "replace":
                        ex = new Replace();
                        break;

                    case "now":
                        ex = new Now();
                        break;

                    case "tostr":
                        ex = new ToString();
                        break;

                    case "strtotime":
                        ex = new StrToTime();
                        break;

                    case "strtodatetime":
                        ex = new StrToDateTime();
                        break;

                    case "addseconds":
                        ex = new AddSeconds();
                        break;

                    case "addminutes":
                        ex = new AddMinutes();
                        break;

                    case "addhours":
                        ex = new AddHours();
                        break;

                    case "adddays":
                        ex = new AddDays();
                        break;

                    case "day":
                        ex = new Day();
                        break;

                    case "month":
                        ex = new Month();
                        break;

                    case "year":
                        ex = new Year();
                        break;

                    case "round":
                        ex = new ParserCore.Expr.Extend.Math.Round();
                        break;

                    case "ceiling":
                        ex = new ParserCore.Expr.Extend.Math.Ceiling();
                        break;

                    case "floor":
                        ex = new ParserCore.Expr.Extend.Math.Floor();
                        break;

                    case "pi":
                        ex = new ParserCore.Expr.Extend.Math.Pi();
                        break;

                    case "tan":
                        ex = new ParserCore.Expr.Extend.Math.Tan();
                        break;

                    case "log":
                        ex = new ParserCore.Expr.Extend.Math.Log();
                        break;
                    }
                }
            }
            return(ex);
        }