Exemplo n.º 1
0
        private string[] CommentTextToDomainCommentTextLines(Token comment, out bool isDecorated)
        {
            CommentTerminal commentTerminal = (CommentTerminal)comment.Terminal;

            CommentKind commentKind = GrammarHelper.GetCommentKind(commentTerminal, GetCommentCleaner(commentTerminal).NewLine);

            string startSymbol = commentTerminal.StartSymbol;

            string endSymbol = commentKind == CommentKind.Delimited
                ? commentTerminal.EndSymbols.First(_endSymbol => comment.Text.EndsWith(_endSymbol))
                : string.Empty;

            string text = comment.Text;

            text = text
                   .Remove(text.Length - endSymbol.Length, endSymbol.Length)
                   .Remove(0, startSymbol.Length);

            var commentCleaner = GetCommentCleaner(commentTerminal);

            // NOTE: we handle "\n" and "\r" as well to deal with wrongly formatted input
            string[] textLines = text.Split(new[] { commentCleaner.NewLine, "\r", "\n" }, StringSplitOptions.None);
            textLines = commentCleaner.GetCleanedUpCommentTextLines(textLines, comment.Location.Column, commentTerminal, out isDecorated);

            return(textLines);
        }
Exemplo n.º 2
0
        public virtual void GenerateMultiLineComment(List <string> lines, CommentKind kind)
        {
            PushBlock(BlockKind.BlockComment);

            var lineCommentPrologue = Comment.GetLineCommentPrologue(kind);

            if (!string.IsNullOrWhiteSpace(lineCommentPrologue))
            {
                WriteLine("{0}", lineCommentPrologue);
            }

            var multiLineCommentPrologue = Comment.GetMultiLineCommentPrologue(kind);

            foreach (var line in lines)
            {
                WriteLine("{0} {1}", multiLineCommentPrologue, line);
            }

            var lineCommentEpilogue = Comment.GetLineCommentEpilogue(kind);

            if (!string.IsNullOrWhiteSpace(lineCommentEpilogue))
            {
                WriteLine("{0}", lineCommentEpilogue);
            }

            PopBlock();
        }
Exemplo n.º 3
0
        public Comment(IToken token, CommentKind commentKind, IToken previous)
        {
            BestCandidate = null;
            Distance      = 0;

            CommentKind   = commentKind;
            Token         = token;
            PreviousToken = previous;
            AnchorKind    = AnchorKind.None;
        }
Exemplo n.º 4
0
        public static string CommentToString(this Comment comment, CommentKind kind)
        {
            var sections = new List <Section> {
                new Section(CommentElement.Summary)
            };

            GetCommentSections(comment, sections);
            foreach (var section in sections)
            {
                TrimSection(section);
            }
            return(FormatComment(sections, kind));
        }
Exemplo n.º 5
0
        public static void Print(this ITextGenerator textGenerator, Comment comment, CommentKind kind)
        {
            var sections = new List <Section> {
                new Section(CommentElement.Summary)
            };

            GetCommentSections(comment, sections);
            foreach (var section in sections)
            {
                TrimSection(section);
            }
            FormatComment(textGenerator, sections, kind);
        }
Exemplo n.º 6
0
        public override void GenerateFilePreamble(CommentKind kind, string generatorName = "pylon-node-gen")
        {
            var lines = new List <string>
            {
                "----------------------------------------------------------------------------",
                $"This is auto generated code by {generatorName}.",
                "Do not edit this file or all your changes will be lost after re-generation.",
                "----------------------------------------------------------------------------",
            };

            PushBlock(BlockKind.Header);
            GenerateMultiLineComment(lines, kind);
            PopBlock(NewLineKind.BeforeNextBlock);
        }
