instaparse

If you're not trampolining your parser, why bother getting up in the morning?
2015-07-21T21:14:02.000003Z

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

socksy 2015-07-21T21:22:19.000004Z

you can use multimethods dispatching on node type

socksy 2015-07-21T21:25:05.000005Z

use a zipper to navigate the tree

socksy 2015-07-21T21:33:56.000006Z

or heck, just use https://clojure.github.io/clojure/clojure.walk-api.html

socksy 2015-07-21T21:35:10.000007Z

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

socksy 2015-07-21T21:36:02.000008Z

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

socksy 2015-07-21T21:36:44.000009Z

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

socksy 2015-07-21T21:37:03.000010Z

think I re-implemented postwalk also

socksy 2015-07-21T21:39:31.000011Z

seems instaparse you could maybe just use insta/transform

socksy 2015-07-21T21:40:04.000012Z

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

aengelberg 2015-07-21T22:16:36.000013Z

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

2015-07-21T22:21:12.000014Z

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.

2015-07-21T22:23:51.000015Z

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

aengelberg 2015-07-21T22:25:05.000016Z

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

aengelberg 2015-07-21T22:25:20.000017Z

Hey, that rhymes

aengelberg 2015-07-21T22:25:50.000018Z

@marcofiset Take a look at this section of the readme: https://github.com/engelberg/instaparse#transforming-the-tree

2015-07-21T22:36:12.000020Z

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 😃