Menu

#4 Help with filters

v1.0_(example)
closed
nobody
None
3
2015-06-27
2013-10-18
Anonymous
No

How do I code the filters for multi-line comments that start with #+ and end with #-? If you compare this to C, you can say that "/" = "#+", and "\" = "#-".

Discussion

  • Al Danial

    Al Danial - 2013-10-18

    interesting... your question ended up revealing a bug in cloc. My initial answer was going to be "yes, just use the remove_between_general directive". However when I ran with

    cloc --write-lang-def=lang.txt
    

    to make a custom file I could modify, I noticed only start-of-comment markers appear; the end-of-comment marker is missing. Your definition should look something like:

    YourLangName
        filter remove_between_general #+ #-
        filter call_regexp_common C
        extension yourFileExt
        3rd_gen_scale 1.00
    

    but doubtful that will work until I fix the bug.

    Another alternative is to modify the cloc source code to handle your language. If you're working with the source version instead of the .exe, I can explain how to do that.

     
  • Anonymous

    Anonymous - 2013-10-18

    I am working with the exe file. If you talk me through using the source version, I would be happy to give it a try.

    Here's the complete definition that I'm using. The language (Siemens NX Knowledge Fusion DFA) is pretty obscure, but I happen to be evaluating several applications that are written in it. The language also uses "#" as a comment character. It works like C++'s "//".

    dfa
    filter remove_between_general #+ #-
    filter call_regexp_common C
    filter remove_matches ^\s#
    filter remove_inline #.
    $
    extension dfa
    3rd_gen_scale 1.00

    When I use the remove_between_general, I receive a lot of "Use of uninitialized value in quotemeta at cloc-1.60.exe line 3791." messages.

     
  • Al Danial

    Al Danial - 2013-10-18

    OK, for starters you'll need a Perl interpreter installed on your Windows box, something like Strawberry Perl or ActiveState Perl (ActivePerl). Once you have that, pull the latest cloc source code from subversion (https://sourceforge.net/p/cloc/code/HEAD/tree/trunk/cloc) and save it to a file called 'cloc.pl'.
    Use a text editor to modify cloc.pl in the following way:

    First add an entry for your language extension. Look for a line that starts with
    "%{$rh_Language_by_Extension} = (" and put your dfa extension to language name after it:

    %{$rh_Language_by_Extension} = (
             'dfa' = 'dfa',
    

    Next add your language filters below the line that starts with "%{$rhaa_Filters_by_Language} = ("

    %{$rhaa_Filters_by_Language} = (             # {{{1
                'dfa'    => [
                                [ 'remove_matches'      , '^\s*#' ],
                                [ 'remove_between_general', '#+', '#-' ],
                                [ 'call_regexp_common'  , 'C'     ],
                                [ 'remove_inline'       , '#.*$'  ],
                            ],
    

    Finally, below "%{$rh_Scale_Factor} = (" add your language scale factor:

    %{$rh_Scale_Factor}          = (
            'dfa'     =>   1.00,
    

    Let me know how that works out.

     
  • Anonymous

    Anonymous - 2013-10-18

    Thank you very much. It works perfectly!

     
  • Al Danial

    Al Danial - 2013-10-18

    cool

     
  • Al Danial

    Al Danial - 2013-10-18
    • status: open --> pending
     
  • Al Danial

    Al Danial - 2015-06-27
    • status: pending --> closed
     
  • Al Danial

    Al Danial - 2015-06-27

    v1.64 released

     

Anonymous
Anonymous

Add attachments
Cancel