Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • by chromatic (983) on 2003.03.13 12:46 (#17927) Homepage Journal

    I was interested to run across PMD [sourceforge.net], the software on which the Copy/Paste Detector runs. Though it's not possible to do that sort of static analysis in Perl, there are ways to do something very similar. I've resurrected my long-dormant bytecode-to-XML project.

    PMD uses treecc [southern-storm.com.au] to build an AST, then uses the Visitor pattern to call an event for each node in the tree. From there, he looks for specific patterns of nodes. It's a little tricky, but you can build up a sort of state machine.

    My code is B::SAX (no, it's not ready yet), which is like an inside-out Visitor. It throws events for each node in the tree. I just have to write a SAX handler that can check for patterns, a handler to transform bad patterns into good patterns, and a handler that mangles the output into something B::Deparse can understand.

    Yeah, there's a lot of hand-waving there, but the really hard part -- tokenizing Perl -- is done.