Miscount of C++ comments
Brought to you by:
alnd
Hi, cloc (v1.60, 1.62) seems to miscount C++ comments in some case.
1) For attached sample.cpp,
the expected is blank:2, comment:16, code:2,
but the result is blank:2, comment:11, code:7 .
2) When we change the filter order in the language definition file as follows:
C++ filter call_regexp_common C filter remove_matches ^\s*// filter remove_inline //.*$
then the result is blank:2, comment:15,code:3 .
3) When we change the filter as follows:
C++ filter call_regexp_common C++
then the result is blank:2, comment:17,code:1 .
(line 11 and 12 are combined into one line "code1code2")
Is there some workaround for this problem ?
Thank you,
tksh
Anonymous
As far as I investigated the code,
only one filter "call_regexp_common C++" as in 3) should work well
because Regexp::Common supports both of inline "//" and multi-line "/ /" comments.
The problem is probably that Regexp::Common removes "\n" from an inline comment line.
The modification below seems to work well.
Last edit: tksh 2014-10-31
I tested your mod to sub to_eol() from Regexp::Common and simplified the language filter to just use Regexp::Common's C++ but that still returned blank:2, comment:17, code:1.
The lines are still joined into a single "code1code2". This is with Perl 5.18.0. Still scratching my head on this one.
Did you confirm that $HAVE_Rexexp_Common = 0 ?
Attached is my test.
Sorry for the delay, but I've just now gotten around to fixing this. As the code now lives on github, you can test the change by grabbing the code from https://github.com/AlDanial/cloc/blob/dev/cloc.