A playground for Piranha
Project description
PiranhaAgent
PiranhaAgent uses a static inference algorithm and OpenAI's GPT-4 model to generate human-like piranha rules from code examples. It generates these rules in TOML format, which can be applied to refactor other parts of the codebase.
Install
To get started with PiranhaAgent, follow these instructions:
pip install polyglot-piranha-playground
Usage (Playground UI)
To run the playground:
piranha-playground
To define your transformation rules, you will need to provide pairs of code snippets: 'before' and 'after' transformation. Each piece of code that needs transformation should be marked by unique identifiers surrounded by comments (like // 1
, // 2
, etc.). These identifiers serve two purposes:
- They denote which part of the code should be transformed.
- They define the transformation sequence, or cascading, i.e., which transformations should follow which.
Example
Consider the following code snippet:
Code before refactoring:
class SomeClass {
// 1 -> 2
// 1
void someMethod(String arg) {
}
// end
void otherMethod() {
String x;
// 2
someMethod(x);
// end
}
}
Code after refactoring:
class SomeClass {
// 1 -> 2
// 1
public String someMethod() {
}
// end
void otherMethod() {
String x;
// 2
x = someMethod();
// end
}
}
In this example, there are two transformation points, marked by the identifiers // 1
and // 2
.
// 1
shows the transformation fromvoid someMethod(String arg)
topublic String someMethod()
.// 2
shows the transformation fromsomeMethod(x)
tox = someMethod()
.
The arrow notation // 1 -> 2
indicates the transformation cascade, i.e., transformation // 2
should be applied after transformation // 1
.
Each transformation snippet begins with the identifier (like // 1
) and ends with a // end
comment.
This way of representing transformations helps to create clear, concise, and human-friendly refactoring rules, making it easier to manage and understand your transformations.
Make sure to follow these conventions when inputting your code for refactoring. Happy coding!
Note: The code before and after must be syntactically correct, and it should parse. Moreover, after applying the rules to code before, the refactored code should match the code after. (spaces are ignored).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file polyglot-piranha-playground-0.0.3.tar.gz
.
File metadata
- Download URL: polyglot-piranha-playground-0.0.3.tar.gz
- Upload date:
- Size: 34.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f941b178bea38f70953bbb46f1a03dfd23977ce1c878a9c40e30e4a4865ab90 |
|
MD5 | 21810e1954e0a86e9ac3a6c2da186c23 |
|
BLAKE2b-256 | 842ce906a83aab24a52723a1be0f416f0e8aba8f141c9a4f9fe052706089a41e |
File details
Details for the file polyglot_piranha_playground-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: polyglot_piranha_playground-0.0.3-py3-none-any.whl
- Upload date:
- Size: 50.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ccab0df879016d9e0f25dfaaf737dba3d46770477fd8bb6f65134ee03887de5 |
|
MD5 | 91129790ae21d3dac5d5c6d41f0f15e2 |
|
BLAKE2b-256 | e9244cd2d3e721b0c8d384d65985db96277c2f03953c3c456b26296da6956fb1 |