22

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.

7
  • "fix"? You mean identify the braces correctly, or somehow modify the source code? Commented Aug 10, 2010 at 20:39
  • @Ira: I'm looking for the first. Commented Aug 10, 2010 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. Commented Aug 11, 2010 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. Commented Aug 11, 2010 at 18:58
  • GumTree is a syntax-aware diff tool (via) Commented Jul 25 at 11:50

5 Answers 5

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.

Sign up to request clarification or add additional context in comments.

7 Comments

@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: 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: 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.
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: 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.
|
0

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

1 Comment

I'm using BC and I'm looking for something automatic.
0

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

1 Comment

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.
0

I like Source Gear's DiffMerge.

3 Comments

Agreed, I use this as well, it is a great tool.
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.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.