https://github.com/replikativ/datalog-parser
Generic datalog parser compliant to datomic, datascript and datahike queries.
https://github.com/replikativ/datalog-parser
Last synced: 8 months ago
JSON representation
Generic datalog parser compliant to datomic, datascript and datahike queries.
- Host: GitHub
- URL: https://github.com/replikativ/datalog-parser
- Owner: replikativ
- License: epl-2.0
- Created: 2019-05-27T14:41:03.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T15:53:16.000Z (about 1 year ago)
- Last Synced: 2025-04-09T04:02:24.235Z (9 months ago)
- Language: Clojure
- Size: 73.2 KB
- Stars: 71
- Watchers: 8
- Forks: 11
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# datalog-parser
A Datalog parser. This parser is used by [Datahike](https://github.com/replikativ/datahike) and follows the Datalog dialect of [Datomic](https://www.datomic.com/).
Note: This repository has been moved from the [lambdaforge organization](https://github.com/replikativ) to [replikativ](https://github.com/replikativ). So, you will find older releases of the parser at the [lambdaforge clojars page](https://clojars.org/io.lambdaforge/datalog-parser).
## Usage
Add the current release of `io.replikativ/datalog-parser` to your `project.clj`. Start a repl and run:
```Clojure
(require '[datalog.parser :as parser])
(parser/parse '[:find ?x :in $ ?y :where [?x :z ?y]])
;;=> (namespaces omitted for brevity)
;; #Query{:qfind #FindRel{:elements [#Variable{:symbol ?x}]}
;; :qwith nil
;; :qin [#BindScalar{:variable #SrcVar{:symbol $}}
;; #BindScalar{:variable #Variable{:symbol ?y}}]
;; :qwhere [#Pattern{:source #DefaultSrc{}
;; :pattern [#Variable{:symbol ?x}
;; #Constant{:value :z}
;; #Variable{:symbol ?y}]}]}
```
For more examples look at the [tests](test/datalog/parser_test.cljc).
### Benchmarking and Profiling
To benchmark or profile the parser, change to the parser-perf namespace
or require it:
```clojure
(in-ns 'datalog.parser-perf')
```
Then run the parse benchmark or profiler:
```clojure
(parse)
(profile)
```
To see the produced flame graph, you can start a web server at `port`:
```clojure
(in-ns 'datalog.parser-perf')
(prof/server-files port)
```
## TODO
## 0.2.0
Unparsing support, missing types:
- PullSpec
- PullAttrName
- PullReverseAttrName
- PullLimitExpr
- PullDefaultExpr
- PullWildcard
- PullRecursionLimit
- PullMapSpecEntry
- PullAttrWithOpts
## License
Copyright © 2020 lambdaforge UG (haftungsbeschränkt), Nikita Prokopov
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 1.0.