예제 #1
0
 private static bool IsValidStringLexem(LexemV8 lexemV8)
 {
     if (lexemV8 == null)
     {
         return(true);
     }
     return(lexemV8.DoubleQuoteCount % 2 == 0);
 }
예제 #2
0
 private static bool IsValidStringLexem(LexemV8 lexemV8)
 {
     if (lexemV8 == null)
     {
         return true;
     }
     return lexemV8.DoubleQuoteCount % 2 == 0;
 }
예제 #3
0
        public static LexemV8 Parse(string data)
        {
            if (String.IsNullOrEmpty(data))
            {
                return(null);
            }
            Stack <LexemV8> _lexemStack = new Stack <LexemV8>();
            LexemV8         lexemV8     = null;

            for (int i = 0; i < data.Length; i++)
            {
                char ch = data[i];
                if (ch == StartLexem &&
                    IsValidStringLexem(lexemV8))
                {
                    LexemV8 braceLexemV8 = new LexemV8 {
                        LexemType = LexemV8Type.Brace
                    };
                    if (_lexemStack.Count > 0)
                    {
                        LexemV8 parentBrace = _lexemStack.Peek();
                        parentBrace.AddChild(braceLexemV8);
                    }
                    _lexemStack.Push(braceLexemV8);
                }
                else if (ch == DelimiterLexem &&
                         IsValidStringLexem(lexemV8))
                {
                    LexemV8 parentBrace = _lexemStack.Peek();
                    parentBrace.AddChild(lexemV8);
                    lexemV8 = null;
                }
                else if (ch == EndLexem &&
                         IsValidStringLexem(lexemV8))
                {
                    LexemV8 parentBrace = _lexemStack.Pop();
                    parentBrace.AddChild(lexemV8);
                    if (_lexemStack.Count == 0)
                    {
                        lexemV8 = parentBrace;
                    }
                    else
                    {
                        lexemV8 = null;
                    }
                }
                else if (NeedAddChar(lexemV8, ch))
                {
                    if (lexemV8 == null)
                    {
                        lexemV8 = new LexemV8();
                    }
                    lexemV8.AddChar(ch);
                }
            }
            return(lexemV8);
        }
예제 #4
0
 private static bool NeedAddChar(LexemV8 lexemV8, char ch)
 {
     if (lexemV8 == null)
     {
         return(!Char.IsWhiteSpace(ch));
     }
     else
     {
         return(true);
     }
 }
예제 #5
0
 private static bool NeedAddChar(LexemV8 lexemV8, char ch)
 {
     if (lexemV8 == null)
     {
         return !Char.IsWhiteSpace(ch);
     }
     else
     {
          return true;
     }
 }
예제 #6
0
 public static LexemV8 Parse(string data)
 {
     if (String.IsNullOrEmpty(data))
     {
         return null;
     }
     Stack<LexemV8> _lexemStack = new Stack<LexemV8>();
     LexemV8 lexemV8 = null;
     for (int i = 0; i < data.Length; i++)
     {
         char ch = data[i];
         if (ch == StartLexem
             && IsValidStringLexem(lexemV8))
         {
             LexemV8 braceLexemV8 = new LexemV8 { LexemType = LexemV8Type.Brace };
             if (_lexemStack.Count > 0)
             {
                 LexemV8 parentBrace = _lexemStack.Peek();
                 parentBrace.AddChild(braceLexemV8);
             }
             _lexemStack.Push(braceLexemV8);
         }
         else if (ch == DelimiterLexem
             && IsValidStringLexem(lexemV8))
         {
             LexemV8 parentBrace = _lexemStack.Peek();
             parentBrace.AddChild(lexemV8);
             lexemV8 = null;
         }
         else if(ch == EndLexem
             && IsValidStringLexem(lexemV8))
         {
             LexemV8 parentBrace = _lexemStack.Pop();
             parentBrace.AddChild(lexemV8);
             if (_lexemStack.Count == 0)
             {
                 lexemV8 = parentBrace;
             }
             else
             {
                 lexemV8 = null;
             }
         }
         else if (NeedAddChar(lexemV8, ch))
         {
             if (lexemV8 == null)
             {
                 lexemV8 = new LexemV8();
             }
             lexemV8.AddChar(ch);
         }
     }
     return lexemV8;
 }
예제 #7
0
 public void AddChild(LexemV8 child)
 {
     if (child == null)
     {
         return;
     }
     if (_childLexemList == null)
     {
         _childLexemList = new List<LexemV8>();
     }
     _childLexemList.Add(child);
     child.Parent = this;
 }
예제 #8
0
 public void AddChild(LexemV8 child)
 {
     if (child == null)
     {
         return;
     }
     if (_childLexemList == null)
     {
         _childLexemList = new List <LexemV8>();
     }
     _childLexemList.Add(child);
     child.Parent = this;
 }
예제 #9
0
        internal bool TryParseValueFromV8String(Session session, LexemV8 lexem, out object value)
        {
            value = null;
            if (!IsPrimitiveType
                || lexem == null
                || lexem.LexemType != LexemV8Type.Brace
                || lexem.ChildLexemList == null
                || lexem.ChildLexemList.Count != 2)
            {
                return false;
            }
            string dataValue = lexem.ChildLexemList[1].Data.Trim();

            switch (Type)
            {
                case TypeEnum.Boolean:
                    value = !(dataValue == "0");
                    return true;
                case TypeEnum.Date:
                    DateTime dt;
                    if (DateTime.TryParseExact(dataValue, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dt))
                    {
                        value = dt;
                        return true;
                    }
                    break;
                case TypeEnum.String:
                    if (dataValue.StartsWith("\""))
                    {
                        dataValue = dataValue.Remove(0, 1);
                    }
                    if (dataValue.EndsWith("\""))
                    {
                        dataValue = dataValue.Remove(dataValue.Length-1, 1);
                    }
                    value = dataValue;
                    return true;
                case TypeEnum.Decimal:
                    decimal dc;
                    if (decimal.TryParse(dataValue, NumberStyles.Number, CultureInfo.InvariantCulture, out dc))
                    {
                        value = dc;
                        return true;
                    }
                    break;
            }
            return false;
        }