instaparse

If you're not trampolining your parser, why bother getting up in the morning?
2018-05-27T18:50:50.000111Z

👋 Hi everyone!

2018-05-27T18:58:08.000012Z

I'm completely new to both instaparse and EBNF. Right now, I'm trying to create some docs that show the difference in core.async between Clojure and ClojureScript. I started by manually looking through the code in each repo and translating the available defns to markdown to show a simple matrix of which features/primitives are available in the cooresponding libraries. Of course I started thinking: "I could use some regex to do this, can't I?" I then asked myself "is there a better way in Clojure?" and found instaparse. Can anyone refer me to a good guide for building my own "EBNF" grammar?

2018-05-27T19:01:53.000073Z

btw, http://instaparse-live.matt.is/ is awesome

2018-05-27T19:08:47.000036Z

@loganpowell Why not just read the clojure code as data? I mean lisp code IS data, there's no need to deal with string parsing

2018-05-27T19:09:31.000006Z

how would I pull out the pieces of the function definitions as strings?

2018-05-27T19:09:51.000097Z

I'm converting it to markdown

2018-05-27T19:10:07.000140Z

just print it to string

2018-05-27T19:10:26.000065Z

haha, I'm very stupid. That's a great idea

2018-05-27T19:10:52.000025Z

you might want pprint actually, since it's for docs

2018-05-27T19:11:07.000082Z

ok, so I get the string that way, then how do I pull out the specific parts of that string that I need?

2018-05-27T19:11:35.000064Z

well first parse the whole thing into data with the built-in read function

2018-05-27T19:12:10.000028Z

manipulate the data as much as you want then print it

2018-05-27T19:12:25.000062Z

hmm... let me give that a shot!

2018-05-27T19:13:27.000099Z

@loganpowell if you need more advanced code analysis, check out tools.analyzer

2018-05-27T19:13:38.000001Z

https://github.com/clojure/tools.analyzer

2018-05-27T19:14:03.000109Z

I'm using cljs, works the same?

2018-05-27T19:14:34.000084Z

you mean the read part or analyser?

2018-05-27T19:14:45.000027Z

both

2018-05-27T19:14:58.000013Z

former is called cljs.reader/read-string in cljs

2018-05-27T19:15:07.000060Z

latter I have no idea if it works in cljs (I'm gonna guess no)

2018-05-27T19:16:32.000006Z

is reader a part of core or do I need to add it as a :dependency?

2018-05-27T19:16:49.000024Z

it's built-in

2018-05-27T19:16:55.000101Z

cool

2018-05-27T19:18:07.000055Z

it's working 🙂 I was getting all excited about instaparse... now I have to calm down my curiosity and get to work 😄

2018-05-27T19:19:01.000012Z

do I use core.match with this?

2018-05-27T19:19:55.000081Z

Haha, I suppose building a parser yourself would be a great learning exercise too.... but code grammar is a bit complex.

2018-05-27T19:20:33.000003Z

it looks as so, you're right

2018-05-27T19:20:33.000041Z

You can use whatever tools you want to process the data, it's just a list

2018-05-27T19:20:43.000126Z

ok, let me give it a go

aengelberg 2018-05-27T20:44:57.000068Z

yeah, Instaparse only aims to help turn strings into data, so if you already have a way to do that (`read-string`) then instaparse won't be much help

aengelberg 2018-05-27T20:45:21.000031Z

the "analysis" of your resulting data is always left as an exercise to the reader anyway 🙂