Пример #1
0
        public Data Parse(string source, string content)
        {
            if (string.IsNullOrEmpty(content) || content == DataConvertorConsts.NullStr)
            {
                return(null);
            }

            Stack <Data> dataStack   = new Stack <Data>();
            Data         lastData    = null;
            PartialData  partialData = new PartialData();

            partialData.ValueType = DataType.Data;
            partialData.Key       = "";
            Word lastWord = new Word(source, 0, 0, DataConvertorConsts.ValueBegin);

            WordSplitter.Split(source, content, DataConvertorConsts.WordChars, (Word word) => {
                ProcessWord(dataStack, ref lastData, partialData, lastWord, word);
                lastWord = word;
            });

            if (dataStack.Count == 0 && lastData != null)
            {
                return(lastData);
            }
            else
            {
                throw new WordException(lastWord, "Data Stack Error: {0}, {1}", dataStack.Count, lastData);
            }
        }
Пример #2
0
 public bool TryParse(string source, string content, out Data val, bool isDebug = false)
 {
     try {
         val = Parse(source, content);
         return(true);
     } catch (Exception e) {
         Log.ErrorOrDebug(isDebug, "Parse Failed: <{0}> {1}\n\n{2}\n\n{3}",
                          typeof(Data).FullName,
                          CaretException.GetMessage(source, e),
                          e.StackTrace, WordSplitter.AppendLineNumber(content));
     }
     val = null;
     return(false);
 }