private void ProcessValue(Stack <Data> dataStack, ref Data lastData, PartialData partialData, Word lastWord, Word word) { Data data = dataStack.Count > 0 ? dataStack.Peek() : null; if (DataConvertorConsts.IsWordChar(word.Value)) { if (word.Value == DataConvertorConsts.DataBegin) { Data subData = new Data(); dataStack.Push(subData); if (data != null) { data.SetData(partialData.Key, subData); } partialData.Clear(); } else if (word.Value == DataConvertorConsts.DataEnd) { if (partialData.ValueType == DataType.String) { SetSimpleDataValue(data, partialData, new Word(word.Caret, "")); PopDataFromStack(dataStack, ref lastData, word); } else { throw new WordException(word, "Missing Value"); } } else if (lastWord.Value == DataConvertorConsts.ValueBegin || word.Value != DataConvertorConsts.ValueBegin) { throw new WordException(word, "Syntax Error"); } } else if (lastWord.Value == DataConvertorConsts.ValueBegin) { SetSimpleDataValue(data, partialData, word); } else { throw new WordException(word, "Syntax Error"); } }
private void SetSimpleDataValue(Data data, PartialData partialData, Word word) { if (data == null) { throw new WordException(word, "Syntax Error"); } bool ok = false; switch (partialData.ValueType) { case DataType.Bool: ok = data.SetBool(partialData.Key, Convertor.BoolConvertor.Parse(word.Value)); break; case DataType.Int: ok = data.SetInt(partialData.Key, Convertor.IntConvertor.Parse(word.Value)); break; case DataType.Long: ok = data.SetLong(partialData.Key, Convertor.LongConvertor.Parse(word.Value)); break; case DataType.Float: ok = data.SetFloat(partialData.Key, Convertor.FloatConvertor.Parse(word.Value)); break; case DataType.Double: ok = data.SetDouble(partialData.Key, Convertor.DoubleConvertor.Parse(word.Value)); break; case DataType.String: ok = data.SetString(partialData.Key, Convertor.StringConvertor.Parse(word.Value)); break; } if (ok) { partialData.Clear(); } else { throw new WordException(word, "Syntax Error"); } }