liquidsoap-prettier 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.github/workflows/check-formatting.yml +32 -0
  2. package/README.md +31 -5
  3. package/package.json +1 -1
  4. package/src/cli.js +104 -9
  5. package/tests/liq/audio.liq +460 -0
  6. package/tests/liq/autocue.liq +1081 -0
  7. package/tests/liq/clock.liq +14 -0
  8. package/tests/liq/cron.liq +74 -0
  9. package/tests/liq/error.liq +48 -0
  10. package/tests/liq/extra/audio.liq +677 -0
  11. package/tests/liq/extra/audioscrobbler.liq +482 -0
  12. package/tests/liq/extra/deprecations.liq +976 -0
  13. package/tests/liq/extra/externals.liq +196 -0
  14. package/tests/liq/extra/fades.liq +260 -0
  15. package/tests/liq/extra/file.liq +66 -0
  16. package/tests/liq/extra/http.liq +160 -0
  17. package/tests/liq/extra/interactive.liq +917 -0
  18. package/tests/liq/extra/metadata.liq +75 -0
  19. package/tests/liq/extra/native.liq +201 -0
  20. package/tests/liq/extra/openai.liq +150 -0
  21. package/tests/liq/extra/server.liq +177 -0
  22. package/tests/liq/extra/source.liq +476 -0
  23. package/tests/liq/extra/spinitron.liq +272 -0
  24. package/tests/liq/extra/telnet.liq +266 -0
  25. package/tests/liq/extra/video.liq +59 -0
  26. package/tests/liq/extra/visualization.liq +68 -0
  27. package/tests/liq/fades.liq +941 -0
  28. package/tests/liq/ffmpeg.liq +605 -0
  29. package/tests/liq/file.liq +387 -0
  30. package/tests/liq/getter.liq +74 -0
  31. package/tests/liq/hls.liq +329 -0
  32. package/tests/liq/http.liq +1048 -0
  33. package/tests/liq/http_codes.liq +447 -0
  34. package/tests/liq/icecast.liq +58 -0
  35. package/tests/liq/io.liq +106 -0
  36. package/tests/liq/liquidsoap.liq +31 -0
  37. package/tests/liq/list.liq +440 -0
  38. package/tests/liq/log.liq +47 -0
  39. package/tests/liq/lufs.liq +295 -0
  40. package/tests/liq/math.liq +23 -0
  41. package/tests/liq/medialib.liq +752 -0
  42. package/tests/liq/metadata.liq +253 -0
  43. package/tests/liq/nfo.liq +258 -0
  44. package/tests/liq/null.liq +71 -0
  45. package/tests/liq/playlist.liq +1347 -0
  46. package/tests/liq/predicate.liq +106 -0
  47. package/tests/liq/process.liq +93 -0
  48. package/tests/liq/profiler.liq +5 -0
  49. package/tests/liq/protocols.liq +1139 -0
  50. package/tests/liq/ref.liq +28 -0
  51. package/tests/liq/replaygain.liq +135 -0
  52. package/tests/liq/request.liq +467 -0
  53. package/tests/liq/resolvers.liq +33 -0
  54. package/tests/liq/runtime.liq +70 -0
  55. package/tests/liq/server.liq +99 -0
  56. package/tests/liq/settings.liq +41 -0
  57. package/tests/liq/socket.liq +33 -0
  58. package/tests/liq/source.liq +362 -0
  59. package/tests/liq/sqlite.liq +161 -0
  60. package/tests/liq/stdlib.liq +172 -0
  61. package/tests/liq/string.liq +476 -0
  62. package/tests/liq/switches.liq +197 -0
  63. package/tests/liq/testing.liq +37 -0
  64. package/tests/liq/thread.liq +161 -0
  65. package/tests/liq/tracks.liq +100 -0
  66. package/tests/liq/utils.liq +81 -0
  67. package/tests/liq/video.liq +918 -0
