Exemplo n.º 1
0
        void ParseDocLet(DocLet DocLet)
        {
            DocItem Item = null;

            if (DocLet.Find(Tags.Namespace) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Namespace);
            }
            else if (DocLet.Find(Tags.Class) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Class);
            }
            else if (DocLet.Find(Tags.Interface) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Interface);
            }
            else if (DocLet.Find(Tags.Enum) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Enum);
            }
            else if (DocLet.Find(Tags.Constructor) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Constructor);
            }
            else if (DocLet.Find(Tags.Field) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Field);
            }
            else if (DocLet.Find(Tags.Constant) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Constant);
            }
            else if (DocLet.Find(Tags.Property) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Property);
            }
            else if (DocLet.Find(Tags.Function) != null)
            {
                if (DocLet.Find(Tags.Namespace) == null && DocLet.Find(Tags.Enum) == null)
                {
                    Item = new DocItem(this, DocLet, DocItemType.Function);
                }
            }
            else if (DocLet.Find(Tags.Callback) != null)
            {
                Item = new DocItem(this, DocLet, DocItemType.Callback);
            }


            if (Item != null)
            {
                string Name = Item.Name;
                Global.AddToFlatList(Item);
            }
        }
Exemplo n.º 2
0
        /* construction */
        /// <summary>
        /// Constructor
        /// </summary>
        internal DocItem(Parser Parser, DocLet DocLet, DocItemType ItemType)
        {
            this.Parser   = Parser;
            this.DocLet   = DocLet;
            this.ItemType = ItemType;

            if (DocLet != null)
            {
                this.FilePath       = DocLet.FilePath;
                this.FirstLineIndex = DocLet.FirstLineIndex;
                this.LastLineIndex  = DocLet.LastLineIndex;

                Parse();
                ParseAfter();
            }

            this.DocLet = null;
        }
Exemplo n.º 3
0
        void Parse()
        {
            string BlockText;
            string sName, S, S2;
            bool   IsNameTypeTag;
            int    Index;



            // parse name tags (they are all multi-line)
            foreach (string NameTag in Tags.NameTags)
            {
                BlockText = GetMultiLineTagValue(NameTag);
                if (!string.IsNullOrWhiteSpace(BlockText))
                {
                    sName = string.Empty;
                    if (NameTag == Tags.Constructor)
                    {
                        sName = BlockText.Trim();
                        if (!string.IsNullOrWhiteSpace(sName))
                        {
                            // member of + description
                            Index = sName.IndexOfAny(new char[] { '\r', '\n', ' ' });
                            if (Index == -1)
                            {
                                MemberOf = sName;
                            }
                            else
                            {
                                MemberOf = sName.Substring(0, Index);
                                S        = sName.Remove(0, MemberOf.Length).Trim();

                                if (!string.IsNullOrWhiteSpace(S))
                                {
                                    Description = S.TrimStart(new char[] { ' ', '-' });
                                }
                            }
                        }

                        break;
                    }



                    IsNameTypeTag = Tags.IsNameTypeTag(NameTag);

                    // type
                    if (IsNameTypeTag)
                    {
                        // @tag {Type} [MemberOf]Name [Description]

                        S  = string.Empty;
                        S2 = Sys.ExtractBracketedString(BlockText, out S);

                        IsNameTypeTag = !string.IsNullOrWhiteSpace(S);

                        if (IsNameTypeTag)
                        {
                            if (!string.IsNullOrWhiteSpace(S))
                            {
                                Type = S;
                            }

                            if (!string.IsNullOrWhiteSpace(S2))
                            {
                                sName = S2.Trim();
                            }
                        }
                    }


                    if (!IsNameTypeTag)
                    {
                        // @tag [MemberOf]Name [Description]
                        sName = BlockText.Trim();
                    }



                    // name + description
                    Index = sName.IndexOfAny(new char[] { '\r', '\n', ' ' });
                    if (Index == -1)
                    {
                        Name = sName;
                    }
                    else
                    {
                        Name = sName.Substring(0, Index);
                        S    = sName.Remove(0, Name.Length).Trim();

                        //S = sName.Substring(Index);
                        if (!string.IsNullOrWhiteSpace(S))
                        {
                            Description = S.TrimStart(new char[] { ' ', '-' });
                        }
                    }

                    break;
                }
            }



            // description
            if (string.IsNullOrWhiteSpace(Description))
            {
                Description = GetMultiLineTagValue(Tags.Description);
            }

            if (!string.IsNullOrWhiteSpace(Description))
            {
                string[]      Parts = Description.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                StringBuilder SB    = new StringBuilder();
                foreach (string s in Parts)
                {
                    SB.AppendLine(s.TrimStart(new char[] { ' ', '*' }));
                }
                Description = SB.ToString();
            }

            // name
            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = GetSingleLineTagValue(Tags.Name);
            }

            // name + memberof
            if (!string.IsNullOrWhiteSpace(Name))
            {
                Index = Name.LastIndexOf('.');
                if (Index != -1)
                {
                    S        = Name;
                    Name     = S.Substring(Index + 1);
                    MemberOf = S.Substring(0, Index);
                }
            }

            // memberof
            if (string.IsNullOrWhiteSpace(MemberOf))
            {
                MemberOf = GetSingleLineTagValue(Tags.MemberOf);
            }

            // type
            if (string.IsNullOrWhiteSpace(Type))
            {
                Type = GetSingleLineTagValue(Tags.Type);
            }

            // ensure memberof
            if (string.IsNullOrWhiteSpace(MemberOf))
            {
                if (ItemType == DocItemType.Namespace || ItemType == DocItemType.Callback || ItemType == DocItemType.Interface)
                {
                    MemberOf = "global";
                }
                else
                {
                    MemberOf = Parser.Global.ContextName;
                }
            }

            // default
            Default = GetSingleLineTagValue(Tags.Default);


            if (ItemType == DocItemType.Class || ItemType == DocItemType.Enum)
            {
                // extends
                foreach (string NameTag in Tags.ExtendsTags)
                {
                    if (string.IsNullOrWhiteSpace(Extends))
                    {
                        Extends = GetSingleLineTagValue(NameTag);
                    }
                }

                // events
                Events = GetEvents();

                // implements
                Implements = GetImplements();
            }

            // category
            if (ItemType == DocItemType.Class || this.ItemType == DocItemType.Function)
            {
                Category = GetSingleLineTagValue(Tags.Category);
            }

            // access
            S = GetSingleLineTagValue(Tags.Access);
            if (!string.IsNullOrWhiteSpace(S))
            {
                if (S.IsSameText("private"))
                {
                    Access = Access.Private;
                }
                else if (S.IsSameText("protected"))
                {
                    Access = Access.Protected;
                }
                else if (S.IsSameText("public"))
                {
                    Access = Access.Public;
                }
            }

            // flags
            IsReadOnly   = DocLet.Find(Tags.ReadOnly) != null;
            IsStatic     = DocLet.Find(Tags.Static) != null;
            IsDeprecated = DocLet.Find(Tags.Deprecated) != null;
            IsBitField   = DocLet.Find(Tags.BitField) != null;
            IsFunction   = DocLet.Find(Tags.Function) != null; // when is namespace or enum and has a callable function with the same name
            IsEventArgs  = DocLet.Find(Tags.EventArgs) != null;

            // is function
            IsFunction = (ItemType == DocItemType.Function || ItemType == DocItemType.Constructor || ItemType == DocItemType.Callback) ||
                         ((ItemType == DocItemType.Namespace || ItemType == DocItemType.Enum) && (DocLet.Find(Tags.Function) != null));

            // Params + Return
            if (IsFunction)
            {
                Params = GetParams();
                if (ItemType != DocItemType.Constructor)
                {
                    Return = GetReturn();
                }
            }

            // Throws
            if (IsFunction || ItemType == DocItemType.Property)
            {
                Throws = GetThrows();
            }


            ParseExamples();
            ParseTutorials();
            ParseSee();
        }
