Fork me on GitHub
#instaparse
<
2018-05-27
>
Logan Powell18:05:50

👋 Hi everyone!

akiroz19:05:47

@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

Logan Powell19:05:31

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

Logan Powell19:05:51

I'm converting it to markdown

akiroz19:05:07

just print it to string

Logan Powell19:05:26

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

akiroz19:05:52

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

Logan Powell19:05:07

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

akiroz19:05:35

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

akiroz19:05:10

manipulate the data as much as you want then print it

Logan Powell19:05:25

hmm... let me give that a shot!

akiroz19:05:27

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

Logan Powell19:05:03

I'm using cljs, works the same?

akiroz19:05:34

you mean the read part or analyser?

akiroz19:05:58

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

akiroz19:05:07

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

Logan Powell19:05:32

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

akiroz19:05:49

it's built-in

Logan Powell19:05:07

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

Logan Powell19:05:01

do I use core.match with this?

akiroz19:05:55

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

Logan Powell19:05:33

it looks as so, you're right

akiroz19:05:33

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

Logan Powell19:05:43

ok, let me give it a go

aengelberg20:05:57

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

aengelberg20:05:21

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