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 Expr to CST #281

Open
Roger-luo opened this issue May 23, 2021 · 3 comments
Open

convert Expr to CST #281

Roger-luo opened this issue May 23, 2021 · 3 comments

Comments

@Roger-luo
Copy link

Hi, I come accross from domluna/JuliaFormatter.jl#414

I'm thinking about using JuliaFormatter as the pretty printer of Julia Expr objects, thus I need to convert things to CST objects it uses, I'm wondering if there is an API for this? or if there are related works on this?

@pfitzseb
Copy link
Member

This definitely isn't possible at the moment. While a CSTParser.EXPR has a head and args like a normal Expr and is easily convertible to the latter, it does have additional info that can't be recovered from the AST.
It should be possible to work around that for your case (where you never had any textual representation to begin with), but seems like a fair bit of work.

@Roger-luo
Copy link
Author

I guess one workaround could be print Expr to string then parse it back using CSTParser ? sounds evil but might work I guess.

@domluna
Copy link

domluna commented May 26, 2021

The text representation won't be lossless but I think most of the time it would give you something you could be happy with.

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

3 participants