lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.75k stars 401 forks source link

Canonical way to convert dicts / lists to trees, like transform(), but in reverse? #1299

Closed NeoVG closed 5 days ago

NeoVG commented 1 year ago

Hello everybody.

Is there a canonical way to implement something like a transformer, but in reverse? Basically something where I can feed a dict or list into and get a Tree back, which I then can feed into Reconstructor().reconstruct() to generate text.

Thanks in advance!

erezsh commented 5 days ago

Currently there is no standard way to convert a Lark tree into a dict/list/json, and so I don't know what the reverse would look like.

But I believe you could write a custom function in a few lines. Let me know if you need advice on that.

Sorry for the late response.