python-client icon indicating copy to clipboard operation
python-client copied to clipboard

Convert a UAST into Python AST

Open pcyin opened this issue 7 years ago • 7 comments

Hi. I am new to bblfsh and was wondering if I could convert a UAST into Python's AST structure defined by the ast module. Thanks!

pcyin avatar Mar 30 '18 16:03 pcyin

Hi @pcyin. The short answer: it's not possible at the moment.

Can you share more information about your use case?

It looks like you are parsing Python sources (since you want python AST at the end) from Python (since you are using this client). If it's the only use case, it will be easier for you to use Python parser itself, without Babelfish server.

On the other hand, if you want to convert any AST to Python AST, then the problem is on a totally different level. We are currently working on a new implementation of UAST that might make this conversion possible.

dennwc avatar Mar 30 '18 19:03 dennwc

If the problem is getting the Python AST you can use ParseNative instead of parse.

juanjux avatar Mar 30 '18 19:03 juanjux

@juanjux But it will not be directly compatible with Python's ast module in this case.

dennwc avatar Mar 30 '18 19:03 dennwc

It's the same structure with added positions in some cases and json format.

juanjux avatar Mar 30 '18 19:03 juanjux

Sure, the structure is the same, but these object will not be of a class ast.AST defined in mentioned Python module. This might make a difference in some cases.

dennwc avatar Mar 30 '18 20:03 dennwc

Closing, as the question seems to be answered and there is no further discussion. But please, feel free to re-open if that is not the case.

bzz avatar Jan 24 '19 14:01 bzz

I think it's relevant, but it should be addressed in SDK first: https://github.com/bblfsh/sdk/issues/352

dennwc avatar Jan 29 '19 15:01 dennwc