Exemplo n.º 7
0
        private static string FormatComment(List <Section> sections, CommentKind kind)
        {
            var commentPrefix  = Comment.GetMultiLineCommentPrologue(kind);
            var commentBuilder = new StringBuilder();

            sections.Sort((x, y) => x.Type.CompareTo(y.Type));
            var remarks = sections.Where(s => s.Type == CommentElement.Remarks).ToList();

            if (remarks.Any())
            {
                remarks.First().GetLines().AddRange(remarks.Skip(1).SelectMany(s => s.GetLines()));
            }
            if (remarks.Count > 1)
            {
                sections.RemoveRange(sections.IndexOf(remarks.First()) + 1, remarks.Count - 1);
            }

            foreach (var section in sections.Where(s => s.HasLines))
            {
                var lines      = section.GetLines();
                var tag        = section.Type.ToString().ToLowerInvariant();
                var attributes = string.Empty;
                if (section.Attributes.Any())
                {
                    attributes = ' ' + string.Join(" ", section.Attributes);
                }
                commentBuilder.Append($"{commentPrefix} <{tag}{attributes}>");
                if (lines.Count == 1)
                {
                    commentBuilder.Append(lines[0]);
                }
                else
                {
                    commentBuilder.AppendLine();
                    foreach (var line in lines)
                    {
                        commentBuilder.AppendLine($"{commentPrefix} <para>{line}</para>");
                    }
                    commentBuilder.Append($"{commentPrefix} ");
                }
                commentBuilder.AppendLine($"</{tag}>");
            }
            if (commentBuilder.Length > 0)
            {
                var newLineLength = Environment.NewLine.Length;
                commentBuilder.Remove(commentBuilder.Length - newLineLength, newLineLength);
            }
            return(commentBuilder.ToString());
        }
Exemplo n.º 8
0
        public virtual void GenerateFilePreamble(CommentKind kind, string generatorName = "CppSharp")
        {
            var lines = new List <string>
            {
                "----------------------------------------------------------------------------",
                "<auto-generated>",
                $"This is autogenerated code by {generatorName}.",
                "Do not edit this file or all your changes will be lost after re-generation.",
                "</auto-generated>",
                "----------------------------------------------------------------------------"
            };

            PushBlock(BlockKind.Header);
            GenerateMultiLineComment(lines, kind);
            PopBlock();
        }
