private void PushNamespaceSegment(string NamespaceSegment)
            {
                currentSegment = storedSegments.Where(s => s.SegmentName == NamespaceSegment && s.ParentPath == (currentSegment?.SegmentPath ?? "")).FirstOrDefault();

                if (currentSegment == null)
                {
                    currentSegment = new NamespaceSegment(currentSegment?.SegmentPath ?? "", NamespaceSegment);
                    storedSegments.Add(currentSegment);
                }

                segments.Push(currentSegment);
            }
            private void PopNamespaceSegment()
            {
                var segment = segments.Pop();

                if (segments.Count > 0)
                {
                    currentSegment = segments.Peek();
                }
                else
                {
                    currentSegment = null;
                }
            }
            public string ProcessContent()
            {
                storedSegments.Clear();
                storedProcs.Clear();
                segments.Clear();
                procs.Clear();
                currentProc    = null;
                currentSegment = null;

                Match  m;
                string line;

                StringBuilder sb = new StringBuilder();

                using (StringReader sr = new StringReader(content))
                {
                    int cnt = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        cnt++;

                        m = pushReg.Match(line);

                        if (m != null && m.Success && !string.IsNullOrWhiteSpace(m.Groups[1].Value))
                        {
                            PushNamespaceSegment(m.Groups[1].Value);
                            continue;
                        }

                        if (popReg.IsMatch(line))
                        {
                            PopNamespaceSegment();
                            continue;
                        }

                        if (procReg.IsMatch(line))
                        {
                            PushStoreProc(cnt);
                            continue;
                        }

                        if (endProcReg.IsMatch(line))
                        {
                            PopProc();
                            continue;
                        }

                        m = forcedNamespacelabelReg.Match(line);

                        if (m != null && m.Success && !string.IsNullOrWhiteSpace(m.Groups[1].Value))
                        {
                            var pathParts = m.Groups[1].Value.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                            string lastNamespace = pathParts[0];
                            string label         = pathParts.Last();
                            string path          = "." + string.Join(".", pathParts.Skip(1).Take(pathParts.Length - 2)) + ".";

                            if (path == "..")
                            {
                                path = "";
                            }

                            var namespaceSegment = storedSegments.Where(ss => ss.SegmentName == lastNamespace && ss.ParentPath == path).FirstOrDefault();

                            if (namespaceSegment == null)
                            {
                                namespaceSegment = new NamespaceSegment(path, lastNamespace);
                                storedSegments.Add(namespaceSegment);
                            }

                            namespaceSegment.AddLabel(label);
                        }

                        if (currentProc != null)
                        {
                            currentProc.ScanSentence(line);
                        }

                        if (currentSegment != null)
                        {
                            currentSegment.ScanSentence(line, procs);
                        }

                        if (line.Contains("__PRINT_INIT"))
                        {
                            line = line;
                        }
                    }
                }

                segments.Clear();
                procs.Clear();

                using (StringReader sr = new StringReader(content))
                {
                    int cnt = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        cnt++;

                        m = pushReg.Match(line);

                        if (m != null && m.Success && !string.IsNullOrWhiteSpace(m.Groups[1].Value))
                        {
                            PushNamespaceSegment(m.Groups[1].Value);
                            continue;
                        }

                        if (popReg.IsMatch(line))
                        {
                            PopNamespaceSegment();
                            continue;
                        }

                        if (procReg.IsMatch(line))
                        {
                            PushExistingProc(cnt);
                            sb.AppendLine(line);
                            continue;
                        }

                        if (endProcReg.IsMatch(line))
                        {
                            PopProc();
                            sb.AppendLine(line);
                            continue;
                        }

                        if (currentSegment != null)
                        {
                            line = currentSegment.ParseSentence(line, procs);
                        }

                        sb.AppendLine(line);
                    }
                }

                return(sb.ToString());
            }