are there any resources on writing a datalog parser/query engine?
The datalog bnf can be translated to spec or malli (I have an example of the latter) You can then call parse/decode and bob's your uncle That takes care of parsing, at least
(by which I mean a datomic-like query syntax)
Not that I know of, but what would you like to know?
I sort of assume there's a theoretical starting point that would be useful if I wanted to write my own
You could start with my ClojureD talk from 2019?
I have been reading asami's source code but perhaps I'll begin again there đ
It starts a bit simplistically, but gets into the âhowâ
ty!
I also just found https://github.com/lambdaforge/datalog-parser
but I think i'd like to write my own parser, to understand it better
Asami doesnât actually parse. It just uses Clojure structures
tweaks this a little to form the AST, does some algebra and reordering on it, and then executes it
that's essentially what I want to do, I think
If you look at Asami, I recommend going back to an earlier iteration
Specifically⌠https://github.com/threatgrid/naga/tree/d149904da8ecb510ddbbb5b73824c74da4b05d77/src/naga/storage/memory
that did joins and filters only, but it was much easier to follow
once you have that, then the latest code will make much more sense
I was getting a bit lost this morning in the planner distinctions and how that effected everything
Also, the code I pointed you at doesnât handle queries as youâre familiar with them. Youâd be looking for the query function in code.clj line 294. After the storage object, this function takes 2 arguments:
⢠output-pattern: this is the content of a :find clause and can be something like [?p ?v]
⢠patterns: this is the content of a :where clause, and can be something like [?e :age ?a] [(> ?a 20)] [?e ?p ?v]
The plan-path function can be safely ignored. Just assume that the output plan value is the same as the input patterns value. It also returns resolution-map, but thatâs a bit misleading. Itâs just that the default planner used this map, and the first step of the query also happened to use this map, and I figured I could save myself a step by returning it and using it, rather than looking it up again.
yes⌠I wouldnât look at that AT ALL đ
that just does the reordering
you can turn it off
(And we often do)