cgmb / guardonce

Utilities for converting from C/C++ include guards to #pragma once and back again.
MIT License
142 stars 3 forks source link

Understand C++: Ignore comments #7

Open cgmb opened 11 years ago

cgmb commented 11 years ago

When searching through files, anything within comment blocks should be ignored as irrelevant.

cgmb commented 8 years ago

It seems that C gives you a surprising amount of flexibility in placing comments.

e.g.

/* comment */ # /* comment */ include /* comment */ <stdio.h> // comment
cgmb commented 8 years ago

It can be even worse...

/*
comment */ # /* comment */ include /* comment */ <stdio.h> /* comment
*/

In the smart parser, I've been stripping comments from the beginning and ends of the lines, because they're usually irrelevant once the code is changed. Unfortunately, it's a little unclear what to do when they span multiple lines. I suspect I should leave them alone. Multi-line comments are probably less likely to be specific to the line I'm removing than single-line comments are.

I've never actually seen this sort of code, but I could imagine it:

/* Copyright <Year> <Author>
   <License>
*/ #pragma once
cgmb commented 7 years ago

I should probably mention that the 'smart parser' was dropped in 3af39a7107029265d2ab2887f47823af41f3c15d. Not sure if or when I'll work on it again. It would certainly handle a few more weird cases, like the horror above, but I would basically only find out if it was worth the (significant) effort after the fact.