Git Product home page Git Product logo

tree-sitter-gumtree's Introduction

A Tree-Sitter - Gumtree Differentiation Co-package

This project is dedicated to get tree-sitter parser to work with gumtree conveniently by python interface with help of networkx.

Running

Download Jars file

Download the jars.zip and unzip into jars folder

Clone and Init submodules

git clone https://github.com/datvo06/tree-sitter-gumtree
git submodule update --init --recursive

Install requirements

pip install tree-sitter
pip install networkx

Example

Get map by line

Given 2 files as follows:

// File 1
#include <stdio.h>

int main(int argc, char** argv){
		int a = 2;
		int b = 3;
		a = a + b;
		for (int i = 0; i < 3; i++){
				a += 1;
		}
		printf("Hello, World! %d\n", a);
		return 0;
}

and

// File 2
#include <stdio.h>

int main(int argc, char** argv){
		int a = 2;
		int b = 3;
		b = a + b;
		int c = a - b;
		for (int i = 0; i < 3; i++){
				a += 1;
		}
		printf("Hello, World! %d\n", a);
		return 0;
}
python3 get_mapping_by_line <file1> <file2> <out_file>
python3 get_mapping_by_line selfunittests/file1.cpp selfunittests/file2.cpp out.json

This will give you the following results:

{
    "mapping": {
        "1": 1,
        "3": 3,
        "4": 4,
        "5": 5,
        "6": 6,
        "7": 8,
        "8": 9,
        "9": 10,
        "10": 11,
        "11": 12,
        "12": 13
    },
    "deleted": [],
    "inserted": [
        7
    ]
}

Note that the empty lines are removed.

Interfacing and usage

The self unit test scripts can be found in `selfunittests/test_parse', and ran by

python -m selfunittests.test_parse

Additional Info

Json object format for communicating between jars file

(In case we wish to use the jar alone)

Single json dict for description of an AST Tree:

  • The input to ast_diff.jar is as follows:
"file1":{
	"nodes" {
		{
			"1": {
				"ntype": "identifier",
				"token": "a",
				"start_line": 1,
				"start_col": 1,
				"start_pos": 1,
				"end_line": 1,
				"end_col": 1,
				"end_pos": 1,
				"parent": -1
			},
			"size": 1
		}
	},
"file2": {
	...
}
}

and it will output the following

{
	"srcNodes":{
			{
				"id": 0,
				"parent_id": -1,
				"type": "MethodCallExpr",
				"label": "nodeToJson",
				"range": {
					begin: {
						"pos": 0,
						"line": 1,
						"col": 0
					}
					end: {
						"pos": 6022,
						"line": 195
						"col": -1
				}
			}
		},
	},
	"dstNodes":{
	 ...
	},
	"mapping":{
		"1" : 1, // Id mapping
		...
	},
	"inserted": {
		2, 3, 4...
	},
	"deleted": {
		0
	}
}

tree-sitter-gumtree's People

Contributors

datvo06 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.