@@ -0,0 +1,440 @@
1
+ # Add an element at the top of a list.
2
+ # @category List
3
+ def list.cons(x, l) =
4
+ list.add(x, l)
5
+ end
6
+
7
+ # "Delayed" version of `list.case` where the value on empty list is only
8
+ # evaluated if necessary.
9
+ # @category List
10
+ def list.dcase(l, d, f) =
11
+ f = list.case(l, d, fun (x, l) -> {f(x, l)})
12
+ f()
13
+ end
14
+
15
+ # Return the head (first element) of a list, or `default` if the list is empty.
16
+ # @category List
17
+ # @param ~default Default value if key does not exist.
18
+ def list.hd(~default=null, l) =
19
+ list.dcase(
20
+ l,
21
+ {
22
+ default
23
+ ?? error.raise(
24
+ error.not_found,
25
+ "no default value for list.hd"
26
+ )
27
+ },
28
+ fun (x, _) -> x
29
+ )
30
+ end
31
+
32
+ # Return the list without its first element.
33
+ # @category List
34
+ def list.tl(l) =
35
+ list.case(l, [], fun (_, l) -> l)
36
+ end
37
+
38
+ # Create a list with given length, filled with given element.
39
+ # @category List
40
+ # @param n Number of elements in the list.
41
+ # @param x Element to fill the list with.
42
+ def list.make(n, x) =
43
+ list.init(n, fun (_) -> x)
44
+ end
45
+
46
+ # Determining whether a list is empty or not.
47
+ # @category List
48
+ def list.is_empty(l) =
49
+ list.case(l, true, fun (_, _) -> false)
50
+ end
51
+
52
+ # Return the last element of a list.
53
+ # @category List
54
+ def list.last(~default=null, l) =
55
+ list.nth(default=default, l, list.length(l) - 1)
56
+ end
57
+
58
+ # Call a function on every element of a list.
59
+ # @category List
60
+ def list.iter(f, l) =
61
+ list.iteri(fun (_, v) -> f(v), l)
62
+ end
63
+
64
+ # Check whether an element belongs to a list.
65
+ # @category List
66
+ def list.mem(x, l) =
67
+ err = error.register("mem")
68
+ try
69
+ list.iter(fun (v) -> if v == x then error.raise(err, "found") end, l)
70
+ false
71
+ catch _ : [err] do
72
+ true
73
+ end
74
+ end
75
+
76
+ # Map a function on every element of a list, starting from the right. This
77
+ # function is tail-recursive.
78
+ # @category List
79
+ def list.map.right(f, l) =
80
+ list.ind(l, [], fun (x, _, l) -> list.cons(f(x), l))
81
+ end
82
+
83
+ # Map a function on every element of a list, along with its index.
84
+ # @category List
85
+ def list.mapi(f, l) =
86
+ n = ref(0)
87
+
88
+ def f(x) =
89
+ i = n()
90
+ n := i + 1
91
+ f(i, x)
92
+ end
93
+
94
+ list.map(f, l)
95
+ end
96
+
97
+ # Add indices to every element of a list, so that it can be accessed with the
98
+ # notation `l[n]`.
99
+ # @category List
100
+ def list.indexed(l) =
101
+ list.mapi(fun (i, x) -> (i, x), l)
102
+ end
103
+
104
+ # Fold a function on every element of a list: `list.fold(f,x1,[e1,..,en]) is f(...f(f(x1,e1),e2)...,en)`.
105
+ # @category List
106
+ # @param f Function `f` for which `f(x,e)` which will be called on every element `e` with the current value of `x`, returning the new value of `x`.
107
+ # @param x Initial value x1, to be updated by successive calls of `f(x,e)`.
108
+ def list.fold(f, x, l) =
109
+ ret = ref(x)
110
+ list.iter(fun (v) -> ret := f(ret(), v), l)
111
+ ret()
112
+ end
113
+
114
+ # Fold a function on every element of a list. Similar to `list.fold` but
115
+ # iterates from the right of the list. It is slightly more efficient than
116
+ # `list.fold`.
117
+ # @category List
118
+ # @param f Function `f` for which `f(x,e)` which will be called on every element `e` with the current value of `x`, returning the new value of `x`.
119
+ # @param x Initial value x1, to be updated by successive calls of `f(x,e)`.
120
+ def list.fold.right(f, x, l) =
121
+ list.ind(l, x, fun (e, _, r) -> f(e, r))
122
+ end
123
+
124
+ # Concatenate all the elements of a list of lists.
125
+ # @category List
126
+ def list.flatten(l) =
127
+ list.fold(fun (l, s) -> list.append(l, s), [], l)
128
+ end
129
+
130
+ # Filter a list according to a predicate. The order in which elements are
131
+ # handled is not specified (and is currently implemented from the right).
132
+ # @category List
133
+ # @param ~remove Function called on an element when it is removed.
134
+ # @param p Predicate indicating whether an element should be kept or not.
135
+ # @param l List to filter.
136
+ def list.filter(~remove=fun (_) -> (), p, l) =
137
+ # list.case(l, [], fun (x, l) -> if p(x) then list.cons(x, list.filter(p, l)) else list.filter(p, l) end)
138
+ list.ind(
139
+ l,
140
+ [],
141
+ fun (x, _, l) ->
142
+ if
143
+ p(x)
144
+ then
145
+ list.cons(x, l)
146
+ else
147
+ (remove(x) : unit)
148
+ l
149
+ end
150
+ )
151
+ end
152
+
153
+ # Map a function on a list (like `list.map`) excepting that the value is removed
154
+ # if the function returns `null`.
155
+ # @category List
156
+ # @param f Function called on every element of the list.
157
+ # @param l The list.
158
+ def list.filter_map(f, l) =
159
+ def f(x, _, l) =
160
+ y = f(x)
161
+ if null.defined(y) then list.cons(null.get(y), l) else l end
162
+ end
163
+
164
+ list.ind(l, [], f)
165
+ end
166
+
167
+ # Associate a value to a key in an association list. This functions raises
168
+ # `error.not_found` if no default value is specified.
169
+ # @category List
170
+ # @param ~default Value returned if the key is not found.
171
+ def list.assoc(~default=null, key, l) =
172
+ ret = ref(💣())
173
+ err = error.register("assoc")
174
+ try
175
+ list.iter(
176
+ fun (v) ->
177
+ if
178
+ fst(v) == key
179
+ then
180
+ ret := snd(v)
181
+ error.raise(err, "found")
182
+ end,
183
+ l
184
+ )
185
+
186
+ null.case(
187
+ default,
188
+ fun () ->
189
+ error.raise(
190
+ error.not_found,
191
+ "no default value for list.assoc"
192
+ ),
193
+ fun (v) -> v
194
+ )
195
+ catch _ : [err] do
196
+ ret()
197
+ end
198
+ end
199
+
200
+ # `list.assoc.mem(key,l)` returns `true` if `l` contains a pair (key,value).
201
+ # @category List
202
+ # @param a Key to look for.
203
+ # @param l List of pairs (key,value).
204
+ def list.assoc.mem(a, l) =
205
+ err = error.register("find")
206
+ try
207
+ list.iter(fun (el) -> if fst(el) == a then error.raise(err, "found") end, l)
208
+ false
209
+ catch _ : [err] do
210
+ true
211
+ end
212
+ end
213
+
214
+ # Associate a value to a key in an association list. This functions is similar
215
+ # to `list.assoc` excepting that it returns `null` if no value exists for the
216
+ # key.
217
+ # @category List
218
+ def list.assoc.nullable(key, l) =
219
+ try
220
+ null(list.assoc(key, l))
221
+ catch _ do
222
+ null
223
+ end
224
+ end
225
+
226
+ # Keep only the elements of an association list satisfying a given predicate.
227
+ # @category List
228
+ def list.assoc.filter(p, l) =
229
+ def p(kv) =
230
+ p(fst(kv), snd(kv))
231
+ end
232
+
233
+ list.filter(p, l)
234
+ end
235
+
236
+ # Map a function of every element of the associative list, removing the entry if
237
+ # the function returns `null`.
238
+ # @category List
239
+ def list.assoc.filter_map(f, l) =
240
+ def f(kv) =
241
+ f(fst(kv), snd(kv))
242
+ end
243
+
244
+ list.filter_map(f, l)
245
+ end
246
+
247
+ # Remove the first pair from an associative list.
248
+ # @category List
249
+ # @param key Key of pair to be removed.
250
+ # @param l List of pairs (key,value).
251
+ def list.assoc.remove(key, l) =
252
+ ret = ref(💣())
253
+ err = error.register("assoc.remove")
254
+ try
255
+ list.iter(
256
+ fun (v) ->
257
+ if
258
+ fst(v) == key
259
+ then
260
+ ret := snd(v)
261
+ error.raise(err, "found")
262
+ end,
263
+ l
264
+ )
265
+
266
+ l
267
+ catch _ : [err] do
268
+ list.remove((key, ret()), l)
269
+ end
270
+ end
271
+
272
+ # Remove all pairs with given key from an associative list.
273
+ # @category List
274
+ # @param key Key of pairs to be removed.
275
+ # @param l List of pairs (key,value).
276
+ def list.assoc.remove.all(key, l) =
277
+ list.assoc.filter(fun (k, _) -> k != key, l)
278
+ end
279
+
280
+ # Check that a predicate is satisfied for every element in a list.
281
+ # @category List
282
+ # @param p Predicate.
283
+ # @param l List
284
+ def list.for_all(p, l) =
285
+ err = error.register("for_all")
286
+ try
287
+ list.iter(fun (v) -> if not p(v) then error.raise(err, "found") end, l)
288
+ true
289
+ catch _ : [err] do
290
+ false
291
+ end
292
+ end
293
+
294
+ # Check that a predicate is satisfied for some element in a list.
295
+ # @category List
296
+ # @param p Predicate.
297
+ # @param l List
298
+ def list.exists(p, l) =
299
+ err = error.register("exists")
300
+ try
301
+ list.iter(fun (v) -> if p(v) then error.raise(err, "found") end, l)
302
+ false
303
+ catch _ : [err] do
304
+ true
305
+ end
306
+ end
307
+
308
+ # First element satisfying a predicate. Raises `error.not_found` if not element
309
+ # is found and no default value was specified.
310
+ # @category List
311
+ # @param ~default Returned value when the predicate is not found.
312
+ # @param p Predicate.
313
+ # @param l List
314
+ def list.find(~default=null, p, l) =
315
+ ret = ref(💣())
316
+ err = error.register("find")
317
+ try
318
+ list.iter(
319
+ fun (v) ->
320
+ if
321
+ p(v)
322
+ then
323
+ ret := v
324
+ error.raise(err, "found")
325
+ end,
326
+ l
327
+ )
328
+
329
+ null.case(
330
+ default,
331
+ fun () ->
332
+ error.raise(
333
+ error.not_found,
334
+ "no default value for list.find"
335
+ ),
336
+ fun (v) -> v
337
+ )
338
+ catch _ : [err] do
339
+ ret()
340
+ end
341
+ end
342
+
343
+ # First index where a predicate is satisfied.
344
+ # @category List
345
+ # @param p Predicate.
346
+ # @param l List
347
+ def list.index(p, l) =
348
+ list.ind(l, 0, fun (x, _, r) -> if p(x) then 0 else r + 1 end)
349
+ end
350
+
351
+ # Create an iterator over the elements of a list.
352
+ # @category List
353
+ def list.iterator(l) =
354
+ l = ref(l)
355
+
356
+ def f() =
357
+ list.case(
358
+ l(),
359
+ null,
360
+ fun (x, t) ->
361
+ begin
362
+ l := t
363
+ x
364
+ end
365
+ )
366
+ end
367
+
368
+ f
369
+ end
370
+
371
+ # Returns a copy of the given list with a new element inserted at a given
372
+ # position. Raises `error.not_found` if the list has less than `index` elements.
373
+ # @category List
374
+ # @param index Index to insert at, starting at `0`.
375
+ # @param new_element Element to insert
376
+ # @param l List to insert into.
377
+ def list.insert(index, new_element, l) =
378
+ if
379
+ list.length(l) < index
380
+ then
381
+ error.raise(
382
+ error.not_found,
383
+ "List should have at least #{index} elemments"
384
+ )
385
+ end
386
+
387
+ if
388
+ index == 0
389
+ then
390
+ new_element::l
391
+ else
392
+ def f(cur, el) =
393
+ let (pos, l) = cur
394
+ l = if pos + 1 == index then new_element::el::l else el::l end
395
+ (pos + 1, l)
396
+ end
397
+
398
+ let (_, l) = list.fold(f, (0, []), l)
399
+ list.rev(l)
400
+ end
401
+ end
402
+
403
+ # Compute the beginning of a list.
404
+ # @category List
405
+ # @param n Number of elements in the returned list.
406
+ # @param l List whose prefix should be taken.
407
+ def list.prefix(n, l) =
408
+ len = list.length(l)
409
+ n = n < len ? n : len
410
+ list.init(n, fun (n) -> list.nth(l, n))
411
+ end
412
+
413
+ # Pick a random element in a list.
414
+ # @category List
415
+ # @param ~default Value returned if the list is empty.
416
+ # @param l List in which the element should be picked.
417
+ def list.pick(~default=null, l) =
418
+ if
419
+ list.is_empty(l)
420
+ then
421
+ default
422
+ ?? error.raise(
423
+ error.not_found,
424
+ "empty list in list.pick"
425
+ )
426
+ else
427
+ list.nth(l, random.int(min=0, max=list.length(l)))
428
+ end
429
+ end
430
+
431
+ # Sort a list according to the "natural" order.
432
+ # @category List
433
+ # @param l List to sort
434
+ def list.sort.natural(l) =
435
+ def compare(x, y) =
436
+ if x < y then -1 elsif x > y then 1 else 0 end
437
+ end
438
+
439
+ list.sort(compare, l)
440
+ end
@@ -0,0 +1,47 @@
1
+ # Log a critical message
2
+ # @category Liquidsoap
3
+ def log.critical(~label="lang", msg) =
4
+ log(label=label, level=1, msg)
5
+ end
6
+
7
+ # Log a severe message
8
+ # @category Liquidsoap
9
+ def log.severe(~label="lang", msg) =
10
+ log(label=label, level=2, msg)
11
+ end
12
+
13
+ # Log an important message
14
+ # @category Liquidsoap
15
+ def log.important(~label="lang", msg) =
16
+ log(label=label, level=3, msg)
17
+ end
18
+
19
+ # Log a normal message
20
+ # @category Liquidsoap
21
+ def log.info(~label="lang", msg) =
22
+ log(label=label, level=4, msg)
23
+ end
24
+
25
+ # Log a debug message
26
+ # @category Liquidsoap
27
+ def log.debug(~label="lang", msg) =
28
+ log(label=label, level=5, msg)
29
+ end
30
+
31
+ # Get and set the log level.
32
+ # @category Liquidsoap
33
+ def log.level =
34
+ settings.log.level
35
+ end
36
+
37
+ # Get and set the file logging
38
+ # @category Liquidsoap
39
+ def log.file =
40
+ settings.log.file
41
+ end
42
+
43
+ # Get and set logging to stdout
44
+ # @category Liquidsoap
45
+ def log.stdout =
46
+ settings.log.stdout
47
+ end