GumTreeDiff / gumtree

An awesome code differencing tool
https://github.com/GumTreeDiff/gumtree/wiki
GNU Lesser General Public License v3.0
916 stars 173 forks source link

gumtree implementation in swift programming language #164

Open aminul7506 opened 5 years ago

aminul7506 commented 5 years ago

How can I implement gumtree for swift programming language using the existing codebase ? Should I implement a swift AST in java for this ?

jrfaller commented 5 years ago

Hi! It would be a nice feature! There are two solution, depending on if a parser for swift exists in Java. In this case you can use the parsers API to generate an AST compatible with Gumtree (see how it is done for instance in the module gen.js that uses Rhino. If this is not the case, you'll have to build an external tool that produces a XML file compatible with Gumtree, this how it's done in the gen.c module for instance. Which parser do you want to use?

aminul7506 commented 5 years ago

A parser for swift does not exist in Java but we have a parser for swift written in swift from https://github.com/yanagiba/swift-ast . I want to use this AST for swift. For this what should I do ? Should I make a tool from this swift AST that produces gumtree compatible XML file ? It would be helpful for me if you tell me about this.

jrfaller commented 5 years ago

Yes you have to make an executable tool that uses your parser to produce a XML compatible with GumTree!

You can take a look to the format here (in testSerializeTree()): https://github.com/GumTreeDiff/gumtree/blob/develop/core/src/test/java/com/github/gumtreediff/test/TestTreeIoUtils.java

You can look how to implement the adapter here : https://github.com/GumTreeDiff/gumtree/tree/develop/gen.c/src/main/java/com/github/gumtreediff/gen/c

Good luck with that!

aminul7506 commented 5 years ago

Thank you sir. I am trying this.

aminul7506 commented 5 years ago

Sir, can you please tell me what is Type, Label , Length and Position of a Node with an example?

jrfaller commented 5 years ago

For instance consider the Python code v = 12;

We have the following tree :

Therefore, type: lexical category of the node value (only valid for leaf nodes): associated value (for instance v for the NameStore or 12 for the Num pos: absolute position (number of elapsed characters) of the beginning of the node in the text file length: length of the node in the text file, in characters (we have end_pos = pos + length)

Cheers!

aminul7506 commented 5 years ago

Another question. Where I have to install cgum for seeing the diff for C programme? I am trying to see the C programme diff in gumtree but failed

jrfaller commented 5 years ago

Hi! cgum is here : https://github.com/GumTreeDiff/cgum

But if it's easier you can also look into the gen.python and https://github.com/GumTreeDiff/pythonparser tools that does exactly the same also. I just fixed these two yesterday so they use all the good practices for implementing an external generator.

Cheers!

jrfaller commented 4 years ago

Hi! Any progress on this issue? Cheers!

jrfaller commented 2 years ago

Hi @aminul7506!

If you are still interested by having Swift into GumTree I think I can use the tree sitter parser easily now?