Exemplo n.º 9
0
        public static string GetLineCommentEpilogue(CommentKind kind)
        {
            switch (kind)
            {
            case CommentKind.BCPL:
            case CommentKind.BCPLSlash:
            case CommentKind.BCPLExcl:
                return(string.Empty);

            case CommentKind.C:
            case CommentKind.JavaDoc:
            case CommentKind.Qt:
                return(" */");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 10
0
        public static string GetMultiLineCommentPrologue(CommentKind kind)
        {
            switch (kind)
            {
            case CommentKind.BCPL:
            case CommentKind.BCPLExcl:
                return("//");

            case CommentKind.C:
            case CommentKind.JavaDoc:
            case CommentKind.Qt:
                return(" *");

            case CommentKind.BCPLSlash:
                return("///");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 11
0
        public virtual void GenerateLegalFilePreamble(CommentKind kind, string creatorYear = "", string creatorName = "Björn Rennfanz <*****@*****.**>")
        {
            // Check if year is empty
            if (string.IsNullOrEmpty(creatorYear))
            {
                // Set copyright year to today
                creatorYear = DateTime.Now.ToString("yyyy");
            }

            var lines = new List <string>
            {
                "MIT License",
                "",
                $"Copyright (c) {creatorYear} {creatorName}",
                "",
                "Permission is hereby granted, free of charge, to any person obtaining a copy",
                "of this software and associated documentation files (the \"Software\"), to deal",
                "in the Software without restriction, including without limitation the rights",
                "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell",
                "copies of the Software, and to permit persons to whom the Software is",
                "furnished to do so, subject to the following conditions:",
                "",
                "The above copyright notice and this permission notice shall be included in all",
                "copies or substantial portions of the Software.",
                "",
                "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR",
                "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,",
                "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE",
                "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER",
                "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,",
                "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE",
                "SOFTWARE.",
                ""
            };

            PushBlock(BlockKind.Header);
            GenerateMultiLineComment(lines, kind);
            PopBlock();
        }
Exemplo n.º 12
0
        private static string FormatComment(List <Section> sections, CommentKind kind)
        {
            var commentPrefix = Comment.GetMultiLineCommentPrologue(kind);

            var commentBuilder = new StringBuilder();

            foreach (var section in sections.Where(s => s.Lines.Count > 0))
            {
                var tag        = section.Type.ToString().ToLowerInvariant();
                var attributes = string.Empty;
                if (section.Attributes.Any())
                {
                    attributes = ' ' + string.Join(" ", section.Attributes);
                }
                commentBuilder.Append($"{commentPrefix} <{tag}{attributes}>");
                if (section.Lines.Count == 1)
                {
                    commentBuilder.Append(section.Lines[0]);
                }
                else
                {
                    commentBuilder.AppendLine();
                    foreach (var line in section.Lines)
                    {
                        commentBuilder.AppendLine($"{commentPrefix} <para>{line}</para>");
                    }
                    commentBuilder.Append($"{commentPrefix} ");
                }
                commentBuilder.AppendLine($"</{tag}>");
            }
            if (commentBuilder.Length > 0)
            {
                var newLineLength = Environment.NewLine.Length;
                commentBuilder.Remove(commentBuilder.Length - newLineLength, newLineLength);
            }
            return(commentBuilder.ToString());
        }
Exemplo n.º 13
0
 public BlockCommandComment(CommentKind Kind) : base(Kind)
 {
 }
Exemplo n.º 14
0
        private static void FormatComment(ITextGenerator textGenerator, List <Section> sections, CommentKind kind)
        {
            var commentPrefix = Comment.GetMultiLineCommentPrologue(kind);

            sections.Sort((x, y) => x.Type.CompareTo(y.Type));
            var remarks = sections.Where(s => s.Type == CommentElement.Remarks).ToList();

            if (remarks.Any())
            {
                remarks.First().GetLines().AddRange(remarks.Skip(1).SelectMany(s => s.GetLines()));
            }
            if (remarks.Count > 1)
            {
                sections.RemoveRange(sections.IndexOf(remarks.First()) + 1, remarks.Count - 1);
            }

            foreach (var section in sections.Where(s => s.HasLines))
            {
                var lines      = section.GetLines();
                var tag        = section.Type.ToString().ToLowerInvariant();
                var attributes = string.Empty;
                if (section.Attributes.Any())
                {
                    attributes = ' ' + string.Join(" ", section.Attributes);
                }
                textGenerator.Write($"{commentPrefix} <{tag}{attributes}>");
                if (lines.Count == 1)
                {
                    textGenerator.Write(lines[0]);
                }
                else
                {
                    textGenerator.NewLine();
                    foreach (var line in lines)
                    {
                        textGenerator.WriteLine($"{commentPrefix} <para>{line}</para>");
                    }
                    textGenerator.Write($"{commentPrefix} ");
                }
                textGenerator.WriteLine($"</{tag}>");
            }
        }
Exemplo n.º 15
0
 public Comment(CommentKind Kind = default, @string Text = default, ref ptr <Comment> Next = default)
 {
     this.Kind = Kind;
     this.Text = Text;
     this.Next = Next;
 }
Exemplo n.º 16
0
 public Comment(string[] textLines, CommentCategory category, CommentPlacement placement, int lineIndexDistanceFromOwner, CommentKind kind, bool isDecorated)
 {
     this.TextLines = textLines;
     this.Category  = category;
     this.Placement = placement;
     this.LineIndexDistanceFromOwner = lineIndexDistanceFromOwner;
     this.Kind        = kind;
     this.IsDecorated = isDecorated;
 }
Exemplo n.º 17
0
 public HTMLTagComment(CommentKind Kind) : base(Kind)
 {
 }
Exemplo n.º 18
0
 public Comment(CommentKind kind)
 {
 }
Exemplo n.º 19
0
 public InlineContentComment(CommentKind Kind) : base(Kind)
 {
 }
Exemplo n.º 20
0
 public BlockContentComment(CommentKind Kind) : base(Kind)
 {
 }