instaparse

If you're not trampolining your parser, why bother getting up in the morning?
markaddleman 2021-06-14T17:24:26.012100Z

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...

aengelberg 2021-06-14T18:13:06.013Z

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

aengelberg 2021-06-14T18:13:40.013500Z

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

aengelberg 2021-06-14T18:14:22.013900Z

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

markaddleman 2021-06-14T18:15:49.015100Z

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

aengelberg 2021-06-14T18:17:11.015800Z

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

markaddleman 2021-06-14T18:18:16.016400Z

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

aengelberg 2021-06-14T18:18:50.017Z

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

markaddleman 2021-06-15T13:53:56.000100Z

Thank you!

aengelberg 2021-06-14T18:19:16.017300Z

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

markaddleman 2021-06-14T18:20:37.017600Z

hm. thanks. I'll give it a try