👋 Hi everyone!
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 defn
s 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?
btw, http://instaparse-live.matt.is/ is awesome
@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
how would I pull out the pieces of the function definitions as strings?
I'm converting it to markdown
just print it to string
haha, I'm very stupid. That's a great idea
you might want pprint
actually, since it's for docs
ok, so I get the string that way, then how do I pull out the specific parts of that string that I need?
well first parse the whole thing into data with the built-in read
function
manipulate the data as much as you want then print it
hmm... let me give that a shot!
@loganpowell if you need more advanced code analysis, check out tools.analyzer
I'm using cljs, works the same?
you mean the read
part or analyser?
both
former is called cljs.reader/read-string
in cljs
latter I have no idea if it works in cljs (I'm gonna guess no)
is reader
a part of core or do I need to add it as a :dependency?
it's built-in
cool
it's working 🙂 I was getting all excited about instaparse... now I have to calm down my curiosity and get to work 😄
do I use core.match
with this?
Haha, I suppose building a parser yourself would be a great learning exercise too.... but code grammar is a bit complex.
it looks as so, you're right
You can use whatever tools you want to process the data, it's just a list
ok, let me give it a go
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
the "analysis" of your resulting data is always left as an exercise to the reader anyway 🙂