Exemplo n.º 1
0
        public IHtmlWriter WriteComment(string comment, CommentStyle commentStyle)
        {
            if (IncludeComments && !string.IsNullOrEmpty(comment))
            {
                if (commentStyle == CommentStyle.Xml)
                {
                    Write("<!-- ");
                    Write(comment);
                    WriteLine(" -->");
                }
                else if (commentStyle == CommentStyle.SingleLineC)
                {
                    Write("// ");
                    WriteLine(comment);
                }
                else if (commentStyle == CommentStyle.MultiLineC)
                {
                    Write("/* ");
                    Write(comment);
                    WriteLine(" */");
                }
            }

            return(this);
        }
        private static string CreateToken(CommentStyle style)
        {
            switch (style)
            {
            case CommentStyle.XmlStyle:
                return(Lexems.SingleLineXmlStyleComment);

            case CommentStyle.Normal:
            default:
                return(Lexems.SingleLineComment);
            }
        }
Exemplo n.º 3
0
        public static string AsString(this CommentStyle quoteStyle)
        {
            switch (quoteStyle)
            {
            case CommentStyle.MultiLine: return("/*");

            case CommentStyle.Hashmark: return("#");

            case CommentStyle.DashDash: return("--");

            default: throw new NotSupportedException();
            }
        }
