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

Convert AST from OCaml to Python #5

Open
ArulselvanMadhavan opened this issue Jan 25, 2023 · 2 comments
Open

Convert AST from OCaml to Python #5

ArulselvanMadhavan opened this issue Jan 25, 2023 · 2 comments

Comments

@ArulselvanMadhavan
Copy link

Hi, Thanks for making this work public! I'm interested in using this project to get the AST of python code represented in OCaml, modify the AST, and write the AST back as python code.

  1. Is there a way to convert the AST represented as OCaml value to be converted into python AST - so I can use ast.unparse() to write the python source code?
  2. If the above method is too tedious, is the only other option to write a printer for the AST in OCaml that spits out python code? This creates potential mismatch with python ast module
@grievejia
Copy link
Owner

grievejia commented Feb 8, 2023

Unfortunately I did not include any logic to re-convert the OCaml values back into the Python layer. In theory this can be done, but it's going to require as much code as I have for the parser. I do not have plan to take on such workload any time soon, as the initial intended purpose of this project is a uni-directional conversion from Python AST to OCaml and not the other way around.

And you are correct that it's also possible to serialize the OCaml AST from OCaml directly, with the caveat that the output may not fully match ast.unparse().

@ArulselvanMadhavan
Copy link
Author

@grievejia Thanks for your response! I went ahead and made one - https://github.com/ArulselvanMadhavan/opine

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

No branches or pull requests

2 participants