static SAddLineResult AddLine(CKey inParent, CKey inCurrentArrayKey, CTokenLine line, ITreeBuildSupport inSupport, CBuildCommands inCommands) { SAddLineResult result = new SAddLineResult(); if (line.IsEmpty()) { if (line.Comments != null) { inCommands.SetNextLineComment(line.Comments.Text, line.Position.Line, inParent); } result.current_array_key = inCurrentArrayKey; } else if (line.IsRecordDivider()) { result.current_array_key = null; result.WasRecordDivider = true; } else if (line.IsCommandLine()) { result.current_array_key = ExecuteCommand(inParent, inCurrentArrayKey, line, inSupport, inCommands); } else if (line.Head != null) { result.current_array_key = inCurrentArrayKey; if (result.current_array_key == null) { result.current_array_key = CreateNewArrayKey(inParent, line, inCommands); } if (line.AdditionMode == EKeyAddingMode.AddUnique && result.current_array_key.IsKeyWithNamePresent(line.Head.Text)) { inSupport.GetLogger().LogError(EErrorCode.ElementWithNameAlreadyPresent, line); } result.last_key_add_mode = line.AdditionMode; result.last_record_key = CKey.Create(result.current_array_key, line, inSupport.GetLogger()); if (inCommands.IsNextLineCommentPresent) { result.last_record_key.AddComments(inCommands.PopNextLineComments(inParent)); } } else if (!line.IsTailEmpty) { //if (!line.IsNewArrayLine && line.TailLength == 1 && !inParent.IsArray) // inParent.AddTokenTail(line, true, inSupport.GetLogger()); //else { result.current_array_key = CreateNewArrayKey(inParent, line, inCommands); result.current_array_key.AddTokenTail(line, inSupport.GetLogger()); } } return(result); }
//inStartLine - next of parent line static void Collect(CKey inParent, int inParentRank, int inStartLine, int inEndLine, List <CTokenLine> inLines, ITreeBuildSupport inSupport, CKey inRoot, EKeyAddingMode inKeyAddingMode) { CBuildCommands command_for_next_string = null; int start = inStartLine; do { int old_start = start; CTokenLine line = inLines[start]; if (line.IsCommandLine()) { if (line.Command == ECommands.Name) { if (line.CommandParams.Length < 1) { inSupport.GetLogger().LogError(EErrorCode.EmptyCommand, line); } else { if (inParent.IsArray && line.Rank == inParentRank) { if (!inParent.SetName(line.CommandParams[0])) { inSupport.GetLogger().LogError(EErrorCode.DublicateKeyName, line); } } else { //inSupport.GetLogger().LogError(EErrorCode.NextArrayKeyNameMissParent, line); if (command_for_next_string == null) { command_for_next_string = new CBuildCommands(inSupport.GetLogger()); } command_for_next_string.SetNextArrayKeyName(line.CommandParams[0], line.Position.Line, inParent); } } } else if (line.Command == ECommands.Insert) { ExecuteCommand_Insert(inParent, line, inSupport, inRoot); } else if (line.Command == ECommands.Delete) { ExecuteCommand_Delete(inParent, line, inSupport); } else if (line.Command == ECommands.ChangeValue) { inParent.ChangeValues(line.CommandParams.GetDictionary()); } } else if (line.IsEmpty() && line.Comments != null) { if (command_for_next_string == null) { command_for_next_string = new CBuildCommands(inSupport.GetLogger()); } command_for_next_string.SetNextLineComment(line.Comments.Text, line.Position.Line, inParent); } else if (!line.IsEmpty()) { EKeyAddingMode adding_mode = inKeyAddingMode; if (adding_mode == EKeyAddingMode.AddUnique && line.AdditionMode != EKeyAddingMode.AddUnique) { adding_mode = line.AdditionMode; } Tuple <CKey, int> new_key_new_line = CreateKey(start, inEndLine, inLines, inSupport, inRoot, inParent, adding_mode); CKey new_key = new_key_new_line.Item1; if (command_for_next_string != null && command_for_next_string.IsNextArrayKeyNamePresent) { if (!new_key.SetName(command_for_next_string.PopNextArrayKeyName(inParent))) { inSupport.GetLogger().LogError(EErrorCode.DublicateKeyName, line); } } if (command_for_next_string != null && command_for_next_string.IsNextLineCommentPresent) { new_key.AddComments(command_for_next_string.PopNextLineComments(inParent)); } //if (!new_key.IsArray && line.AdditionMode == EKeyAddingMode.AddUnique && inParent.IsKeyWithNamePresent(new_key.Name)) // inSupport.GetLogger().LogError(EErrorCode.ElementWithNameAlreadyPresent, inLines[start]); //if(line.AdditionMode == EKeyAddingMode.AddUnique) // new_key.SetParent(inParent); //else if (line.AdditionMode == EKeyAddingMode.Override || line.AdditionMode == EKeyAddingMode.Add) //{ // if (line.AdditionMode == EKeyAddingMode.Override) // { // var pathes = new List<List<string>>(); // new_key.GetTerminalPathes(pathes, new List<string>()); // //for correct deleting array elems // for (int i = pathes.Count - 1; i >= 0; --i) // { // var path = pathes[i]; // RemoveKeysByPath(inParent, path); // } // } // CKey child_key = inParent.FindChildKey(new_key.Name); // if (child_key != null) // child_key.MergeKey(new_key); // else // new_key.SetParent(inParent); //} start = new_key_new_line.Item2; } if (old_start == start) { start++; } }while (start < inEndLine); }