Hey,
So I'm searching for smarter answer to a diff parser I'm writing. I'm writing a custom beatification program that uses Artistic Style to satisfy part of its needs.
The code has to have standardized ugly-code warning message. But, AStyle doesn't produce an output of changes it makes, so I'm using diff on the before and after code to figure out what's changed.
How would you do it?
My pseudocode, if you're interested:
Right now, I'm converting each line that diff highlights in the "before changes" into a regex pattern. In my Python parser, I've got two lists: before_change and after_change. before_change contains lines (as strings) of "before changes" code that diff produces, and after_change contains those of "after changes".
Basically I convert every line in before_change into a regex expression, and check to see if it's matches any in after_change. On a match, I delete both entries from the lists to prevent redundant matches. I also ignore any blank lines, and lines containing only curly braces.
I'm not happy with my code. It's too verbose, and not as robust as I want. I can see possible issues with repeated keywords:
1. short lines like
would match up with
Code:
doFunction1(x); //and
doFunction2( doFunction1(x)) ;
OR
2. simple lines like
would match
Code:
} else { and
} else { //(that are similar but belong to different groups of statements)
Any tips?
Thanks.