21

Are there any (ideally GUI) diff tools that are aware of syntax?

As an example of the kind of thing I'm looking for, I keep finding that my current tool miss aligns repetitive code:

Foo  = { 'hello': 'world',    |  Foo  = { 'hello': 'world',
         'goodnight': 'moon'  |           'goodnight': 'moon'  
       }                      <
                              <
Bar  = { 'picture': 1000,     <
       }                      |         }

I'd like a tool that would try and make matching braces on one side align with matching braces on the other.


Edit: I'm looking for a tool that can automatically spot that condition and correct it's alignment.

BCS
  • 75,627
  • 68
  • 187
  • 294
  • "fix"? You mean identify the braces correctly, or somehow modify the source code? – Ira Baxter Aug 10 '10 at 20:39
  • @Ira: I'm looking for the first. – BCS Aug 10 '10 at 21:27
  • Based on discussion in other answers, BCS appears to want only either a fix to BeyondCompare, or a must-be GUI-based syntax aware differ tool. – Ira Baxter Aug 11 '10 at 16:58
  • @Ira, what I want is a *text* diff tool that uses syntax as hints rather than a syntax diff tool that presents it's results as a text diff. – BCS Aug 11 '10 at 18:58

5 Answers5

5

Not GUI based, but completely syntax driven: my company's Smart Differencer tools for many langauges (incluiding Java, C#, C++, PHP, Python, JavaScript, HTML, XML, COBOL,...)

The Smart Differencer parses the source text like the compiler, so it understands that language syntax and structures the way the compiler does. It compares these structures (using ASTs) to determine the "least edit distance" in terms of edit actions (move, copy, delete, replace, rename-identifier-in-block) on these structures and report them.

In your example, it would know the curly brace on the right belongs to foo, not bar, and would tell you that the entire statement involving bar was simply deleted.

The output style is diff-like if you want to feed the result to another tool, or more human readable if you want to examine it directly.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Sounds really neat, but both over kill and not exactly in the right direction. – BCS Aug 10 '10 at 19:21
  • 3
    @BCS: Dunno about overkill. If you don't pick up the language structures, you can't match them; I don't know of any alternatives that can come close unless all you want is just bracket matching. What's not the right direction part? – Ira Baxter Aug 10 '10 at 20:41
  • 1
    @Ira: bracket matching and (similar alignment hinting rules) is all I want (I guess "syntax aware" is a little strong for what I'm looking for) and I'm wanting a text diff, just one that does a better job of figuring out what's new vs. old. – BCS Aug 10 '10 at 21:30
  • 1
    @BCS: I'm puzzled. If you *really* want better identification of new vs. old, you *really* want the syntax-driven comparison, because it provides descriptions in terms of what the programmers (reviewers?) understand. "You deleted the statement involving bar" seems pretty descriptive of the change you exhibited. – Ira Baxter Aug 10 '10 at 21:38
  • 1
    What I want is "Line 127 became line 134" in a reasonably language agnostic form. Given that it would be driving a GUI, not dumping text, anything else would need to be munged into that anyway with all the disambiguations heuristics that requires. – BCS Aug 11 '10 at 00:10
  • 1
    @BCS: Go check the examples provided at the website. For a move, it produces diffs with detail line and column information L:C which I'll designate P,Q,R,S here. For a delete, it says range P-Q is deleted; for a move you get "Moved range P-Q to range R-S". You can ignore the column data if you want, etc. There's an output that can drive a GUI; see the COBOL GUI example for SmartDifferencer. – Ira Baxter Aug 11 '10 at 02:32
  • The problem is, I already have something (Beyond Compare) close to what I want but it's missing something. While the program you mention seems to be able to do that something, it's also missing a few things (GUI, etc.) that I want and (and this is a significant point) it has a bunch of things I don't care about. I might live with some lacks or excesses but not both. – BCS Aug 11 '10 at 04:38
0

The Pretty Diff tool is syntax aware automatically. The process it uses is to minify code in order to remove comments and then beautify the code so as to normalize formatting and white space. It only supports a few web client-side languages though. This tool works on the client side so you can test it out in your browser and there is a sample page containing some demos.

austincheney
  • 1,189
  • 9
  • 11
0

Beyond Compare will let you realign lines that it mismatches. I generally have good luck with it matching lines properly.

JYelton
  • 35,664
  • 27
  • 132
  • 191
0

I think Beyond Compare has what you are looking for http://www.scootersoftware.com/index.php

Jake1164
  • 12,291
  • 6
  • 47
  • 64
  • I'm using BC and while it lets me fix the alignment by hand (not what I'm looking for), I don't know how to make it do it automatically. – BCS Aug 10 '10 at 17:42
0

I like Source Gear's DiffMerge.

Nick
  • 13,238
  • 17
  • 64
  • 100
  • Agreed, I use this as well, it is a great tool. – Barlow Tucker Aug 10 '10 at 16:09
  • I don't see any indication in the docs of what I'm looking for. It can define matching elements but it doesn't seem to allow them to nest and it doesn't say that it uses them as alignment hints. – BCS Aug 10 '10 at 17:51