instaparse 2021-06-14

Does instaparse support round tripping? I have a string-based language that I want to manipulate. I'd like to parse it, manipulate the parse tree using meander and then generate a new string from the parse tree

sova-soars-the-sora 2021-06-14T18:12:36.012600Z

I think it's possible. I don't know what meander is...

there isn’t a way to “unparse” though that’s been requested a few times

you could write your own “unparser” that leverages insta/transform and implements a different string-reconstruction logic for each tag in your grammar

assuming you don’t use the “hide” rule (`<>`), those implementations would basically just be str

thanks. I may be signing myself up for a world of hurt but my current approach is to use clojure spec to generate the parse tree and then unform to "unparse" it

instaparse will almost certainly be a better fit than clojure spec to do the initial parse, though I see why you’d want to use a library that gives you an “undo” function

yeah, i feel like this is a no-win situation

I don’t think writing your own un-parser would be too challenging

Thank you!

You were right. Using parse options :unhide :all , I can easily use meander to unparse the parse tree

since it’s mostly putting strings back together from a recursive tree

hm. thanks. I'll give it a try