示例#1
0
 public DocBlockEntriesEnumerator(IDocEntry head /*, Func<IDocEntry, bool> predicate*/)
 {
     this.Current = default(T);
     this.Next    = head;
     //_predicate = predicate;
 }
示例#2
0
        /// <summary>
        /// Simple parse of given <paramref name="doccomment"/> into a list of <see cref="IDocEntry"/> instances.
        /// </summary>
        /// <param name="doccomment">Content of the PHPDoc token.</param>
        /// <param name="offset">Start position of <paramref name="doccomment"/> within the source code.</param>
        /// <param name="head">Gets the linked list of entries.</param>
        /// <param name="summary">Gets the documentary comment summary.</param>
        private static bool ParseNoLock(string /*!*/ doccomment, int offset, out IDocEntry head, out string summary)
        {
            head    = null;
            summary = string.Empty;

            if (string.IsNullOrEmpty(doccomment))
            {
                return(false);
            }

            Debug.Assert(doccomment.StartsWith("/**"), "unexpected doc comment prefix");
            Debug.Assert(doccomment.EndsWith("*/"), "unexpected doc comment suffix");

            var            summarybld = StringUtils.GetStringBuilder(); // all the text up to the first phpdoc tag will be accumulated as a summary
            CommonDocEntry current    = null;

            int index = 0;

            while (index < doccomment.Length)
            {
                // consume line
                int eol       = index;
                int linebreak = 0;
                for (; eol < doccomment.Length; eol++)
                {
                    if ((linebreak = TextUtils.LengthOfLineBreak(doccomment, eol)) != 0)
                    {
                        break;
                    }
                }

                // skip the leading witespace and /**
                while (index < eol && (char.IsWhiteSpace(doccomment, index) || doccomment[index] == '*' || (index == 0 && doccomment[index] == '/')))
                {
                    index++;
                }

                // line := [index .. eol + linebreak]
                var line = doccomment.AsSpan(index, eol - index);

                // trim ending
                if (eol >= doccomment.Length - 2 && line.EndsWith("*/".AsSpan()))
                {
                    line = line.Slice(0, line.Length - 2);                                                               // */
                }
                else if (eol >= doccomment.Length - 1 && line.Length != 0 && line[line.Length - 1] == '/')
                {
                    if (line.Length == 1)
                    {
                        break;                   // this was the last line and it was just */
                    }
                    line = line.Slice(0, line.Length - 1);
                }
                line = line.TrimEnd(); // whitespaces

                //
                if (line.Length != 0 && line[0] == '@') // phpdoc tag
                {
                    // create new entry
                    var entry = new CommonDocEntry()
                    {
                        Span    = Span.FromBounds(offset + index, offset + index + line.Length),
                        Next    = null,
                        Content = line.ToString(),
                    };

                    // update linked list
                    if (current != null)
                    {
                        current.Next = entry;
                    }
                    else
                    {
                        head = entry;
                    }

                    current = entry;
                }
                else if (current != null)
                {
                    // append to the current
                    current.Span    = Span.FromBounds(current.Span.Start, offset + index + line.Length);
                    current.Content = current.Content + Environment.NewLine + line.ToString();
                }
                else
                {
                    // append to the summry
                    if (summarybld.Length != 0)
                    {
                        summarybld.AppendLine();
                    }

                    if (summarybld.Length != 0 || line.Length != 0)
                    {
                        summarybld.AppendSpan(line);
                    }
                }

                //
                index = eol + linebreak;
            }

            //
            summary = StringUtils.ReturnStringBuilder(summarybld);

            return(true);
        }