コード例 #1
0
ファイル: ParseTree.cs プロジェクト: kevlyons/Sarcasm
        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);
        }
コード例 #2
0
ファイル: ParseTree.cs プロジェクト: kevlyons/Sarcasm
        private Comment CommentToDomainComment(Token comment, ParseTreeNode parseTreeNodeOwner, CommentPlacement placement, int lineIndexDistanceFromOwner)
        {
            CommentTerminal commentTerminal = (CommentTerminal)comment.Terminal;
            bool            isDecorated;

            return(new Comment(
                       CommentTextToDomainCommentTextLines(comment, out isDecorated),
                       CommentCategoryToDomainCommentCategory(comment.Category),
                       placement,
                       lineIndexDistanceFromOwner,
                       GrammarHelper.GetCommentKind(commentTerminal, GetCommentCleaner(commentTerminal).NewLine),
                       isDecorated
                       ));
        }