-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathworker.ls
33 lines (28 loc) · 916 Bytes
/
worker.ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require! \worker
lenToRegex = {}
lens = []
LTMRegexes = []
lang = process.env.lang || process.argv.filter((in <[ a t h c ]>)).0
require! fs
pre2 = JSON.parse fs.read-file-sync "#lang/lenToRegex.json"
init!
worker.dedicated({ proc })
function init ()
lenToRegex := pre2.lenToRegex
lens := []
for len of lenToRegex
lens.push len
lenToRegex[len] = new RegExp lenToRegex[len], \g
lens.sort (a, b) -> b - a
for len in lens => LTM-regexes.push lenToRegex[len]
function proc (chunk, title, idx)
for re in LTM-regexes
chunk.=replace(re, -> escape "`#it~")
esc = escape title
codepoints-of = -> it.length - it.split( /[\uD800-\uDBFF][\uDC00-\uDFFF]/g ).length + 1
title-codes = codepoints-of title
for len in lens | len < title-codes
title.=replace(lenToRegex[len], -> escape "`#it~")
return "#idx #esc " + unescape(chunk).replace(/"t":""/, """
"t":"#{ unescape title }"
""")