[plug] Another perl question...
David Buddrige
buddrige at wasp.net.au
Thu Nov 21 16:05:56 WST 2002
Hi all,
I am writing a program which will re-arrange a doc++ comment.
A doc++ comment is a C/C++ comment that starts with an extra "*". An
example of a doc++ comment is this:
/**
@doc Some general info about a function.
@precondition Any precondition that the function has
@postcondition Any postcondition that the function has.
*/
I want to have all of my doc++ comments formatted so that the start comment
"/**" is on a line by itself, and each @entry is on a line by itself.
At the moment, I have some doc++ comments that are like this:
/** @doc
This is some general info about a function
@precondition
This is info about a precondition.
*/
I would like to re-arrange this comment so that it looks like this:
/**
@doc This is some general info about a function
@precondition This is info about a precondition.
*/
To do this, I have written the following function:
# This subroutine takes as input a single array reference, and
# rearranges any doc++ commands that are split over multiple lines so
# that each doc++ command is on a line of its own, including the /** and
# */ delimiters which indicate the start and end of a doc++ comment.
sub format_docpp_comment
{
my $doc_comment_array;
my $comment_line;
my $single_comment_line;
$doc_comment_array = $_[0]; # give a friendly name to the array
foreach $comment_line ( @$doc_comment_array )
{
#chomp $comment_line;
my $temp_string;
$temp_string = $comment_line;
chomp $temp_string;
$single_comment_line .= $temp_string;
}
# At this point we have a single string that contains our entire
# doc++ comment. We can now use simple pattern matching to parse
# it.
$single_comment_line =~ m"(\/\*\*)(([\t\n
]*)(\@)(doc|invariant|return|precondition|postcondition)([\t\n\w\.\ ]+))+";
print "2: $2\n";
}
At this point, the $2 variable has within it, the very first doc++ style
comment which is usually:
@doc some text.
I want to get at the rest of the repeated @somecommand doc++ commands.
Does anyone know how this is done?
I kind'of want to store what I have already matched in $2 to some scalar,
and then delete that part of the string matched so far, so that I can repeat
the pattern match for the next chunk. However I am not sure how to proceed.
thanks
David.
More information about the plug
mailing list