Fork me on GitHub
#instaparse
<
2015-07-21
>
marcofiset21:07:02

What are some approaches you guys use to interpret your parse tree?

socksy21:07:19

you can use multimethods dispatching on node type

socksy21:07:05

use a zipper to navigate the tree

socksy21:07:10

recommend using postwalk, and then writing a function to do whatever you’re thinking

socksy21:07:02

depends on how you want to eval, it’s a wee bit harder for compilation, but not much. You just need to make sure you emit a string. One solution would be to treat it as a side effect of whatever function you use

socksy21:07:44

admittedly, when I last did this I wasn’t using an instaparse’d parse tree, so maybe the technique varies a bit

socksy21:07:03

think I re-implemented postwalk also

socksy21:07:31

seems instaparse you could maybe just use insta/transform

socksy21:07:04

which must do a walk of the tree, and takes a map of node type to function

aengelberg22:07:36

@marcofiset insta/transform has always been sufficient for my use cases. Is there more sophisticated functionality you're looking for? If so, clojure.walk/[pre|post]walk might be the next step up.

marcofiset22:07:12

I am not looking for anything particular, just wanted to start a discussion on the subject. I'm using multi methods for the moment and I was curious about what other people might be using.

marcofiset22:07:51

I didn't know about insta/transform, I'll definitely take a look.

aengelberg22:07:05

Yeah, instaparse.core/transform is a simple function that does the trick for simple parse tree consumption.

aengelberg22:07:20

Hey, that rhymes

marcofiset22:07:12

Wow, I'm really impressed with the arithmetic example! Very straightforward and simple. My multi methods solution is going to the trash and will be replaced by something similar 😃