static CKey ExecuteCommand(CKey inParent, CKey inArrKey, CTokenLine line, ITreeBuildSupport inSupport, CBuildCommands inCommands) { CKey arr_key = inArrKey; if (line.Command == ECommands.Name) { if (line.CommandParams.Length < 1) { inSupport.GetLogger().LogError(EErrorCode.EmptyCommand, line); } else { inCommands.SetNextArrayKeyName(line.CommandParams[0], line.Position.Line, inParent); } } else if (line.Command == ECommands.Insert) { if (arr_key == null) { arr_key = CreateNewArrayKey(inParent, line, inCommands); } ExecuteCommand_Insert(arr_key, line, inSupport); } else if (line.Command == ECommands.Delete) { if (arr_key != null) { ExecuteCommand_Delete(arr_key, line, inSupport); } } else if (line.Command == ECommands.ChangeValue) { if (arr_key != null) { arr_key.ChangeValues(line.CommandParams.GetDictionary()); } } return(arr_key); }
//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); }