on 657b415 help sign in
948 lines 17 kB history raw
2### `++jo`
4JSON reparsing core
6Contains converters of [`++json`]() to [`++unit`]()s of well-typed structures.
8Accepts
9-------
11A `fist` is a gate that produces a `grub`.
13A `grub` is a unit of some JSON value.
15Source
16------
18 ++ jo :: json reparser
19 => |% ++ grub (unit ,*)
20 ++ fist $+(json grub)
21 |%
24### `++ar`
26Parse array to list
28Reparser modifier. Reparses an array to the [`++unit`]() of a homogenous
29[`++list`]() using `wit` to reparse every element.
31`wit` is a [`++fist`](), a JSON reparser.
34Accepts
35-------
37A [`++fist`]().
39Produces
40--------
42A [`++rule`]().
44Source
45------
46 ++ ar :: array as list
47 |* wit=fist
48 |= jon=json
49 ?. ?=([%a *] jon) ~
50 %- zl
51 |-
52 ?~ p.jon ~
53 [i=(wit i.p.jon) t=$(p.jon t.p.jon)]
54 ::
56Examples
57--------
59 ~zod/try=> :type; ((ar ni):jo a/~[n/'1' n/'2'])
60 [~ u=~[1 2]]
61 {[%~ u=it(@)] %~}
64### `++at`
66Reparse array as tuple
68Reparser generator. Reparses an array as a fixed-length tuple of
69[`++unit`]()s, using a list of `++fist`s.
71Accepts
72-------
74`wil` is a [`++pole`](), a [`face`]()less list of [`++fist`]()s.
76Produces
77--------
79A [`++rule`]().
81Source
82------
84 ++ at :: array as tuple
85 |* wil=(pole fist)
86 |= jon=json
87 ?. ?=([%a *] jon) ~
88 =+ raw=((at-raw wil) p.jon)
89 ?.((za raw) ~ (some (zp raw)))
90 ::
92Examples
93--------
95 ~zod/try=> ((at ni so ni ~):jo a/~[n/'3' s/'to' n/'4'])
96 [~ u=[q=3 ~.to q=4]]
97 ~zod/try=> :type; ((at ni so ni ~):jo a/~[n/'3' s/'to' n/'4'])
98 [~ u=[q=3 ~.to q=4]]
99 {{[%~ u=[q=@ @ta q=@]] %~} %~}
100 ~zod/try=> ((at ni so ni ~):jo a/~[n/'3' s/'to' n/''])
101 ~
103### `++at-raw`
105Reparse array to tuple
107Reparser generator. Reparses a list of [`++json`]() with `wil` to a tuple of [`++unit`]()s.
109Accepts
110-------
112`wil` is a [`++pole`](), a [face]()less list of [`++fist`]()s.
114Produces
115--------
117A [`++rule`]().
119Source
120------
122 ++ at-raw :: array as tuple
123 |* wil=(pole fist)
124 |= jol=(list json)
125 ?~ wil ~
126 :- ?~(jol ~ (-.wil i.jol))
127 ((at-raw +.wil) ?~(jol ~ t.jol))
128 ::
130Examples
131--------
133 ~zod/try=> ((at-raw ni ni bo ~):jo ~[s/'hi' n/'1' b/&])
134 [~ [~ 1] [~ u=%.y] ~]
136### `++bo`
138Reparse boolean
140Reparser modifier. Reparses a boolean to the [`++unit`]() of a
141boolean.
143Accepts
144-------
146A [`++json`]().
148Produces
149--------
151A [`++fist`]().
153Source
154------
156 ++ bo :: boolean
157 |=(jon=json ?.(?=([%b *] jon) ~ [~ u=p.jon]))
158 ::
160Examples
161--------
163 ~zod/try=> (bo:jo [%b &])
164 [~ u=%.y]
165 ~zod/try=> (bo:jo [%b |])
166 [~ u=%.n]
167 ~zod/try=> (bo:jo [%s 'hi'])
168 ~
170### `++bu`
172Reparse boolean not
174Reparser modifier. Reparses the inverse of a boolean to the [`++unit`]()
175of a loobean.
178Accepts
179-------
181A [`++json`]().
183Produces
184--------
186A [`++fist`]().
188Source
189------
191 ++ bu :: boolean not
192 |=(jon=json ?.(?=([%b *] jon) ~ [~ u=!p.jon]))
193 ::
195Examples
196--------
198 ~zod/try=> (bu:jo [%b &])
199 [~ u=%.n]
200 ~zod/try=> (bu:jo [%b |])
201 [~ u=%.y]
202 ~zod/try=> (bu:jo [%s 'hi'])
203 ~
205### `++cu`
207Reparse and transform
209Reparser modifier. Reparses `jon` and slams the result through `wit`,
210producing a [`++unit`]().
212Accepts
213-------
215`wit` is a [`++fist`]().
217`poq` is a [`gate`]() that accepts and returns a [noun]().
219Produces
220--------
222A [`++fist`]().
224Source
225------
227 ++ cu :: transform
228 |* [poq=$+(* *) wit=fist]
229 |= jon=json
230 (bind (wit jon) poq)
231 ::
233Examples
234--------
236 ~zod/try=> ((cu dec ni):jo [%n '20'])
237 [~ 19]
238 ~zod/try=> ((cu dec ni):jo [%b &])
239 ~
241### `++da`
243Reparse UTC date
245Reparser modifier. Reparses a UTC date string to a [`++unit`]().
247Accepts
248-------
250`jon` is a [`++json`]().
252Produces
253--------
255A [`++fist`]().
257Source
258------
260 ++ da :: UTC date
261 |= jon=json
262 ?. ?=([%s *] jon) ~
263 (bind (stud (trip p.jon)) |=(a=date (year a)))
264 ::
266Examples
267--------
269 ~zod/try=> (da:jo [%s 'Wed, 29 Oct 2014 0:26:15 +0000'])
270 [~ ~2014.10.29..00.26.15]
271 ~zod/try=> (da:jo [%s 'Wed, 29 Oct 2012 0:26:15'])
272 [~ ~2012.10.29..00.26.15]
273 ~zod/try=> (da:jo [%n '20'])
274 ~
276### `++di`
278Reparse millisecond date
280Reparser modifier. Reparses the javascript millisecond date integer to a
281[`++unit`]().
283Accepts
284-------
286`jon` is a [`++json`]().
288Produces
289--------
291A [`++fist`]().
293Source
294------
296 ++ di :: millisecond date
297 |= jon=json
298 %+ bind (ni jon)
299 |= a=@u ^- @da
300 (add ~1970.1.1 (div (mul ~s1 a) 1.000))
301 ::
303Examples
304--------
306 ~zod/try=> (di:jo [%s '2014-10-29'])
307 ~
308 ~zod/try=> (di:jo [%n '1414545548325'])
309 [~ ~2014.10.29..01.19.08..5333.3333.3333.3333]
310 ~zod/try=> (di:jo [%n '1414545615128'])
311 [~ ~2014.10.29..01.20.15..20c4.9ba5.e353.f7ce]
312 ~zod/try=> (di:jo [%n '25000'])
313 [~ ~1970.1.1..00.00.25]
315### `++mu`
317Reparse unit
319Reparser modifier. Reparses `wit` to a [`++unit`]().
321JSON units are considered to be either JSON null or the requested
322value, and are reparsed to results of \~ or (some {value}) respectively.
324Accepts
325-------
327`wit` is a [`++fist`]().
329Produces
330--------
332A [`++fist`]().
334Source
335------
337 ++ mu :: true unit
338 |* wit=fist
339 |= jon=json
340 ?~(jon (some ~) (bind (wit jon) some))
341 ::
343Examples
344--------
346 ~zod/try=> ((mu ni):jo [%n '20'])
347 [~ [~ u=q=20]]
348 ~zod/try=> ((mu ni):jo [%n '15'])
349 [~ [~ u=q=15]]
350 ~zod/try=> ((mu ni):jo ~)
351 [~ u=~]
352 ~zod/try=> ((mu ni):jo [%s 'ma'])
353 ~
355### `++ne`
357Reparse number as real
359XX Currently unimplemented
361A- yup, this will eventually reparse a floating point atom, but
362interfaces for the latter are not currently stable.
364### `++ni`
366Reparse number as integer
368Reparser modifier. Reparses an integer representation to a [`++unit]().
370Accepts
371-------
373`jon` is a ++[`++json`]().
375Produces
376--------
378The `++unit` of an atom.
380Source
381------
383 ++ ni :: number as integer
384 |= jon=json
385 ?. ?=([%n *] jon) ~
386 (rush p.jon dem)
387 ::
389Examples
390--------
392 ~zod/try=> (ni:jo [%n '0'])
393 [~ q=0]
394 ~zod/try=> (ni:jo [%n '200'])
395 [~ q=200]
396 ~zod/try=> (ni:jo [%n '-2.5'])
397 ~
398 ~zod/try=> (ni:jo [%s '10'])
399 ~
400 ~zod/try=> (ni:jo [%b |])
401 ~
402 ~zod/try=> (ni:jo [%n '4'])
403 [~ q=4]
404 ~zod/try=> (ni:jo [%a ~[b/& b/& b/& b/&]])
405 ~
407### `++no`
409Reparse number as text
411Reparser modifier. Reparses a numeric representation to a [++cord]().
413Accepts
414-------
416`jon` is a `++json`.
418Produces
419--------
421The [`++unit`]() of a `++cord`.
423Source
424------
426 ++ no :: number as text
427 |= jon=json
428 ?. ?=([%n *] jon) ~
429 (some p.jon)
430 ::
432Examples
433--------
435 ~zod/try=> (no:jo [%n '0'])
436 [~ u=~.0]
437 ~zod/try=> (no:jo [%n '200'])
438 [~ u=~.200]
439 ~zod/try=> (no:jo [%n '-2.5'])
440 [~ u=~.-2.5]
441 ~zod/try=> (no:jo [%s '10'])
442 ~
443 ~zod/try=> (no:jo [%b |])
444 ~
445 ~zod/try=> (no:jo [%n '4'])
446 [~ u=~.4]
447 ~zod/try=> (no:jo [%a ~[b/& b/& b/& b/&]])
448 ~
450### `++of`
452Reparse object to frond
454Reparser generator. Reparses an object, succeeding if it corresponds to
455one of the key-value pairs in `wer`.
457Accepts
458-------
460`wer` is a [`++pole`](), a [`++face`]()less list of [`++cord`]() and
461[`++fist`]() key-value pairs.
463Produces
464--------
466The [`++unit`]() of a cell of a.....
468Source
469------
471 ++ of :: object as frond
472 |* wer=(pole ,[cord fist])
473 |= jon=json
474 ?. ?=([%o [@ *] ~ ~] jon) ~
475 |-
476 ?~ wer ~
477 ?: =(-.-.wer p.n.p.jon)
478 ((pe -.-.wer +.-.wer) q.n.p.jon)
479 ((of +.wer) jon)
480 ::
482Examples
483--------
485 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%sem s/'hi'] ~ ~)
486 [~ [%sem "hi"]]
487 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%som n/'20'] ~ ~)
488 [~ [%som q=20]]
489 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%som s/'he'] ~ ~)
490 ~
491 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%som s/'5'] ~ ~)
492 ~
493 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%sem s/'5'] ~ ~)
494 [~ [%sem "5"]]
495 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%sem n/'2'] ~ ~)
496 ~
497 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%sem b/&] ~ ~)
498 ~
499 ~zod/try=> ((of sem/sa som/ni ~):jo %a ~[s/'som' n/'4'])
500 ~
501 ~zod/try=> ((of sem/sa som/ni ~):jo %o [%sem s/'hey'] ~ [%sam s/'other value'] ~ ~)
502 ~
504### `++ot`
506Reparse object as tuple
508Reparser generator. For every key in `wer` that matches a key in the
509[`++edge`], the fist in `wer` is applied to the corresponding value in
510the [`++edge`](), the results of which are produced in a tuple.
513Accepts
514-------
516`wer` is a [`++pole`]() of [`++cord`]() to [`++fist`]() key-value pairs.
518Produces
519--------
521A [`++unit`]() of a tuple XX?
523Source
524------
526 ++ ot :: object as tuple
527 |* wer=(pole ,[cord fist])
528 |= jon=json
529 ?. ?=([%o *] jon) ~
530 =+ raw=((ot-raw wer) p.jon)
531 ?.((za raw) ~ (some (zp raw)))
532 ::
534Examples
535--------
537 ~zod/try=> (jobe [%sem s/'ha'] [%som n/'20'] ~)
538 [%o p={[p='sem' q=[%s p=~.ha]] [p='som' q=[%n p=~.20]]}]
539 ~zod/try=> ((ot sem/sa som/ni sem/sa ~):jo (jobe [%sem s/'ha'] [%som n/'20'] ~))
540 [~ u=["ha" q=20 "ha"]]
542### `++ot-raw`
544Reparser generator. Reparses a map `jom` using `wer`; for every key in
545`wer` that matches a key in `map`, the corresponding `++fist` is applied
546to the corresponding value in `jom`, the results of which are produced
547in a tuple.
550Accepts
551-------
553`wer` is a [`++pole`]() of [`++cord`]() to [`++fist`]() key-value pairs.
555Produces
556--------
558A [`++unit`]() of.
560Source
561------
563 ++ ot-raw :: object as tuple
564 |* wer=(pole ,[cord fist])
565 |= jom=(map ,@t json)
566 ?~ wer ~
567 =+ ten=(~(get by jom) -.-.wer)
568 [?~(ten ~ (+.-.wer u.ten)) ((ot-raw +.wer) jom)]
569 ::
571Examples
572--------
574 ~zod/try=> ((ot-raw sem/sa som/ni sem/sa ~):jo (mo [%sem s/'ha'] [%som n/'20'] ~))
575 [[~ u="ha"] [~ q=20] [~ u="ha"] ~]
576 ~zod/try=> ((ot-raw sem/sa som/ni sem/sa ~):jo (mo [%sem s/'ha'] [%som b/|] ~))
577 [[~ u="ha"] ~ [~ u="ha"] ~]
579### `++om`
581Parse object to map
583Reparser modifier. Reparses a [`++json`]() object to a homogenous map
584using `wit`.
586Accepts
587-------
589`wit` is a [`++fist`]().
591Produces
592--------
594A [`++unit`]() of...
596Source
597------
599 ++ om :: object as map
600 |* wit=fist
601 |= jon=json
602 ?. ?=([%o *] jon) ~
603 (zm ~(run by p.jon) wit)
604 ::
606Examples
607--------
609 ~zod/try=> ((om ni):jo (jobe [%sap n/'20'] [%sup n/'5'] [%sop n/'177'] ~))
610 [~ {[p='sup' q=q=5] [p='sop' q=q=177] [p='sap' q=q=20]}]
611 ~zod/try=> ((om ni):jo (jobe [%sap n/'20'] [%sup n/'0x5'] [%sop n/'177'] ~))
612 ~
614### `++pe`
616Add prefix
618Reparser modifier. Adds a static prefix `pre` to the parse result of
619`wit`. See also: [`++stag`]().
621Accepts
622-------
624`pre` is a prefix [`noun`]().
626Produces
627--------
629The [`++unit`]() of a cell of [noun]() and the result of parsing `wit`.
631Source
632------
634 ++ pe :: prefix
635 |* [pre=* wit=fist]
636 (cu |*(a=* [pre a]) wit)
637 ::
639Examples
640--------
642 ~zod/try=> (ni:jo n/'2')
643 [~ q=2]
644 ~zod/try=> (ni:jo b/|)
645 ~
646 ~zod/try=> ((pe %hi ni):jo n/'2')
647 [~ [%hi q=2]]
648 ~zod/try=> ((pe %hi ni):jo b/|)
649 ~
651### `++sa`
653Reparse string to tape
655Reparser modifier. Reparses a [`++json`]() string to a [`++tape`]().
657Accepts
658-------
660`jon` is a [`++json`]().
662Produces
663--------
665The [`++unit`]() of a [`++tape`]().
667Source
668------
670 ++ sa :: string as tape
671 |= jon=json
672 ?.(?=([%s *] jon) ~ (some (trip p.jon)))
673 ::
675Examples
676--------
678 ~zod/try=> (sa:jo s/'value')
679 [~ u="value"]
680 ~zod/try=> (sa:jo n/'46')
681 ~
682 ~zod/try=> (sa:jo a/~[s/'val 2'])
683 ~
685### `++so`
687Reparse string to cord
689Reparser modifier. Reparses a string to a [`++cord`]().
691Accepts
692-------
694`jon` is a [`++json`]().
696Produces
697--------
699The [`++unit`]() of a [`++cord`]().
701Source
702------
704 ++ so :: string as cord
705 |= jon=json
706 ?.(?=([%s *] jon) ~ (some p.jon))
707 ::
709Examples
710--------
712 ~zod/try=> (so:jo s/'value')
713 [~ u=~.value]
714 ~zod/try=> (so:jo n/'46')
715 ~
716 ~zod/try=> (so:jo a/~[s/'val 2'])
717 ~
719### `++su`
721Reparse string
723Reparser generator. Produces a reparser that applies `sab` to a string.
725Accepts
726-------
728`sab` is a [`++rule`].
730Produces
731--------
733A [`++rule`]().
735Source
736------
738 ++ su :: parse string
739 |* sab=rule
740 |= jon=json
741 ?. ?=([%s *] jon) ~
742 (rush p.jon sab)
743 ::
745Examples
746--------
748 ~zod/try=> ((su:jo fed:ag) s/'zod')
749 [~ 0]
750 ~zod/try=> ((su:jo fed:ag) s/'doznec')
751 [~ 256]
752 ~zod/try=> ((su:jo fed:ag) s/'notship')
753 ~
754 ~zod/try=> ((su:jo fed:ag) n/'20')
755 ~
757### `++ul`
759Reparse null
761Reparser modifier. Reparses a null value.
763Accepts
764-------
766`jon` is a [`++json`]().
768Produces
769--------
771The [`++unit`]() of null.
773Source
774------
776 ++ ul |=(jon=json ?~(jon (some ~) ~)) :: null
778Examples
779--------
781 ~zod/try=> (ul:jo `json`~)
782 [~ u=~]
783 ~zod/try=> (ul:jo s/'null')
784 ~
785 ~zod/try=> (ul:jo b/|)
786 ~
787 ~zod/try=> (ul:jo b/&)
788 ~
790### `++za`
792Pole of nonempty units
794Determines if `pod` contains all non-empty units, producing a boolean. Used
795internally.
797Accepts
798-------
800`pod` is a [`++pole`]() of [`++unit`]().
802Produces
803--------
805A boolean.
807Source
808------
810 ++ za :: full unit pole
811 |* pod=(pole (unit))
812 ?~ pod &
813 ?~ -.pod |
814 (za +.pod)
815 ::
817Examples
818--------
820 ~zod/try=> (za:jo ~[`1 `2 `3])
821 %.y
822 ~zod/try=> (za:jo ~[`1 ~ `3])
823 %.n
825### `++zl`
827Collapse unit list
829Produces a unit of the values of `lut` if every unit in `lut` is
830nonempty. Otherwise, produces `~`.
832Accepts
833-------
835`lut` is a [`++list`]() of [`++unit`]()s.
837Produces
838--------
840A boolean.
842Source
843------
845 ++ zl :: collapse unit list
846 |* lut=(list (unit))
847 ?. |- ^- ?
848 ?~(lut & ?~(i.lut | $(lut t.lut)))
849 ~
850 %- some
851 |-
852 ?~ lut ~
853 [i=u:+.i.lut t=$(lut t.lut)]
854 ::
856Examples
857--------
859 ~zod/try=> (zl:jo `(list (unit))`~[`1 `2 `3])
860 [~ u=~[1 2 3]]
861 ~zod/try=> (zl:jo `(list (unit))`~[`1 `17 `3])
862 [~ u=~[1 17 3]]
863 ~zod/try=> (zl:jo `(list (unit))`~[`1 ~ `3])
864 ~
866### `++zp`
868XX
870Collapses a `++pole` of `++unit`s `but`, producing a tuple.
872Accepts
873-------
875`but` is a [`++pole`]() of [`++unit`]().
877Produces
878--------
880??
882Source
883------
885 ++ zp :: unit tuple
886 |* but=(pole (unit))
887 ?~ but !!
888 ?~ +.but
889 u:->.but
890 [u:->.but (zp +.but)]
891 ::
893Examples
894--------
896 ~zod/try=> (zp:jo `(pole (unit))`~[`1 `2 `3])
897 [1 2 3]
898 ~zod/try=> (zp:jo `(pole (unit))`~[`1 `17 `3])
899 [1 17 3]
900 ~zod/try=> (zp:jo `(pole (unit))`~[`1 ~ `3])
901 ! exit
903### `++zm`
905Collapse unit map
907Produces a [`++unit`]() of the [`++map`]() `lum` of term to `++unit` key value
908pairs, with all of the nonempty values stripped of their `++unit`
909wrappers. If any of the `++units` in `lum` are empty, `~` is produced.
910See also: [`++zp`](), [`++zl`]().
912Accepts
913-------
915`lum` is a map of [`++term`]() to [`++unit`]()s.
917Produces
918--------
920The `++unit` of a tuple of what were the key-value pairs of `lum`.
922Source
923------
925 ++ zm :: collapse unit map
926 |* lum=(map term (unit))
927 ?: (~(rep by lum) | |=([[@ a=(unit)] b=?] |(b ?=(~ a))))
928 ~
929 (some (~(run by lum) need))
930 ::
932Examples
933--------
935 ~zod/try=> (zm:jo `(map term (unit ,@u))`(mo a/`4 b/`1 c/`2 ~))
936 [~ {[p=%a q=4] [p=%c q=2] [p=%b q=1]}]
937 ~zod/try=> (zm:jo `(map term (unit ,@u))`(mo a/`4 b/~ c/`2 ~))
938 ~
939 ~zod/try=> (~(run by `(map ,@t ,@u)`(mo a/1 b/2 c/3 ~)) (flit |=(a=@ (lth a 5))))
940 {[p='a' q=[~ u=1]] [p='c' q=[~ u=3]] [p='b' q=[~ u=2]]}
941 ~zod/try=> (zm:jo (~(run by `(map ,@t ,@u)`(mo a/1 b/2 c/3 ~)) (flit |=(a=@ (lth a 5)))))
942 [~ {[p='a' q=1] [p='c' q=3] [p='b' q=2]}]
943 ~zod/try=> (zm:jo (~(run by `(map ,@t ,@u)`(mo a/1 b/7 c/3 ~)) (flit |=(a=@ (lth a 5)))))
944 ~
945 ~zod/try=> (~(run by `(map ,@t ,@u)`(mo a/1 b/7 c/3 ~)) (flit |=(a=@ (lth a 5))))
946 {[p='a' q=[~ u=1]] [p='c' q=[~ u=3]] [p='b' q=~]}