Skip to content

Commit

Permalink
Restored support for full comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
  • Loading branch information
ddobrev committed Jul 29, 2015
1 parent a37f104 commit cd3e729
Show file tree
Hide file tree
Showing 18 changed files with 11,166 additions and 164 deletions.
4 changes: 2 additions & 2 deletions src/AST/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public override void Visit<T>(ICommentVisitor<T> visitor)
/// <summary>
/// A command with word-like arguments that is considered inline content.
/// </summary>
public class InlineCommandComment : Comment
public class InlineCommandComment : InlineContentComment
{
public struct Argument
{
Expand Down Expand Up @@ -388,7 +388,7 @@ public override void Visit<T>(ICommentVisitor<T> visitor)
/// <summary>
/// A line of text contained in a verbatim block.
/// </summary>
public class VerbatimBlockLineComment : BlockCommandComment
public class VerbatimBlockLineComment : Comment
{
public string Text;

Expand Down
167 changes: 161 additions & 6 deletions src/Core/Parser/ASTConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,56 @@ public abstract class CommentsVisitor<TRet>
{
public abstract TRet VisitFullComment(FullComment comment);

public virtual TRet Visit(Parser.AST.Comment comment)
protected abstract TRet VisitBlockCommandComment(BlockCommandComment comment);

protected abstract TRet VisitParamCommandComment(ParamCommandComment comment);

protected abstract TRet VisitTParamCommandComment(TParamCommandComment comment);

protected abstract TRet VisitVerbatimBlockComment(VerbatimBlockComment comment);

protected abstract TRet VisitVerbatimLineComment(VerbatimLineComment comment);

protected abstract TRet VisitParagraphComment(ParagraphComment comment);

protected abstract TRet VisitHTMLStartTagComment(HTMLStartTagComment comment);

protected abstract TRet VisitHTMLEndTagComment(HTMLEndTagComment comment);

protected abstract TRet VisitTextComment(TextComment comment);

protected abstract TRet VisitInlineCommandComment(InlineCommandComment comment);

protected abstract TRet VisitVerbatimBlockLineComment(VerbatimBlockLineComment comment);

public virtual TRet Visit(Comment comment)
{
switch (comment.Kind)
{
case CommentKind.FullComment:
{
var _comment = FullComment.__CreateInstance(comment.__Instance);
return VisitFullComment(_comment);
}
return VisitFullComment(FullComment.__CreateInstance(comment.__Instance));
case CommentKind.BlockCommandComment:
return VisitBlockCommandComment(BlockCommandComment.__CreateInstance(comment.__Instance));
case CommentKind.ParamCommandComment:
return VisitParamCommandComment(ParamCommandComment.__CreateInstance(comment.__Instance));
case CommentKind.TParamCommandComment:
return VisitTParamCommandComment(TParamCommandComment.__CreateInstance(comment.__Instance));
case CommentKind.VerbatimBlockComment:
return VisitVerbatimBlockComment(VerbatimBlockComment.__CreateInstance(comment.__Instance));
case CommentKind.VerbatimLineComment:
return VisitVerbatimLineComment(VerbatimLineComment.__CreateInstance(comment.__Instance));
case CommentKind.ParagraphComment:
return VisitParagraphComment(ParagraphComment.__CreateInstance(comment.__Instance));
case CommentKind.HTMLStartTagComment:
return VisitHTMLStartTagComment(HTMLStartTagComment.__CreateInstance(comment.__Instance));
case CommentKind.HTMLEndTagComment:
return VisitHTMLEndTagComment(HTMLEndTagComment.__CreateInstance(comment.__Instance));
case CommentKind.TextComment:
return VisitTextComment(TextComment.__CreateInstance(comment.__Instance));
case CommentKind.InlineCommandComment:
return VisitInlineCommandComment(InlineCommandComment.__CreateInstance(comment.__Instance));
case CommentKind.VerbatimBlockLineComment:
return VisitVerbatimBlockLineComment(VerbatimBlockLineComment.__CreateInstance(comment.__Instance));
}

throw new ArgumentOutOfRangeException();
Expand Down Expand Up @@ -1542,7 +1583,121 @@ public unsafe class CommentConverter : CommentsVisitor<AST.Comment>
{
public override AST.Comment VisitFullComment(FullComment comment)
{
throw new NotImplementedException();
var fullComment = new AST.FullComment();
for (uint i = 0; i < comment.BlocksCount; i++)
fullComment.Blocks.Add((AST.BlockContentComment) Visit(comment.getBlocks(i)));
return fullComment;
}

protected override AST.Comment VisitBlockCommandComment(BlockCommandComment comment)
{
var blockCommandComment = new AST.BlockCommandComment();
VisitBlockCommandComment(blockCommandComment, comment);
return blockCommandComment;
}

protected override AST.Comment VisitParamCommandComment(ParamCommandComment comment)
{
var paramCommandComment = new AST.ParamCommandComment();
switch (comment.Direction)
{
case ParamCommandComment.PassDirection.In:
paramCommandComment.Direction = AST.ParamCommandComment.PassDirection.In;
break;
case ParamCommandComment.PassDirection.Out:
paramCommandComment.Direction = AST.ParamCommandComment.PassDirection.Out;
break;
case ParamCommandComment.PassDirection.InOut:
paramCommandComment.Direction = AST.ParamCommandComment.PassDirection.InOut;
break;
}
paramCommandComment.ParamIndex = comment.ParamIndex;
return paramCommandComment;
}

protected override AST.Comment VisitTParamCommandComment(TParamCommandComment comment)
{
var paramCommandComment = new AST.TParamCommandComment();
for (uint i = 0; i < comment.PositionCount; i++)
paramCommandComment.Position.Add(comment.getPosition(i));
VisitBlockCommandComment(paramCommandComment, comment);
return paramCommandComment;
}

protected override AST.Comment VisitVerbatimBlockComment(VerbatimBlockComment comment)
{
var verbatimBlockComment = new AST.VerbatimBlockComment();
for (uint i = 0; i < comment.LinesCount; i++)
verbatimBlockComment.Lines.Add((AST.VerbatimBlockLineComment) Visit(comment.getLines(i)));
VisitBlockCommandComment(verbatimBlockComment, comment);
return verbatimBlockComment;
}

protected override AST.Comment VisitVerbatimLineComment(VerbatimLineComment comment)
{
var verbatimLineComment = new AST.VerbatimLineComment { Text = comment.Text };
VisitBlockCommandComment(verbatimLineComment, comment);
return verbatimLineComment;
}

protected override AST.Comment VisitParagraphComment(ParagraphComment comment)
{
var paragraphComment = new AST.ParagraphComment();
for (uint i = 0; i < comment.ContentCount; i++)
paragraphComment.Content.Add((AST.InlineContentComment) Visit(comment.getContent(i)));
paragraphComment.IsWhitespace = comment.IsWhitespace;
return paragraphComment;
}

protected override AST.Comment VisitHTMLStartTagComment(HTMLStartTagComment comment)
{
var htmlStartTagComment = new AST.HTMLStartTagComment();
for (uint i = 0; i < comment.AttributesCount; i++)
{
var attribute = new AST.HTMLStartTagComment.Attribute();
var _attribute = comment.getAttributes(i);
attribute.Name = _attribute.Name;
attribute.Value = _attribute.Value;
htmlStartTagComment.Attributes.Add(attribute);
}
htmlStartTagComment.TagName = comment.TagName;
return htmlStartTagComment;
}

protected override AST.Comment VisitHTMLEndTagComment(HTMLEndTagComment comment)
{
return new AST.HTMLEndTagComment { TagName = comment.TagName };
}

protected override AST.Comment VisitTextComment(TextComment comment)
{
return new AST.TextComment { Text = comment.Text };
}

protected override AST.Comment VisitInlineCommandComment(InlineCommandComment comment)
{
var inlineCommandComment = new AST.InlineCommandComment();
for (uint i = 0; i < comment.ArgumentsCount; i++)
{
var argument = new AST.InlineCommandComment.Argument { Text = comment.getArguments(i).Text };
inlineCommandComment.Arguments.Add(argument);
}
return inlineCommandComment;
}

protected override AST.Comment VisitVerbatimBlockLineComment(VerbatimBlockLineComment comment)
{
return new AST.VerbatimBlockLineComment { Text = comment.Text };
}

private static void VisitBlockCommandComment(AST.BlockCommandComment blockCommandComment, BlockCommandComment comment)
{
blockCommandComment.CommandId = comment.CommandId;
for (uint i = 0; i < comment.ArgumentsCount; i++)
{
var argument = new AST.BlockCommandComment.Argument { Text = comment.getArguments(i).Text };
blockCommandComment.Arguments.Add(argument);
}
}
}

Expand Down
74 changes: 74 additions & 0 deletions src/CppParser/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,78 @@ RawComment::RawComment() : FullCommentBlock(0) {}

FullComment::FullComment() : Comment(CommentKind::FullComment) {}

DEF_VECTOR(FullComment, BlockContentComment*, Blocks)

BlockContentComment::BlockContentComment() : Comment(CommentKind::BlockContentComment) {}

BlockContentComment::BlockContentComment(CommentKind Kind) : Comment(Kind) {}

BlockCommandComment::Argument::Argument() {}

DEF_STRING(BlockCommandComment::Argument, Text)

BlockCommandComment::BlockCommandComment() : BlockContentComment(CommentKind::BlockCommandComment), CommandId(0) {}

BlockCommandComment::BlockCommandComment(CommentKind Kind) : BlockContentComment(Kind) {}

DEF_VECTOR(BlockCommandComment, BlockCommandComment::Argument, Arguments)

ParamCommandComment::ParamCommandComment() : BlockCommandComment(CommentKind::ParamCommandComment), Direction(PassDirection::In), ParamIndex(0) {}

TParamCommandComment::TParamCommandComment() : BlockCommandComment(CommentKind::TParamCommandComment) {}

DEF_VECTOR(TParamCommandComment, unsigned, Position)

VerbatimBlockComment::VerbatimBlockComment() : BlockCommandComment(CommentKind::VerbatimBlockComment) {}

DEF_VECTOR(VerbatimBlockComment, VerbatimBlockLineComment*, Lines)

VerbatimLineComment::VerbatimLineComment() : BlockCommandComment(CommentKind::VerbatimLineComment) {}

DEF_STRING(VerbatimLineComment, Text)

ParagraphComment::ParagraphComment() : BlockContentComment(CommentKind::ParagraphComment), IsWhitespace(false) {}

DEF_VECTOR(ParagraphComment, InlineContentComment*, Content)

HTMLTagComment::HTMLTagComment() : InlineContentComment(CommentKind::HTMLTagComment) {}

HTMLTagComment::HTMLTagComment(CommentKind Kind) : InlineContentComment(Kind) {}

HTMLStartTagComment::Attribute::Attribute() {}

DEF_STRING(HTMLStartTagComment::Attribute, Name)

DEF_STRING(HTMLStartTagComment::Attribute, Value)

HTMLStartTagComment::HTMLStartTagComment() : HTMLTagComment(CommentKind::HTMLStartTagComment) {}

DEF_VECTOR(HTMLStartTagComment, HTMLStartTagComment::Attribute, Attributes)

DEF_STRING(HTMLStartTagComment, TagName)

HTMLEndTagComment::HTMLEndTagComment() : HTMLTagComment(CommentKind::HTMLEndTagComment) {}

DEF_STRING(HTMLEndTagComment, TagName)

InlineContentComment::InlineContentComment() : Comment(CommentKind::InlineContentComment) {}

InlineContentComment::InlineContentComment(CommentKind Kind) : Comment(Kind) {}

TextComment::TextComment() : InlineContentComment(CommentKind::TextComment) {}

DEF_STRING(TextComment, Text)

InlineCommandComment::Argument::Argument() {}

DEF_STRING(InlineCommandComment::Argument, Text)

InlineCommandComment::InlineCommandComment() : InlineContentComment(CommentKind::InlineCommandComment), CommentRenderKind(RenderNormal) {}

DEF_VECTOR(InlineCommandComment, InlineCommandComment::Argument, Arguments)

VerbatimBlockLineComment::VerbatimBlockLineComment() : Comment(CommentKind::VerbatimBlockLineComment) {}

DEF_STRING(VerbatimBlockLineComment, Text)

} } }
Loading

0 comments on commit cd3e729

Please sign in to comment.