Exemplo n.º 4
0
        bool SingleLineTagExists(string TagName)
        {
            Block B = DocLet.Find(TagName);

            return(B != null);
        }
Exemplo n.º 5
0
        string GetMultiLineTagValue(string TagName)
        {
            Block B = DocLet.Find(TagName);

            return(GetMultiLineBlockValue(B));
        }
Exemplo n.º 6
0
        void Parse()
        {
            string[] Lines;
            string   Line;
            string   L; // trimmed line

            DocLet   DocLet = null;
            Block    Block  = null;
            LineKind Kind   = LineKind.None;
            string   S;
            string   TagName = string.Empty;



            foreach (string FilePath in FilePaths)
            {
                Lines = File.ReadAllLines(FilePath);

                for (int i = 0; i < Lines.Length; i++)
                {
                    Line = Lines[i];

                    if (DocLet == null && Line.Trim().Length == 0 && (Block == null))
                    {
                        continue;
                    }


                    L = Line.Trim(' ', '\n', '\r', '\t');


                    // line kind detection
                    // ------------------------------------------------------------------------
                    Kind    = LineKind.None;
                    TagName = string.Empty;

                    if (DocLet == null && L.StartsWith("/**"))
                    {
                        Kind |= LineKind.First;
                        L     = L.Remove(0, 3).TrimStart();
                        Line  = L;

                        DocLet = new DocLet(FilePath, i, Lines);
                    }


                    if (DocLet != null)
                    {
                        if (L.EndsWith("*/"))
                        {
                            Kind |= LineKind.Last;
                            L     = L.Remove(L.Length - 2, 2);
                            L     = L.TrimEnd();

                            Line = Line.TrimEnd();
                            Line = Line.Remove(Line.Length - 2, 2);
                        }

                        if (L.TrimStart(' ', '*').StartsWith("@"))
                        {
                            L = L.TrimStart(' ', '*');
                            S = Tags.FindBlockTag(L);

                            if (S != string.Empty)
                            {
                                Kind   |= LineKind.Block;
                                TagName = S;

                                L    = L.Remove(0, TagName.Length).TrimStart();
                                Line = L;

                                Block = new Block(TagName, L);
                                DocLet.Blocks.Add(Block);
                                L = "";

                                if (!Block.IsMultiLine)
                                {
                                    Block = null;
                                }

                                if (!Sys.In(LineKind.Last, Kind))
                                {
                                    continue;
                                }
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(L))
                        {
                            if (Block == null)
                            {
                                Kind   |= LineKind.Block;
                                TagName = Tags.Description;

                                Block = new Block(TagName, L);
                                DocLet.Blocks.Add(Block);
                            }
                            else if (Block.IsMultiLine)
                            {
                                Kind |= LineKind.Line;
                                Block.Lines.Add(Line);
                            }
                        }
                        else if (Block != null && !Sys.In(LineKind.Last, Kind))
                        {
                            Block.Lines.Add(Line);
                        }


                        // doclet or block creation and line addition
                        // ------------------------------------------------------------------------

                        if (Sys.In(LineKind.Last, Kind))
                        {
                            DocLet.LastLineIndex = i;
                            if (DocLet.Blocks.Count > 0)
                            {
                                ParseDocLet(DocLet);
                            }

                            DocLet = null;
                            Block  = null;
                        }
                    }
                }
            }
        }