예제 #1
0
            /// <summary>
            /// faild parse return null, otherwise return DataBindIfExpress
            /// </summary>
            /// <param name="express"></param>
            /// <returns></returns>
            public static IfDataBindExpress Parse(string express)
            {
                var ifExp = new IfDataBindExpress();

                ifExp.express       = express;
                ifExp.objectExpress = ObjectDataBindExpress.Parse(express);
                return(ifExp.objectExpress != null ? ifExp : null);
            }
예제 #2
0
            /// <summary>
            /// fail return null
            /// </summary>
            /// <returns></returns>
            public static AttributeDataBindExpress Parse(string express, string targetName)
            {
                if ("".Equals(targetName))
                {
                    return(null);
                }

                var attributeExpress = new AttributeDataBindExpress();

                attributeExpress.TargetName    = targetName;
                attributeExpress.express       = express;
                attributeExpress.objectExpress = ObjectDataBindExpress.Parse(express);
                return(attributeExpress.objectExpress != null ? attributeExpress : null);
            }
예제 #3
0
 /// <summary>
 /// faild parse return null, otherwise return DataBindObjectExpress
 /// </summary>
 /// <param name="express"></param>
 /// <returns></returns>
 public static ObjectDataBindExpress Parse(string express)
 {
     try
     {
         var dboe = new ObjectDataBindExpress();
         dboe.ast     = new Expr.Parser().Parse(express);
         dboe.express = express;
         return(dboe);
     }
     catch
     {
     }
     return(null);
 }
예제 #4
0
            /// <summary>
            /// faild parse return null, otherwise return DataBindObjectExpress
            /// </summary>
            /// <param name="express"></param>
            /// <returns></returns>
            public static ForDataBindExpress Parse(string express)
            {
                if (express == null)
                {
                    return(null);
                }

                express = express.Trim();
                int index = express.IndexOf(forInToken);

                if (index < 0)
                {
                    return(null);
                }
                var forExp = new ForDataBindExpress();

                forExp.express       = express;
                forExp.IteratorName  = express.Substring(0, index).Trim();
                forExp.objectExpress = ObjectDataBindExpress.Parse(express.Substring(index + 2).Trim());
                return(forExp.objectExpress != null ? forExp : null);
            }
예제 #5
0
            /// <summary>
            /// fail return null
            /// </summary>
            /// <returns></returns>
            public static TextDataBindExpress Parse(string input)
            {
                if (input == null || "".Equals(input))
                {
                    return(null);
                }

                List <RawTextToken> rawList = new List <RawTextToken>();

                for (int i = 0; i < input.Length; i++)
                {
                    var curr = input[i];
                    if (curr == '{' && i + 1 < input.Length && input[i + 1] == '{')
                    {
                        rawList.Add(new RawTextToken(-1, ' '));
                        i++;
                    }
                    else if (curr == '}' && i + 1 < input.Length && input[i + 1] == '}')
                    {
                        rawList.Add(new RawTextToken(1, ' '));
                        i++;
                    }
                    else
                    {
                        rawList.Add(new RawTextToken(0, curr));
                    }
                }

                // RawTextToken to TextToken
                List <TextToken> tokenList = new List <TextToken>();

                for (int i = 0; i < rawList.Count;)
                {
                    if (rawList[i].type == -1)
                    {
                        int startIndex = i + 1;
                        i++;
                        while (i < rawList.Count && rawList[i].type != 1)
                        {
                            i++;
                        }

                        var str = RawTextToken.ToString(rawList, startIndex, i - startIndex);
                        if (i == rawList.Count) // EOF
                        {
                            // normal text
                            tokenList.Add(new TextToken(str));
                            break;
                        }

                        var express = ObjectDataBindExpress.Parse(str);
                        if (express != null)
                        {
                            tokenList.Add(new TextToken(express));
                        }

                        i++;
                    }
                    else
                    {
                        int startIndex = i;
                        while (i < rawList.Count && rawList[i].type != -1)
                        {
                            i++;
                        }
                        int length = i - startIndex;
                        if (length > 0)
                        {
                            var str = RawTextToken.ToString(rawList, startIndex, length);
                            tokenList.Add(new TextToken(str));
                        }
                    }
                }

                return(tokenList.Count > 0 ? new TextDataBindExpress(tokenList) : null);
            }
예제 #6
0
 public TextToken(ObjectDataBindExpress express)
 {
     IsText       = false;
     this.Express = express;
     this.Text    = null;
 }
예제 #7
0
 public TextToken(string text)
 {
     IsText       = true;
     this.Express = null;
     this.Text    = text;
 }