clj-antlr
with support for split (lexer and parser) grammarsI continued my work to make the timeclock grammar for hledger usable in the browser. And I was very excited to see auto-complete and syntax highlighting working in my browser but that did not happen.
It seems that to have my way, I needed two Antlr grammars: one for the lexer and one for the parser and I only had a combined Antlr grammar. On top of that clj-antlr did not support working with two grammars so I was a bit set-back. There was an issue open since 2017 to support load the grammar with separate Lexer & Parser files but no pull-request and not much update on it.
Fortunately for me there was a patch submitted by Quân / quan-nh that looked promising so I started digging.
After some documentation reading and working with the changes from quan-nh I managed to make clj-antrl load two grammar files so I can continue my work. I ended up using most/all of the work from quan-nh so all credit should go to him for this feature. All I did was to add a test and documentation and fix some failing test.
I submitted the PR and Kyle Kingsbury a.k.a aphyr was kind enough to merge it quickly.
For those of you wanting to see some code:
;; You can now use REPL driven development with Antlr lexer and parser grammars
(let [g (parser "grammars/L.g4" "grammars/T.g4" {})] (g "abbc"))
(:s "a" "b" "b" "c")
My work is not there yet since the changes are not published and I can’t use them easily without that. Kyle asked if I needed the changes but I did not see an update yet. So I’ll look for alternatives.
I could publish the library in my private repo and use it from there until a release is found but why do it this simple :)?
I did come with another idea that I want to try: use the library via deps.edn
.
deps.edn
is the new kid on the Clojure block and allows Clojure projects to depend on other projects that are published as git projects.
There is no need to have binary artifacts published since Clojure does not require it.
I wrote a deps.edn file for the project and