Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including PLSQL #359

Open
MariusKochFHDW opened this issue Jun 26, 2024 · 15 comments
Open

Including PLSQL #359

MariusKochFHDW opened this issue Jun 26, 2024 · 15 comments
Assignees

Comments

@MariusKochFHDW
Copy link

Hey there,

i was just set on a new Project to find a difftool for PLSQL and i recently found gumtree. I already have the antlr4 grammar and parser for PLSQL and have a python script to generate an AST. I already seen the tree-sitter but can't really figure out how to do it.

Thank you in advance :)

@jrfaller
Copy link
Member

Hi! Can you find the parser you want here : https://github.com/bonede/tree-sitter-ng ? Cheers.

@MariusKochFHDW
Copy link
Author

No, unfortunatly there isn't any supported parser for this programming language.

@jrfaller
Copy link
Member

Is there any tree-sitter parser you know that might do the trick ?

@MariusKochFHDW
Copy link
Author

MariusKochFHDW commented Jun 26, 2024

I dont see any. Is there another trick i can use to integrate it?

@jrfaller
Copy link
Member

so maybe you try the antlr-4 integration but I have never really used it seriously

@MariusKochFHDW
Copy link
Author

Where can i find it?

@jrfaller
Copy link
Member

We have a helper here -> https://github.com/GumTreeDiff/gumtree/blob/main/gen.antlr4/src/main/java/com/github/gumtreediff/gen/antlr4/AbstractAntlr4TreeGenerator.java But I have no sample project to showcase how to use it 😢

@MariusKochFHDW
Copy link
Author

Thank you for the response :)
I will have a look at it and tell you if it works.

Hoping for the best 😄

@jrfaller
Copy link
Member

Maybe look at how we do for antlr 3 projects like this -> https://github.com/GumTreeDiff/gumtree/tree/main/gen.antlr3-r

@MariusKochFHDW
Copy link
Author

Hey there again!

I just tried a bunch of stuff and came to the conclusion that the best/easiest way for me to implement PLSQL into Gumtree is the following:

  1. I'm using the antlr4 Lexer and Parser to generate a AST in the form of the antlr4
  2. From there i would love to just send it to either the API or a Method that can handle the antlr4 AST and format it into the XML format gumtree can handle.

Is there some kind of Method or API call that does the trick?
Im pretty new to coding so i hope i didnt overlooked anything importent.
Thankss :)

@jrfaller
Copy link
Member

Hi! Normally if you have a antlr4 grammar you should be able to skip the XML part and use directly the antlr generated objects to convert them to a GumTree AST it would be much more efficient?

@jrfaller jrfaller self-assigned this Jun 29, 2024
@MariusKochFHDW
Copy link
Author

Hello again,
i just cant find any way to get it running.
FYI:
I'm producing a AST in python for PLSQL with a grammar i had to optimize a little bit. I tried to run the python script within the gumtree webdiff -x build_tree.py build_tree2.py.
I gave it another shot with trying to use the -... g antlr-antlr example.pkh. It starts the server but there isn't any diff that happend.

Can you give me a detailed explaination how to use the convert the generated objects to GumTree ASTs and then have a detailed Diff for them?
Thank you in advance :))

@jrfaller
Copy link
Member

jrfaller commented Jul 1, 2024

Hi! Once you have converted your parser specific format to GumTree's agnostic format (a Tree and a TreeContext) every other things come for free (such as the diff :D). For antlr3 grammars it is done via subclassing our helper class like here : https://github.com/GumTreeDiff/gumtree/blob/main/gen.antlr3-r/src/main/java/com/github/gumtreediff/gen/antlr3/r/RTreeGenerator.java . I have no such example for antlr4 grammars but as far as I can see you have 3 methods to override here https://github.com/GumTreeDiff/gumtree/blob/main/gen.antlr4/src/main/java/com/github/gumtreediff/gen/antlr4/AbstractAntlr4TreeGenerator.java (and also don't forget to add the annotation to register the parser, as done in the antlr3 example). For the webdiff command it's trickier because you have to include the antlr4 projects in the distribution here : https://github.com/GumTreeDiff/gumtree/blob/main/dist/build.gradle . Sorry this a lot of stuff to do 😢

@MariusKochFHDW
Copy link
Author

Hey man, almost everything done!
I created a antlr3 folder and put an old grammar in there and registered everything.
It works just like i hoped. The only issue is, that for bigger files (200KB+) the hilighting is getting offset to the text it's marking :(
Is there any way to fix it? Otherwise it's something we can live with :)

Thank you a lot for your help
Cheers!

@jrfaller
Copy link
Member

jrfaller commented Jul 2, 2024

Hi! Very good news! It's strange that you have offsetting problems I think it might come from the parser or the helper. It requires some debugging to understand why the position is wrong (fairly easy to do with a breakpoint if you know the grammar well). Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants