in reply to Stripping Comments from Source

Rolf, thanks for the pointers. B::Deparse appears not to be useful here since the PDK compiles the code into an undocumented mash of things - not a pure intermediate code for sure. PerlNET keeps the complete source inside the compiled PerlNET exe or dll target, at least when building with debug information. This is visible when debugging a PerlNET application, as the debugger can actually show the full source code, calling it a "remote" file, without opening the perl source that was used for the build. I would be content if I could confirm that the non-debug PerlNET build only stores B code.

perltidy looks promising and we are testing it right now. I will report back when done.

sierpinski, thanks for the comment. As Rolf already indicated, a stripping script can easily handle simple formats, but it becomes fairly complicated to try to handle all cases. And yes, the code is complex, a lot of smarts in the algorithms that need commenting for maintenance, and the code goes through multiple revision/distribution cycles.

JavaFan, the comments may contain material that is not appropriate for public view, either an explanation about a complex and proprietary business logic or personal comments among the dev team members. We need to verify a sanitized code before distribution.
Now, since the debug build of PerlNet contains the source code, and its format is undocumented, I can not risk the content of the release build without a good reference - so I want to strip the comments.


UPDATE: perltidy looks like a great tool, and has a delete all comments option (-dac). I just tried it on my otherwise working script and it gave a fatal parsing error. It seems the perltidy parser is not 100% the same as perl. Still, if all else fails I would consider manually simplifying the code to be compatible with perltidy.

Replies are listed 'Best First'.
Re^2: Stripping Comments from Source
by LanX (Saint) on May 12, 2010 at 14:27 UTC
    OK ....I have to admit that I have no clue how "PDK compilations" look like...

    IMHO processing the perlsources before piping them into another make/compilation process should be safe!

    HTH!

    Cheers Rolf

      Your comments were most helpful. Thank you.

        Have a look at PPI::Document, too:

        #!/usr/bin/perl use strict; use warnings; # Straight from the documention use PPI; # Load a document from a file my $Document = PPI::Document->new('My/Module.pm'); # Strip out comments $Document->prune('PPI::Token::Comment'); # Strip out Pod $Document->prune('PPI::Token::Pod'); # Save the file $Document->save('My/Module.pm.stripped');

        Hth, Thomas

        Udate: Added code to strip Pod