This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-23
Channels
- # announcements (3)
- # asami (5)
- # babashka (1)
- # beginners (38)
- # biff (4)
- # calva (12)
- # cider (2)
- # clj-commons (6)
- # clj-kondo (46)
- # clj-on-windows (1)
- # clojure (50)
- # clojure-europe (41)
- # clojure-nl (3)
- # clojure-norway (2)
- # clojure-uk (16)
- # clojured (3)
- # clojurescript (49)
- # conjure (1)
- # cursive (29)
- # datahike (6)
- # datascript (4)
- # emacs (70)
- # funcool (1)
- # google-cloud (12)
- # graalvm (10)
- # graalvm-mobile (7)
- # gratitude (4)
- # hyperfiddle (1)
- # joyride (26)
- # lsp (16)
- # malli (23)
- # nbb (5)
- # off-topic (23)
- # polylith (32)
- # re-frame (23)
- # releases (3)
- # remote-jobs (1)
- # reveal (3)
- # tools-build (16)
- # xtdb (50)
Is there a channel where I can get recommendations for a library? I'm looking for a faster (like, WAY faster) Instaparse or similar that needs to work on ClojureScript...
there's #find-my-lib
you'll never get faster than a hand-rolled parser
at least when compared with a generalized one
An addition to that - you have to use version 4.8-1
with CLJS due to https://github.com/google/closure-compiler/issues/3477.
https://github.com/xapix-io/mutagen/blob/master/src/mutagen/grammars/json.cljc This could work, but i don't have time to prepare proper documentation so you have to look at source code and examples. Maybe next week i will have some time to prepare some
@U2FRKM4TW thanks for the suggestion, but unfortunately, in my case (parsing a prolog term) antlr4 is actually slower - by some orders of magnitude (using the grammar they have available at their github)! I was able make it slightly faster by using some tips from the Instaparse site, but I'll probably need to hand-roll a parser (or change my strategy 100% to not have to parse, which I honestly do not want to do considering what I'm doing right now 😄)
@U02N27RK69K thanks for the tip, I made a parser and indeed it is WAY faster!
@U3Y18N0UC any chance you can share the bnf you're using? I'm curious to try translating it to different parsers
@UK0810AQ2 honestly, it's just a case
checking for different first chars and some regexp: https://gitlab.com/mauricioszabo/spock/-/merge_requests/5/diffs. Nothing really special, and I just need to parse a subset of Prolog so it probably is sufficient :)
It's possible that I'll add some memoize
in the future, but for now it works really well and it's fast enough for my cases.
Rough sketch:
(defn char-range
[from+to]
(let [from (long (first from+to))
to (long (second from+to))]
(m/-simple-schema
{:type ::char-range
:pred (fn [x] (<= from (long x) to))})))
(defn char-seq
[cs]
(into [:cat] (mapv (fn [c] [:= c]) cs)))
(m/parse
(m/schema
[:schema
{:registry
{::digit (char-range "09")
::lower-case (char-range "az")
::upper-case (char-range "AZ")
::letter [:alt ::lower-case ::upper-case]
::number [:+ ::digit]
::var [:cat ::upper-case [:* ::lower-case]]
::boolean [:altn [:true (char-seq "true")] [:false (char-seq "false")]]
::atom [:cat ::lower-case [:* ::letter]]
::term [:altn
#_[:equality ::equality]
[:atom ::atom]
[:var ::var]
[:number ::number]
[:boolean ::boolean]
#_[:structure ::structure]
#_[:list ::list]
#_[:string ::string]]
;; ::equality [:cat
;; ::var
;; [:= \space]
;; [:= \=]
;; [:= \space]
;; ::term]
}}
::term])
(seq "Xyz"))
@UK0810AQ2 do you have an idea of how performant it is?
I can benchmark some rudimentary parsing if you're interested. What should be my baseline?
Ok, this was one code that Instaparse's version was struggling to parse: on my machine, it was taking almos half a second, then I optimized my code and it was parsing in 160ms (better, but FAR from what I wanted).
I can write the schema for it but until I figure out what's up with malli I can't run a full example
Parsing something like (p (seq "foo(X, Y)"))
where p
is a defined parser takes about 3 micro seconds
I'd like to share this experiment I've been poking at for the past year, which I can finally promote from floundering to promising. "Let's write a compiler, how hard can it be?" https://github.com/bsless/clj-analyzer
Thanks for sharing. Btw. the link in the readme is incorrect (relative URL?) - it should be https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/compiler/core-to-core-pipeline