What’s a good way to replace single-line // input number comments with multi-line /* input number */ comments?
I don’t have any preference for the language used to accomplish the task; I was thinking of Perl or sed. The source language will be C (ANSI X3.159-1989).
Simple scripts like
while(<>) {
if (m#^(.*?)//#) {
print $1;
} else {
print $_;
}
}
would be fooled by strings containing // and are not OK. Similarly, // inside a multi-line comment should be left alone.
Edit: Code can assume that there are no trigraphs.
This is the opposite of replace C style comments by C++ style comments. It is similar to Replacing // comments with /* comments */ in PHP (though the accepted answer there cannot handle the special cases I mentioned and so is arguably wrong).
You can use boost::wave lexer’s output to replace all the c++ style comments to C style comments. without getting bothered about the edge cases.
For further documentation please see:
http://www.boost.org/doc/libs/1_47_0/libs/wave/index.html