예제 #1
0
        public static CKey Build(string inRootName, List <CTokenLine> inLines, ITreeBuildSupport inSupport)
        {
            var root = CKey.CreateRoot(inRootName);

            CBuildCommands commands = new CBuildCommands(inSupport.GetLogger());

            SCollectResult collect_res = Collect(root, -1, inLines, 0, inSupport, commands);

            if (!collect_res.WasRecordDivider)
            {
                root.CheckOnOneArray();
            }

            //if(root.ValuesCount == 0 && root.KeyCount == 1 && string.IsNullOrEmpty(root.Name))
            //{
            //    CKey k = root.GetKey(0);
            //    k.SetParent(null);
            //    root = k;
            //}

            return(root);
        }
예제 #2
0
        static SCollectResult Collect(CKey inParent, int inParentRank, List <CTokenLine> inLines, int inStartIndex, ITreeBuildSupport inSupport, CBuildCommands inCommands)
        {
            SAddLineResult current_state = new SAddLineResult();

            int curr_rank = inParentRank + 1;

            bool rec_divider_was = false;

            int i = inStartIndex;

            while (i < inLines.Count)
            {
                int        t    = i;
                CTokenLine line = inLines[i];
                if (!line.IsEmpty() || line.Comments != null)
                {
                    if (line.Rank < curr_rank)
                    {
                        OnClosingKey(current_state.last_record_key, current_state.last_key_add_mode, inSupport);
                        return(new SCollectResult
                        {
                            CurrentLineIndex = i,
                            WasRecordDivider = rec_divider_was
                        });
                    }
                    else if (line.Rank > curr_rank)
                    {
                        if (current_state.last_record_key == null)
                        {
                            current_state.last_record_key = CreateNewArrayKey(inParent, line, inCommands);
                        }

                        SCollectResult collect_res = Collect(current_state.last_record_key, curr_rank, inLines, i, inSupport, inCommands);
                        if (!collect_res.WasRecordDivider)
                        {
                            current_state.last_record_key.CheckOnOneArray();
                        }
                        i = collect_res.CurrentLineIndex;
                    }
                    else
                    {
                        OnClosingKey(current_state.last_record_key, current_state.last_key_add_mode, inSupport);
                        current_state = AddLine(inParent, current_state.current_array_key, line, inSupport, inCommands);

                        if (current_state.WasRecordDivider)
                        {
                            rec_divider_was = true;
                        }
                    }
                }

                if (t == i)
                {
                    i++;
                }
            }

            //if (!rec_divider_was && current_state.current_array_key != null)
            //    current_state.current_array_key.CheckOnOneArray();

            OnClosingKey(current_state.last_record_key, current_state.last_key_add_mode, inSupport);

            return(new SCollectResult
            {
                CurrentLineIndex = i,
                WasRecordDivider = rec_divider_was
            });
        }