Fork me on GitHub
#instaparse
<
2021-06-14
>
markaddleman17:06:26

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-sora18:06:36

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

aengelberg18:06:06

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

aengelberg18:06:40

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

aengelberg18:06:22

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

markaddleman18:06:49

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

aengelberg18:06:11

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

markaddleman18:06:16

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

aengelberg18:06:50

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

markaddleman01:06:04

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

aengelberg18:06:16

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

markaddleman18:06:37

hm. thanks. I'll give it a try