This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-31
Channels
- # ai (5)
- # announcements (11)
- # beginners (19)
- # biff (1)
- # calva (8)
- # cider (3)
- # clj-kondo (12)
- # clojure (97)
- # clojure-europe (39)
- # clojure-nl (1)
- # clojure-norway (74)
- # clojure-uk (35)
- # clojurescript (8)
- # component (8)
- # conjure (4)
- # cursive (13)
- # data-science (1)
- # datahike (55)
- # datomic (2)
- # emacs (3)
- # etaoin (6)
- # gratitude (1)
- # hoplon (12)
- # hyperfiddle (54)
- # introduce-yourself (1)
- # lsp (70)
- # missionary (40)
- # music (1)
- # off-topic (79)
- # re-frame (78)
- # releases (4)
- # sql (5)
- # squint (9)
- # tree-sitter (4)
- # xtdb (20)
Any guesses why I get an error in the repl when I eval js/alert
or (js/alert "hello")
? I’m using vim-fireplace and shadow-cljs and not doing anything especially exotic…
I’ve also tried same expressions in the repl you get from npx shadow-cljs cljs-repl :app
. (js/console.log "asdf")
works fine in both cases.
Edit: This probably belongs in #shadow-cljs; seems to have to do with my shadow config.
and… now I can’t reproduce. I want the last hour (ok more than that) of my life back.
I am trying to parse an .srt subtitle text inside cljs, currently using instaparse. input:
1
00:00:02,290 --> 00:00:03,193
sentence 1
2
00:00:22,825 --> 00:00:24,406
sentence 2
3
00:00:24,406 --> 00:00:24,987
sentence 3
grammar:
Caption = sentence+
sentence = (index new-line
start arrorw end new-line
text new-line)
index = #"\d+"
new-line = #"\n*"
start = hour colon min colon sec comma minisec
end = hour colon min colon sec comma minisec
hour = #"\d{2}"
min = #"\d{2}"
sec = #"\d{2}"
minisec = #"\d{3}"
colon = ":"
comma = ","
arrorw = " --> "
text = #".*"
you can paste these to: https://instaparse-live.matt.is/
it can successfully parse the result.
my question is: is there a better way to achieve this? is parsing .srt files a simple problem without introducing instaparse?It depends on what "better" means in your context, but you could certainly read that in line by line and parse the start/end timestamps with a regex.
Yeah, I'd definitely just use a bunch of calls to split
.
It's a frozen simple format, there's no need to involve any intricate parsers.
Something using tick.core/time:
(->> (str/split sample-srt #"\n\n(?=\d)")
(map str/split-lines)
(map (fn [[i ts & s]]
(let [[_ start end] (re-matches #"(\d\d:\d\d:\d\d,\d\d\d) --> (\d\d:\d\d:\d\d,\d\d\d)" ts)]
{:index i
:timestamp {:start (t/time (str/replace start #"," "."))
:end (t/time (str/replace end #"," "."))}
:sentences s}))))
;; => ({:index "1",
;; :timestamp
;; {:start #time/time "00:00:02.290", :end #time/time "00:00:03.193"},
;; :sentences ("sentence 1")}
;; {:index "2",
;; :timestamp
;; {:start #time/time "00:00:22.825", :end #time/time "00:00:24.406"},
;; :sentences ("sentence 2")}
;; {:index "3",
;; :timestamp
;; {:start #time/time "00:00:24.406", :end #time/time "00:00:24.987"},
;; :sentences ("sentence 3")})