[CMake] Regular Expression to filter out C/C++ Comments

Andreas Lubensky theNfan at gmx.de
Mon Feb 22 17:36:25 EST 2010


Am Montag, 22. Februar 2010 17:29:08 schrieben Sie:
> On Mon, Feb 22, 2010 at 04:28:54PM +0100, Andreas Lubensky wrote:
> > i'm having some trouble building a regular expression to filter out C
> > and C++ style comments (//... /*...*/).  I constructed various regular
> >
> > "((/\\*([^\\*]|(\\*+([^\\*/])))*\\*+/)|(//[^\r\n]*))"
> 
> I don't think RE are the right tool for this job. You probably want a
> little state machine instead (something like 'while (token != '*/') {
> skip_token() }).
> 
> Why are you trying to do this? Can you do the parsing in a "real"
> scripting language instead of in CMake?
> 
> tyler
> 
Hello,
it's already hard enough to convince people to pull in CMake (dependencies 
omg!!1).

While regular expressions may not be perfect for this task, they should work, 
at least i've found many examples in other languages for my problem.
The alternative would be to write a full blown lexer and that seems pretty 
over the top.

CMake just seg faulting seems pretty bad. Might it be a bug after all?


More information about the CMake mailing list