Exemplo n.º 4
0
        public IJavascriptWriter WriteComment(string comment, CommentStyle commentStyle, IPackage package)
        {
            if (!IncludeComments)
            {
                return(this);
            }

            var javascriptNamespace = GetNamespace(package);

            javascriptNamespace.Add(
                new CommentElement
            {
                Name         = null,
                IsPublic     = false,
                Type         = null,
                Comment      = comment,
                CommentStyle = commentStyle
            });
            return(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Appends the script to represent the comment to the StringBuilder.
        /// </summary>
        /// <param name="builder">The StringBuilder to which the comment is appended.</param>
        /// <param name="options">The options to use when appending JavaScript</param>
        /// <param name="allowReservedWords"></param>
        protected internal override void AppendScript(StringBuilder builder, ScriptOptions options, bool allowReservedWords)
        {
            if (AddExtraLineBreaks)
            {
                builder.AppendLine();
            }

            CommentStyle style = Style;

            if (style == CommentStyle.Auto)
            {
                style = Content.Contains("/*") || Content.Contains("*/") || Content.Contains("\r\n")
                                        ? CommentStyle.OneLineComments
                                        : CommentStyle.MultipleLineComments;
            }

            switch (style)
            {
            case CommentStyle.OneLineComments:
                foreach (var line in Content.Split(new[] { "\r\n" }, StringSplitOptions.None))
                {
                    builder.Append("// ");
                    builder.AppendLine(line);
                }
                break;

            case CommentStyle.MultipleLineComments:
                builder.Append("/* ");
                builder.Append(Content);
                builder.Append(" */");
                if (AddExtraLineBreaks)
                {
                    builder.AppendLine();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 6
0
        IHtmlWriter IHtmlWriter.WriteComment(string comment, CommentStyle commentStyle)
        {
            if (IncludeComments && !string.IsNullOrEmpty(comment))
            {
                if (commentStyle == CommentStyle.Xml)
                {
                    _characterStream.WriteBlockComment(comment);
                    WriteLine();
                }
                else if (commentStyle == CommentStyle.SingleLineC)
                {
                    Write("// ");
                    WriteLine(comment);
                }
                else if (commentStyle == CommentStyle.MultiLineC)
                {
                    Write("/* ");
                    Write(comment);
                    WriteLine(" */");
                }
            }

            return(this);
        }
 private static string CreateToken(CommentStyle style)
 {
     switch (style)
     {
         case CommentStyle.XmlStyle:
             return Lexems.SingleLineXmlStyleComment;
         case CommentStyle.Normal:
         default:
             return Lexems.SingleLineComment;
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="comment"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static SingleLineCommentTranslationUnit Create(string comment, CommentStyle style = CommentStyle.Normal)
 {
     return new SingleLineCommentTranslationUnit(comment, CreateToken(style));
 }
Exemplo n.º 9
0
 public string Process(IEnumerable <string> lines, CommentStyle style) => Commenters[style].Process(lines);
 public CodeComment(string text, CommentStyle commentStyle = CommentStyle.Line)
 {
     Text  = text;
     Style = commentStyle;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="comment"></param>
 /// <param name="style"></param>
 /// <returns></returns>
 public static SingleLineCommentTranslationUnit Create(string comment, CommentStyle style = CommentStyle.Normal)
 {
     return(new SingleLineCommentTranslationUnit(comment, CreateToken(style)));
 }
Exemplo n.º 12
0
 public static InjectionOptions TerminateStatement(this InjectionOptions injector, CommentStyle commentStyle, int parenthesisNestingDepth = 0, bool useSemicolon = false)
 {
     injector.CommentStyle              = commentStyle;
     injector.ParenthesisNestingDepth   = parenthesisNestingDepth;
     injector.EndStatementBeforeComment = useSemicolon;
     return(injector);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Scans the file to determine the comment separator
        /// It additionally determines if encoding directives are located on 1 or 2 lines
        /// </summary>
        /// <returns></returns>
        private string DetectCommentStyle()
        {
            fileCommentStyle = CommentStyle.Invalid;

            long pos = rdr.BaseStream.Position;

            Seek(0, SeekOrigin.Begin);

            string line;

            while ((line = ReadLine(out LineType lineType)) != null)
            {
                if (lineType != LineType.Comment)
                {
                    continue;
                }

                if (fileCommentToken == null)
                {
                    foreach (string token in commentTokens)
                    {
                        if (line.StartsWith(token))
                        {
                            fileCommentToken = token;
                            break;
                        }
                    }
                }

                string lineInner = DetectCommment(RemoveCommentToken(line), out CommentType commentType, out CommentSubType commentSubType);
                if (commentType != CommentType.Check)
                {
                    continue;
                }


                string[] parts = line.Split(new string[] { fileCommentToken }, StringSplitOptions.RemoveEmptyEntries);
                switch (parts.Length)
                {
                case 1:
                    long   curPos = rdr.BaseStream.Position;
                    string line2  = ReadLine(out LineType line2Type);
                    if (line2 == null)
                    {
                        fileCommentStyle = CommentStyle.Invalid;
                        stopHandling     = true;
                        goto end_ret;
                    }
                    if (line2Type != LineType.Comment)
                    {
                        string line1CommentInner = DetectCommment(
                            lineInner,
                            out CommentType line1CommentInnerType,
                            out CommentSubType line1CommentInnerSubType
                            );
                        if (line2Type == LineType.Assembly && line1CommentInnerType == CommentType.Encoding)
                        {
                            fileCommentStyle = CommentStyle.TwoLinesAsm;
                            goto end_ret;
                        }
                        continue;
                    }
                    line2 = DetectCommment(RemoveCommentToken(line2), out CommentType comment2Type, out CommentSubType comment2SubType);
                    if (comment2Type == CommentType.Check)
                    {
                        DetectCommment(line2, out comment2Type, out comment2SubType);
                        if (comment2Type == CommentType.Encoding)
                        {
                            fileCommentStyle = CommentStyle.TwoLines;
                        }
                        else
                        {
                            fileCommentStyle = CommentStyle.Invalid;
                            goto end_ret;
                        }
                    }
                    else
                    {
                        fileCommentStyle = CommentStyle.Invalid;
                        goto end_ret;
                    }
                    break;

                case 2:
                    fileCommentStyle = CommentStyle.OneLine;
                    break;

                case 0:
                    goto throw_ex;

                default:
                    if (parts[1].Trim() == "<MCInst")
                    {
                        goto case 2;
                    }

throw_ex:
                    throw new NotSupportedException($"Comment '{line}' contains {parts.Length} pieces");
                }

                if (fileCommentToken != null)
                {
                    break;
                }
            }

end_ret:
            Seek(pos, SeekOrigin.Begin);
            return(fileCommentToken);
        }