summaryrefslogtreecommitdiff
path: root/desk/lib/sortug.hoon
blob: bf988daf5b06fcc788e4e3ef7390a65c1038a97f (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
|%
++  maybe
  |*  =mold
  $%  [%ok mold]
      [%err p=@t]
  ==  
++  uri-encode
  |=  t=tape  ^-  tape
  =+  (en-urlt:html t)  ::  double-encoding because iris decodes shit at some point for some reason
(en-urlt:html -)
++  web
  |%
  ++  images
  %-  silt  :~('png' 'jpg' 'jpeg' 'svg' 'webp')
  ++  is-image
  |=  url=@t  ^-  ?
    =/  u=(unit purl:eyre)  (de-purl:html url)
      ?~  u  .n
    =/  ext  p.q.u.u
    ?~  ext  .n
    (~(has in images) u.ext)
  --
++  slice
  |*  [a=(list) count=@ud index=@ud]
  =|  i=@ud
  |-  ^+  a
  ?~  a  ~
  ?:  .=(count 0)  ~
  ?:  (lth i index)  $(a t.a, i +(i))
  :-  i.a  
  $(a t.a, i +(i), count (dec count))
  
++  pick
  |*  [a=(list) b=@]
  =/  top  (dec (lent a))
  =/  ind  (mod b top)
    (snag ind a)
++  flop                                                ::  reverse
  |*  a=(list)
  =>  .(a (homo a))
  ^+  a
  =+  b=`_a`~
  |-
  ?~  a  b
  $(a t.a, b [i.a b])
++  seq
|%
  :: TODO study these two well
  ++  reel
    ~/  %reel
    |*  [a=(list) b=_=>(~ |=([* *] +<+))]
    |-  ^+  ,.+<+.b
    ?~  a
      +<+.b
    (b i.a $(a t.a))
  ++  roll
    ~/  %roll
    |*  [a=(list) b=_=>(~ |=([* *] +<+))]
    |-  ^+  ,.+<+.b
    ?~  a
      +<+.b
    $(a t.a, b b(+<+ (b i.a +<+.b)))
  ++  snip
    |*  a=(list)
    =/  rev  (flop a)
    ?~  rev  a
    (flop t.rev)
--
++  fold
|*  [a=(list) b=* c=_|=(^ +<+)]
|-  ^+  b 
?~  a  b
=/  nb  (c [i.a b])
$(a t.a, b nb)
++  foldi
|*  [a=(list) b=* c=_|=(^ +<+)]
=|  i=@ud
|-  ^+  b 
?~  a  b
=/  nb  (c i i.a b)
$(a t.a, b nb, i +(i))
++  mapi
|*  [a=(list) b=gate]
=|  i=@ud
=>  .(a (homo a))
^-  (list _?>(?=(^ a) (b i i.a)))
|-
?~  a  ~
:-  i=(b i i.a) 
t=$(a t.a, i +(i))
++  cord-size  
|=  c=@t
(met 3 c)
++  concat-cord-list
|=  c=(list @t)
(rap 3 c)
++  cut-cord
|=  [c=@t s=@ud e=@ud]
(cut 3 [s e] c)
++  cfind-index
  |=  [nedl=@t hay=@t length=@ud case=?]  ^-  (unit [snip=@t left-amari=@ud right-amari=@ud])
  =/  nlen  (met 3 nedl)
  =/  hlen  (met 3 hay)
  ?:  (lth hlen nlen)  ~
  =?  nedl  !case
    (crass nedl)
  ::  iterate from index 0
  =/  pos  0
  =/  lim  (sub hlen nlen)
  |-
  :: If our position is further than the length of query
  :: it's obviously not gonna happen anymore so return
  ?:  (gth pos lim)  ~
  ::  If needle is equal to the [position needle-length] slice of hay then we're good
  =/  substring  ?:  case  (cut 3 [pos nlen] hay)  (crass (cut 3 [pos nlen] hay))
  ?.  .=(nedl substring)  $(pos +(pos))
    :: we grab a bigger piece of the cord, starting where
    =/  [start-index=@ud end-index=@ud]  [pos (add pos nlen)]
    ::  say it's [150 160]
    =/  halfway=@ud  (div (sub length nlen) 2)  :: that's 45
    =/  start=@ud   ?:  (gth pos halfway)  (sub pos halfway)  0  :: that's 105   
    =/  end=@ud  ?:  (gte (add halfway end-index) hlen)  hlen  (add halfway end-index)  ::  200
    
    =/  right-amari  (sub halfway (sub end end-index))      ::  5
    =/  left-amari   (sub halfway (sub start-index start))  ::  0
    =/  snip=@t  (cut 3 [start end] hay)  
    %-  some  :+  snip  left-amari  right-amari

++  cfindi
  |=  [nedl=@t hay=@t case=?]  ^-  @t
  =/  nlen  (met 3 nedl)
  =/  hlen  (met 3 hay)
  =|  res=@t
  ?:  (lth hlen nlen)  res
  =?  nedl  !case
    (crass nedl)
  ::  iterate from index 0
  =/  pos  0
  =/  lim  (sub hlen nlen)
  |-
  :: If our position is further than the length of query
  :: it's obviously not gonna happen anymore so return
  ?:  (gth pos lim)  res
  ::  If needle is equal to the [position needle-length] slice of hay then we're good
  ?:  .=  nedl
      ?:  case
        (cut 3 [pos nlen] hay)
      (crass (cut 3 [pos nlen] hay))
    :: we grab a bigger piece of the cord, starting where
    =/  s  ?:  (lte pos 50)  0  (sub pos 50)
    (cut 3 [s 100] hay)
  $(pos +(pos))
++  cfind
  |=  [nedl=@t hay=@t case=?]
  ^-  ?
  =/  nlen  (met 3 nedl)
  =/  hlen  (met 3 hay)
  ?:  (lth hlen nlen)
    |
  =?  nedl  !case
    (crass nedl)
  =/  pos  0
  =/  lim  (sub hlen nlen)
  |-
  ?:  (gth pos lim)
    |
  ?:  .=  nedl
      ?:  case
        (cut 3 [pos nlen] hay)
      (crass (cut 3 [pos nlen] hay))
    &
  $(pos +(pos))
    ++  crass
      |=  text=@t
      ^-  @t
      %^    run
          3
        text
      |=  dat=@
      ^-  @
      ?.  &((gth dat 64) (lth dat 91))
        dat
      (add dat 32)
++  js
  |%
  ++  de
    |%  
    ++  maybe
      |*  fst=$-(json *)
      |=  jon=json
      ?~  jon  ~  (fst jon)
    ++  st
      |=  mol=mold
      |=  jon=json
      ?>  ?=([%s *] jon)
      %-  mol  p.jon
    ++  ur
      |*  wit=$-(json *)
      |=  jon=(unit json)
      ?~(jon ~ `(wit u.jon))
    ++  gen
      |=  jon=json
      ?-  -.jon
    %s  p.jon
    %n  p.jon
    %b  p.jon
    %a  (turn p.jon gen)
    %o  ((om:dejs:format gen) jon)
      ==
    --
  ++  en
    |%
    ++  bitch  %bitch
    --
  --
++  string
  |%
++  replace
  |=  [bit=tape bot=tape =tape]
  ^-  ^tape
  |-
  =/  off  (find bit tape)
  ?~  off  tape
  =/  clr  (oust [(need off) (lent bit)] tape)
  $(tape :(weld (scag (need off) clr) bot (slag (need off) clr)))
  ::
++  split
  |=  [str=tape delim=tape]
  ^-  (list tape)
  (split-rule str (jest (crip delim)))
::
::  Split string by parsing rule delimiter.
++  split-rule
  |*  [str=tape delim=rule]
  ^-  (list tape)
  %+  fall
    (rust str (more delim (star ;~(less delim next))))
  [str ~]
++  contains
  |=  [str=tape nedl=tape]
  ^-  ?
  ?~  (find nedl str)  |  &
  ++  trim
  |=  a=tape
  |-  ^-  tape
    ?:  ?=([%' ' *] a)
      $(a t.a)
    (flop a)
  ++  number
  |=  a=@ud  ^-  tape
  ?:  =(0 a)  "0"
  %-  flop
  |-  ^-  tape
  ?:(=(0 a) ~ [(add '0' (mod a 10)) $(a (div a 10))])
  ++  capitalize
  |=  a=@t  ^-  tape
  =/  t=(list @t)  (trip a)
  ?~  t  (trip a)
  t(i (sub i.t 32))
  ++  enpath
  |=  str=cord  ^-  path
    =/  allow  ;~(pose low nud)
    =/  lcase  %+  cook
    |=  a=@t  (add 32 a)  hig
    =/  rul  ;~(pose allow lcase)
    =/  del  ;~(less rul next)
    =/  frul  (more del (cook crip (star rul)))
    (rash str frul)
  ++  enkebab2
  |=  str=cord  ^-  tape
    =/  allow  ;~(pose low nud hep)
    =/  kebab  (cold '-' next)
    =/  lcase  %+  cook
    |=  a=@t  (add 32 a)  hig
    =/  rul  ;~(pose allow lcase kebab)
    (rash str (star rul))
  ++  enkebab3
  |=  str=cord  ^-  tape
    =/  allow  ;~(pose low nud hep)
    =/  kebab  (cold '-' next)
    =/  lcase  %+  cook
    |=  a=@t  (add 32 a)  hig
    =/  rul  ;~(pose allow lcase unic kebab)
    (rash str (star rul))
  ++  unic
    %-  cook  :_  unicode
    |=  a=@  %-  crip  (scow:parsing %uw a)
  ++  unicode  (shim 128 100.000.000)
  ++  enkebab
    |=  str=cord
    ^-  cord
    ~|  str
    =-  (fall - str)
    %+  rush  str
    =/  name
      %+  cook
        |=  part=tape
        ^-  tape
        ?~  part  part
        :-  (add i.part 32)
        t.part
      ;~(plug hig (star low))
    %+  cook
      |=(a=(list tape) (crip (zing (join "-" a))))
    ;~(plug (star low) (star name))
  ++  cut-cord
  |=  [=cord chars=@ud]
  %+  end  3^chars  cord
  ++  pad
  |=  [t=tape length=@ud]  ^-  tape
  ?:  .=(length (lent t))  t
  $(t "0{t}")
  ++  date-to-path
  |=  d=@da  ^-  path
  =+  [[a y] m [d h mm s f]]=(yore d)
  =/  yr  (numb:enjs:format y)
  ?>  ?=(%n -.yr)
  /[p.yr]/(scot %ud m)/(scot %ud d)
  ++  date-to-tape
  |=  [d=@da delim=tape]  ^-  tape
  =+  [[a y] m [d h mm s f]]=(yore d)
  =/  ys  (ud-to-cord y)
  =/  month  (pad "{<m.m>}" 2)
  =/  day  (pad "{<d.d>}" 2)
  "{(trip ys)}{delim}{month}{delim}{day}"
  ++  datetime-to-tape
  |=  [d=@da delim=tape]  ^-  tape
  =+  [[a y] m [d h mm s f]]=(yore d)
  =/  ys  (ud-to-cord y)
  =/  month  (pad "{<m.m>}" 2)
  =/  day  (pad "{<d.d>}" 2)
  =/  hours  (pad "{<h.h>}" 2)
  =/  minutes  (pad "{<m.mm>}" 2)
  =/  seconds  (pad "{<s.s>}" 2)
  "{(trip ys)}{delim}{month}{delim}{day} {hours}:{minutes}:{seconds}"
  ++  time-to-tape
  |=  d=@da  ^-  tape
  =+  [[a y] m [d h mm s f]]=(yore d)
  =/  hours  (pad "{<h.h>}" 2)
  =/  minutes  (pad "{<m.mm>}" 2)
  "{hours}:{minutes}"
  ++  ud-to-cord
  |=  n=@ud  ^-  @t
  %-  crip
  %-  zing  (rush (scot %ud n) (more dot (star nud)))
  ++  remove
  |=  [s=@t r=@t]  ^-  @t
  %-  crip
  %-  zing
  %+  rush  s
  %+  more  (jest r)
  %-  star
  ;~(less (jest r) next)
  --
++  io
  |_  =bowl:gall
  ++  retrieve
  |=  =path
  =/  bp  /gx/(scot %p our.bowl)/[dap.bowl]/(scot %da now.bowl)
  .^(* (weld bp (weld path /noun)))
  ++  scry
  |*  [app=@tas =path =mold]
  =/  bp  /gx/(scot %p our.bowl)/[app]/(scot %da now.bowl)
  =/  pat  (weld bp (weld path /noun))
  .^(mold pat)
  ++  scry2
  |*  [app=@tas =path =mold]
  =/  bp  /gx/(scot %p our.bowl)/[app]/(scot %da now.bowl)
  =/  pat  (weld bp (weld path /noun))
  %-  mole  |.  .^(mold pat)
  ++  scry-pad
  |=  t=@tas  ^-  path  /(scot %p our.bowl)/[t]/(scot %da now.bowl)
  --
++  sail
  |%
  ++  coki-to-string
    |=  m=(map @t @t)  ^-  cord
    %-  crip  %-  ~(rep by m)  
    |=  [pair=[key=@t value=@t] acc=tape] 
    "{acc}{(trip key.pair)}={(trip value.pair)}; "
  ++  handle-html-form
  |=  body=(unit octs)  ^-  (map @t @t)
  ?~  body  ~
  =/  text  q.u.body
  =/  clean  (remove:string text '%0D')
  :: TODO html forms use \0d\0a
 ::  for carriage return
  :: this breaks the markdown parser
  =/  parser  (more tis (star next))
  =/  res  (rush clean yquy:de-purl:html)
  ?~  res  ~  (malt u.res)
  --
+$  michi  (list @t)  :: proper path with upper case
++  parsing
  |%
  ++  to-htmldate  |=  d=@da  ^-  tape
    =+  [[* y=@] m=@ [d=@ h=@ mm=@ s=@ f=*]]=(yore d)
    =/  ys    (scow %ud y)
    =/  ms    (pad:string (scow %ud m) 2)
    =/  ds    (pad:string (scow %ud d) 2)
    =/  hs    (pad:string (scow %ud h) 2)
    =/  mins  (pad:string (scow %ud mm) 2)
    "{ys}-{ms}-{ds}T{hs}:{mins}"
  ++  y  (bass 10 (stun 3^4 dit))
  :: ++  m  (sear (snug mon:yu) (plus alf))
  ++  d  (bass 10 (stun 1^2 dit))
  ::                                                ::  ++t:stud:chrono:
  ++  t                                             ::  hours:minutes:secs
    :: %+  cook  |=([h=@u @ m=@u @ s=@u] ~[h m s])
    :: ;~(plug d col d col d)
    ;~(plug d col d)
  ++  weekday-3
    ;~  pose
      %+  cold  0  (jest 'Sun')
      %+  cold  1  (jest 'Mon')
      %+  cold  2  (jest 'Tue')
      %+  cold  3  (jest 'Wed')
      %+  cold  4  (jest 'Thu')
      %+  cold  5  (jest 'Fri')
      %+  cold  6  (jest 'Sat')
    ==
  ++  monthname-3
    ;~  pose
      %+  cold  1  (jest 'Jan')
      %+  cold  2  (jest 'Feb')
      %+  cold  3  (jest 'Mar')
      %+  cold  4  (jest 'Apr')
      %+  cold  5  (jest 'May')
      %+  cold  6  (jest 'Jun')
      %+  cold  7  (jest 'Jul')
      %+  cold  8  (jest 'Aug')
      %+  cold  9  (jest 'Sep')
      %+  cold  10  (jest 'Oct')
      %+  cold  11  (jest 'Nov')
      %+  cold  12  (jest 'Dec')
    ==
  ++  three-section-time  ::  hours:minutes:secs
    %+  cook  |=([h=@u @ m=@u @ s=@u] [h m s])
    ;~(plug d col d col d)
  ++  html-datetime
    %+  cook  |=  [y=@ud * m=@ud * d=@ud * h=@ud * min=@ud]
      =/  dt  *date  =.  dt  dt(y y, m m, d.t d, h.t h, m.t min)
      (year dt)
    ;~  plug  y  hep  d  hep  d  (just 'T')
        t
    ==
  ++  twatter-date
  %+  cook  |=  [w=@ * m=@ * d=@ * [h=@ mn=@ s=@] * y=@]
  =|  dat=date  %-  year
  dat(y y, m m, t [d h mn s ~])
  ;~  plug
    weekday-3
    ace
    monthname-3
    ace
    d
    ace
    three-section-time
    ;~  plug
      ace
      lus
      y
      ace
    ==
    y
  ==
  ++  white  (star gah)
  ++  para
    |%
    ++  eof        ;~(less next (easy ~))
    ++  white      (mask "\09 ")
    ++  blank      ;~(plug (star white) (just '\0a'))
    ++  hard-wrap  (cold ' ' ;~(plug blank (star white)))
    ++  one-space  (cold ' ' (plus white))
    ++  empty
      ;~  pose
        ;~(plug blank (plus blank))
        ;~(plug (star white) eof)
        ;~(plug blank (star white) eof)
      ==
    ++  para
      %+  ifix
        [(star white) empty]
      %-  plus
      ;~  less
        empty
        next
      ==
    --
  ++  trim  para:para  ::  from whom/lib/docu
  ++  link  auri:de-purl:html
  ++  youtube
    ;~  pfix
      ;~  plug
          (jest 'https://')
          ;~  pose
              (jest 'www.youtube.com/watch?v=')
              (jest 'youtube.com/watch?v=')
              (jest 'youtu.be/')
          ==
      ==
      ;~  sfix
          (star aln)
          (star next)
      ==
    ==
  ++  twatter
    ;~  pfix
      ;~  plug
          (jest 'https://')
          ;~  pose
              (jest 'x.com/')
              (jest 'twitter.com/')
          ==
          (star ;~(less fas next))
          (jest '/status/')
      ==
      ;~  sfix
          (star nud)
          (star next)
      ==
    ==
        
  :: WIP
  ++  scow
  |=  [mod=@tas a=@]  ^-  tape
  ?+  mod  ""
  %ud  (a-co:co a)
  %ux  ((x-co:co 0) a)
  %uv  ((v-co:co 0) a)
  %uw  ((w-co:co 0) a)
  ==
  ++  b64  (bass 64 (plus siw:ab))
  ++  b16  (bass 16 (plus six:ab))
  ++  slaw
  |=  [mod=@tas txt=@t]  ^-  (unit @)
  ?+  mod  ~
  %ud  (rush txt dem)
  %ux  (rush txt b16)
  %uv  (rush txt vum:ag)
  %uw  (rush txt b64)
  ==
  :: ++  b64  
  :: %+  cook
  ::   |=(a=tape (rap 3 ^-((list @) a)))
  ::  (star ;~(pose nud low cen hig hep dot sig cab)) 
  ++  stam
  %+  sear
    |=  m=michi
    ^-  (unit michi)
    ?:  ?=([~ ~] m)  ~
    ?.  =(~ (rear m))  `m
    ~
  ;~(pfix fas (most fas b64))  
  ++  smat
  |=  m=michi  ^-  tape
  =/  t  "/"
  |-
  ?~  m  t
  =/  nt  "{t}/{(trip i.m)}"
  $(m t.m, t nt)
  ++  de-comma
  %+  sear
    |=  p=path
    ^-  (unit path)
    ?:  ?=([~ ~] p)  `~
    ?.  =(~ (rear p))  `p
    ~
  (most com urs:ab)
  ++  de-path
  ::   modified from apat:de-purl:html
  =/  delim  ;~(pose fas dot)
  %+  cook  :: get rid of the last dot and make the extension a part of the path
  |=  p=path  ?~  p  p
  =/  flopped=path  (flop p)
  =/  sr=path  (rash -.flopped (csplit dot))
  =/  rest=path  +.flopped
  %-  flop  %+  welp  (flop sr)  rest
  ;~(pfix fas (more fas smeg:de-purl:html))
  ++  atom-dots
  |=  s=@t  ^-  @ud
  =/  no-dots  (rush s dem)
  ?~  no-dots  (rash s dem:ag)  u.no-dots
  ++  csplit  |*  =rule  
  (more rule (cook crip (star ;~(less rule next))))
  ++  split  |*  =rule  
  (more rule (star ;~(less rule next)))
  ++  dinfix  |*  [pf=rule sf=rule]
  =/  neither  (star ;~(less ;~(pose pf sf) next))
  ;~(pfix pf ;~(sfix neither sf))
  ++  infix  
  |*  =rule
  (ifix [rule rule] (star ;~(less rule next)))

  ++  infix2
    |*  [delim=rule inner=rule]
    |=  tub=nail
    =+  vex=(delim tub)
    ?~  q.vex
      (fail tub)
    =/  but=nail  tub
    =+  outer=(;~(sfix (plus ;~(less delim next)) delim) q.u.q.vex)
    ?~  q.outer
      (fail tub)
    =+  in=(inner [1 1] p.u.q.outer)
    ?~  q.in
      (fail tub)
    outer(p.u.q p.u.q.in)
    
  ++  qux  (bass 16 (stun [4 4] hit))
  ++  better-dejson                                          ::  parse JSON
  =<  |=(a=cord `(unit json)`(rush a apex))
  |%
  ::                                                  ::  ++abox:de-json:html
  ++  abox                                            ::  array
    %+  stag  %a
    (ifix [sel (wish ser)] (more (wish com) apex))
  ::                                                  ::  ++apex:de-json:html
  ++  apex                                            ::  any value
    %+  knee  *json  |.  ~+
    %+  ifix  [spac spac]
    ;~  pose
      (cold ~ (jest 'null'))
      (stag %b bool)
      (stag %s stri)
      (cook |=(s=tape [%n p=(rap 3 s)]) numb)
      abox
      obox
    ==
  ::                                                  ::  ++bool:de-json:html
  ++  bool                                            ::  boolean
    ;~  pose
      (cold & (jest 'true'))
      (cold | (jest 'false'))
    ==
  ::                                                  ::  ++digs:de-json:html
  ++  digs                                            ::  digits
    (star (shim '0' '9'))
  ::                                                  ::  ++esca:de-json:html
  ++  esca                                            ::  escaped character
    ;~  pfix  bas
      =*  loo
        =*  lip
          ^-  (list (pair @t @))
          [b+8 t+9 n+10 f+12 r+13 ~]
        =*  wow  `(map @t @)`(malt lip)
        (sear ~(get by wow) low)
      =*  tuf  ;~(pfix (just 'u') (cook tuft qux))
      ;~(pose doq fas soq bas loo tuf)
    ==
  ::                                                  ::  ++expo:de-json:html
  ++  expo                                            ::  exponent
    ;~  (comp twel)
      (piec (mask "eE"))
      (mayb (piec (mask "+-")))
      digs
    ==
  ::                                                  ::  ++frac:de-json:html
  ++  frac                                            ::  fraction
    ;~(plug dot digs)
  ::                                                  ::  ++jcha:de-json:html
  ++  jcha                                            ::  string character
    ;~(pose ;~(less doq bas prn) esca)
  ::                                                  ::  ++mayb:de-json:html
  ++  mayb                                            ::  optional
    |*(bus=rule ;~(pose bus (easy ~)))
  ::                                                  ::  ++numb:de-json:html
  ++  numb                                            ::  number
    ;~  (comp twel)
      (mayb (piec hep))
      ;~  pose
        (piec (just '0'))
        ;~(plug (shim '1' '9') digs)
      ==
      (mayb frac)
      (mayb expo)
    ==
  ::                                                  ::  ++obje:de-json:html
  ++  obje                                            ::  object list
    %+  ifix  [(wish kel) (wish ker)]
    (more (wish com) pear)
  ::                                                  ::  ++obox:de-json:html
  ++  obox                                            ::  object
    (stag %o (cook malt obje))
  ::                                                  ::  ++pear:de-json:html
  ++  pear                                            ::  key-value
    ;~(plug ;~(sfix (wish stri) (wish col)) apex)
  ::                                                  ::  ++piec:de-json:html
  ++  piec                                            ::  listify
    |*  bus=rule
    (cook |=(a=@ [a ~]) bus)
  ::                                                  ::  ++stri:de-json:html
  ++  stri                                            ::  string
    (cook crip (ifix [doq doq] (star jcha)))
  ::                                                  ::  ++tops:de-json:html
  ++  tops                                            ::  strict value
    ;~(pose abox obox)
  ::                                                  ::  ++spac:de-json:html
  ++  spac                                            ::  whitespace
    (star (mask [`@`9 `@`10 `@`13 ' ' ~]))
  ::                                                  ::  ++twel:de-json:html
  ++  twel                                            ::  tape weld
    |=([a=tape b=tape] (weld a b))
  ::                                                  ::  ++wish:de-json:html
  ++  wish                                            ::  with whitespace
    |*(sef=rule ;~(pfix spac sef))
  --  ::de-json
  --  :: parsing
++  search
  |%
  ++  parse-query
  |=  query=@t  ^-  (map @t [query=@t neg=?])
  :: =s  \'"machine learning" OR "data science" lmao -filter:links -from:elonmusk since:2023-01-01 until:2023-10-12 lang:en filter:verified\'
  ~
  ++  apex
  %+  knee  **
  |.  ~+
  %-  star
  ;~  pose
    (stag %quot quotes)
    (stag %white (split:parsing ace))
    (stag %lol rest)
    :: next
  ==
++  rest  (plus ;~(less doq next))
++  quotes  (infix:parsing doq)
++  else  (star next)
  --
--