NAME
String::Comments::Extract - Extract comments from C, C++, and JavaScript
VERSION
Version 0.01
SYNOPSIS
use String::Comments::Extract;
my $source = <<_END_;
/* A Hello World program
Copyright Ty Coon
// ...and Buckaroo Banzai
"Yoyodyne"*/
void main() {
printf("Hello, World.\n");
printf("/* This is not a real comment */");
printf("// Neither is this */");
// But this is
}
// Last comment
_END_
my $comments = String::Comments::Extract::C->extract_comments($source);
# ... returns the following result:
/* A Hello World program
Copyright Ty Coon
// ...and Buckaroo Banzai
"Yoyodyne"*/
// But this is
// Last comment
my @comments = String::Comments::Extract::C->collect_comments($source);
# ... returns the following list:
(
' A Hello World program
Copyright Ty Coon
// ...and Buckaroo Banzai
"Yoyodyne"'
' But this is',
' Last comment',
)
DESCRIPTION
String::Comments::Extract is a tool for extracting comments from C/C++/JavaScript source. The extractor is implemented using an actual tokenizer (written in C via XS, adapted from JavaScript::Minifier::XS), so it can robustly deal with notoriously problematic cases. Comment-like structures in strings, for example:
std::cout << "This is not a // real C++ comment " << std::endl
printf("/* This is not a real C comment */\n");
# The extractor will ignore both of the above
String::Comments::Extract considers C/C++/JavaScript comment structures the same, so, for now, it doesn't really matter which method you use (this means it will not complain about C++ style comments in C source).
METHODS
String::Comments::Extract::JavaScript->extract( <source> )
String::Comments::Extract::CPP->extract( <source> )
String::Comments::Extract::C->extract( <source> )
Returns a string representing the comments in <source>
Comment delimeters (/* */ //
) are left in as-is
Whitespace of <source> is otherwise preserved, so you'll probably have to do some post-processing on the result to get rid of some cruft.
String::Comments::Extract::JavaScript->collect( <source> )
String::Comments::Extract::CPP->collect( <source> )
String::Comments::Extract::C->collect( <source> )
Returns a list containing an item for each block- or line-comment in <source>
Comment delimeters (/* */ //
) are removed (although may appear in the comment itself)
Whitespace outside of comments may not be preserved exactly as it was in <source>
SEE ALSO
AUTHOR
Robert Krimen, <rkrimen at cpan.org>
SOURCE
You can contribute or fork this project via GitHub:
http://github.com/robertkrimen/string-comments-extract/tree/master
git clone git://github.com/robertkrimen/string-comments-extract.git PACKAGE
BUGS
Please report any bugs or feature requests to bug-string-comments-extract at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=String-Comments-Extract. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc String::Comments::Extract
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=String-Comments-Extract
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2008 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.