Example #1
0
        static void OnClosingKey(CKey key, EKeyAddingMode inKeyAddMode, ITreeBuildSupport inSupport)
        {
            if (key == null)
            {
                return;
            }

            if (key.IsEmpty)
            {
                inSupport.GetLogger().LogError(EErrorCode.HeadWithoutValues, key);
                return;
            }

            if (inKeyAddMode == EKeyAddingMode.AddUnique)
            {
                return;
            }

            CKey parent = key.Parent;

            if (parent == null)
            {
                inSupport.GetLogger().LogError(EErrorCode.KeyMustHaveParent, key);
                return;
            }

            key.SetParent(null);

            if (inKeyAddMode == EKeyAddingMode.Override)
            {
                var pathes = new List <List <string> >();
                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(parent, path);
                }

                inKeyAddMode = EKeyAddingMode.Add;
            }

            if (inKeyAddMode == EKeyAddingMode.Add)
            {
                CKey child_key = parent.FindChildKey(key.Name);
                if (child_key != null)
                {
                    child_key.MergeKey(key);
                }
                else
                {
                    key.SetParent(parent);
                }
            }
        }
Example #2
0
        static Tuple <CKey, int> CreateKey(int inStartLine, int inEndLine, List <CTokenLine> inLines, ITreeBuildSupport inSupport,
                                           CKey inRoot, CKey inParent, EKeyAddingMode inKeyAddingMode)
        {
            CTokenLine line     = inLines[inStartLine];
            int        key_rank = line.Rank;

            if (line.IsHeadEmpty)
            {
                CKey arr_key = CKey.CreateArrayKey(inParent, line.Position);
                arr_key.AddTokenTail(line, inSupport.GetLogger());
                return(new Tuple <CKey, int>(arr_key, inStartLine + 1));
            }
            else
            {
                CKey key = null;
                if (inKeyAddingMode != EKeyAddingMode.AddUnique)
                {
                    key = inParent.FindChildKey(line.Head.Text);
                    if (key == null)
                    {
                        inSupport.GetLogger().LogError(EErrorCode.CantFindKey, line, $"Key name: {line.Head.Text}");
                    }
                    else
                    {
                        if (inKeyAddingMode == EKeyAddingMode.Override)
                        {
                            key.ClearComments();
                            key.ClearValues();
                        }

                        if (inKeyAddingMode == EKeyAddingMode.Override || inKeyAddingMode == EKeyAddingMode.Add)
                        {
                            key.AddTokenTail(line, inSupport.GetLogger());
                        }
                    }
                }
                else if (inParent.IsKeyWithNamePresent(line.Head.Text))
                {
                    inSupport.GetLogger().LogError(EErrorCode.ElementWithNameAlreadyPresent, line);
                }

                if (key == null)
                {
                    key = CKey.Create(inParent, line, inSupport.GetLogger());
                }

                int last_line = FindNextSameRankLine(inStartLine, inEndLine, key_rank, inLines);

                if (last_line > inStartLine + 1)
                {
                    EKeyAddingMode next_add_mode = inKeyAddingMode;
                    if (next_add_mode == EKeyAddingMode.Add)
                    {
                        next_add_mode = EKeyAddingMode.AddUnique;
                    }

                    CollectByDivs(key, key_rank, inStartLine + 1, last_line, inLines, inSupport, inRoot, next_add_mode);
                }

                if (key.KeyCount == 0 && key.ValuesCount == 0)
                {
                    inSupport.GetLogger().LogError(EErrorCode.HeadWithoutValues, line);
                }

                return(new Tuple <CKey, int>(key, last_line));
            }
        }