Largely complete /lib/talk-json (still missing diffs), /mar/talk/action.

This commit is contained in:
Fang 2017-10-19 23:58:18 +02:00
parent 7fdcf344e3
commit 7d4e0512cf
2 changed files with 226 additions and 35 deletions

View File

@ -3,23 +3,155 @@
::
/- talk
::
::> rules for sur-json conversion: (proposal, adhered to below)
::> proposed rules for sur-json conversion, adhered to below:
::> 1. to save the devs from having to learn multiple interfaces, try to match
::> the hoon structure as closely as possible, including attribute names.
::> 2. if these names are p/q/r, slightly more semantic naming is preferred.
::> 2. if these names are p/q/r, ~slightly more semantic naming is preferred~
::> fix that in the sur file.
::> 2. when dealing with $%, the tag is the variable name. ie `{$x ...}` -> `x`
::> for tagged unions with one piece of data, `x` holds that value.
::> for tagged unions with multiple pieces of data, `x` is an object.
::> 3. ...
::> 3. lists and sets become arrays. maps become objects.
::> 4. stringify cells only when/in a way such that it benefits the majority of
::> foreseen usecases.
::
=, talk
|%
++ en-json ::> sur to json
++ en-tape ::> sur to tape
=, talk
|%
++ circ ::> circle
|= a/circle
:(weld (scow %p hos.a) "/" (trip nom.a))
::
++ rang ::> range
|= a/range
?~ a ~
;: weld
"/" (scow hed.u.a)
?~ tal.u.a ~
(scow u.tal.u.a)
==
::
++ sorc ::> source
|= a/source
(weld (circ cir.a) (rang ran.a))
--
::
++ de-tape ::> tape to sur (parse)
=, talk
|%
++ circ ::> circle
;~((glue fas) ;~(pfix sig fed:ag) urt:ab)
::
++ rang ::> range
=/ pont
;~ pose
(stag %ud dim:ag)
%+ stag %da
%+ sear
|= a/coin
^- (unit @da)
?. ?=({$$ $da @da} a) ~
`q.p.a
nuck:so
==
=+ ;~ pose
(cook some ;~(pfix fas pont))
(easy ~)
==
;~ pose
(cook some ;~(plug ;~(pfix fas pont) -))
(easy ~)
==
::
++ sorc ::> source
;~(plug circ rang)
--
::
++ en-json ::> sur to json
=, talk
=, enjs:format
|%
::TODO these first few should probably make their way
:: into the stdlib...
++ sa ::> set as array
|* {a/(set) b/$-(* json)}
^- json
[%a ~(tap in (~(run in a) b))]
::
++ dank ::> tank
|= a/tank
?: ?=($leaf -.a) (frond %leaf (tape p.a))
%+ frond -.a
%- pairs
?- -.a
$palm
:+ :- %style
%- pairs :~
mid+(tape p.p.a)
cap+(tape q.p.a)
open+(tape r.p.a)
close+(tape s.p.a)
==
lines+a+(turn q.a dank)
~
$rose
:+ :- %style
%- pairs :~
mid+(tape p.p.a)
open+(tape q.p.a)
close+(tape r.p.a)
==
lines+a+(turn q.a dank)
~
==
::
::
++ circ ::> circle
|= a/circle
^- json
s+(crip (circ:en-tape a))
::
++ filt ::> filter
|= a/filter
^- json
(pairs cas+b+cas.a utf+b+utf.a ~)
::
++ sorc ::> source
|= a/source
^- json
s+(crip (sorc:en-tape a))
::
++ spec ::> speech
|= a/speech
^- json
:: only %url has just a single piece of data.
?: ?=($url -.a)
(frond %url s+(crip (apix:en-purl:html url.a)))
%+ frond -.a
%- pairs
?- -.a
$lin ~[pat+b+pat.a msg+s+msg.a]
$exp ~[exp+s+exp.a res+a+(turn res.a dank)]
$ire ~[top+s+(scot %uv top.a) sep+(spec sep.a)] ::TODO @uv as number?
$fat ~[tac+(atta tac.a) sep+(spec sep.a)]
$inv ~[inv+b+inv.a cir+(circ cir.a)]
$app ~[app+s+app.a msg+s+msg.a]
==
::
++ atta ::> attache
|= a/attache
^- json
%+ frond -.a
?- -.a
$name (pairs nom+s+nom.a tac+(atta tac.a) ~)
$text s+(of-wain:format +.a)
$tank a+(turn +.a dank)
==
--
::
++ de-json ::> json to sur
=, talk
=, dejs-soft:format
|%
::TODO these first few should maybe make their way
@ -40,8 +172,8 @@
++ dist
^- $-(json (unit diff-status))
%- of :~
full+(ot pec+(su pres) man+huma ~)
presence+(su pres)
full+(ot pec+pres man+huma ~)
presence+pres
human+dihu
remove+ul
==
@ -51,7 +183,7 @@
%- of :~
full+huma
handle+(mu so)
true+
true+(mu trun)
==
::
::> ||
@ -60,22 +192,29 @@
::> messaging targets and their metadata.
::+|
::
::TODO maybe just an object?
++ circ ::> circle
^- $-(nail (like circle))
;~((glue fas) ;~(pfix sig fed:ag) urt:ab)
^- $-(json (unit circle))
(su circ:de-tape)
::
::TODO maybe just an object?
++ sorc ::> source
^- $-(json (unit source))
(su sorc:de-tape)
::
++ filt ::> filter
^- $-(json (unit filter))
(ot cas+bo utf+bo ~)
::
++ pres ::> presence
^- $-(nail (like presence))
(perk %gone %idle %hear %talk ~)
^- $-(json (unit presence))
(su (perk %gone %idle %hear %talk ~))
::
++ huma ::> human
^- $-(json (unit human))
%- ot :~
han+(mu so)
tru+(mu true)
==
(ot han+(mu so) tru+(mu trun) ~)
::
++ true ::> truename
++ trun ::> truename
^- $-(json (unit truename))
(ot fir+so mid+(mu so) las+so ~)
::
@ -85,6 +224,21 @@
::> structures for containing main message data.
::+|
::
::++ enve ::> envelope
:: ^- $-(json (unit thought))
:: (ot num+ni gam+gram ~)
::
++ gram ::> telegram
^- $-(json (unit telegram))
%- ot :~
aut+(su fed:ag)
::TODO can we do anything about this duplication?
uid+seri
aud+audi
wen+di
sep+spec
==
::
++ thot ::> thought
^- $-(json (unit thought))
%- ot :~
@ -95,21 +249,22 @@
==
::
++ spec ::> speech
^- $-(json (unit speech))
%- of :~
lin+(ot pat+bo txt+so ~)
url+(su aurf:de-purl:html)
exp+(ot exp+so res+(ar dank) ~)
ire+(ot top+seri sep+spec ~)
fat+(ot tac+atta sep+spec ~)
inv+(ot inv+bo cir+(su circ) ~)
==
::^- $-(json (unit speech))
(of lin+(ot pat+bo txt+so ~) ~)
::%- of :~
:: lin+(ot pat+bo txt+so ~)
:: url+(su aurf:de-purl:html)
:: exp+(ot exp+so res+(ar dank) ~)
:: ire+(ot top+seri sep+spec ~)
:: fat+(ot tac+atta sep+spec ~)
:: inv+(ot inv+bo cir+circ ~)
::==
::
++ atta ::> attache
^- $-(json (unit attache))
%- of :~
name+(ot nom+so tac+atta ~)
text+(ar so)
text+(cu to-wain:format so)
tank+(ar dank)
==
::
@ -125,6 +280,6 @@
::
++ audi ::> audience
^- $-(json (unit audience))
(as (su circ))
(as circ)
--
--

View File

@ -1,26 +1,62 @@
::
:::: /mar/talk/rumor/hoon
:::: /mar/talk/action/hoon
::
/- talk
/+ talk-json
::
=, talk
|_ dif/action
|_ act/action:talk
::
++ grab ::> convert from
|%
++ noun action ::< from %noun
++ noun action:talk ::< from %noun
++ json ::> from %json
=, de-json:talk-json
=, dejs-soft:format
=, talk-json:de-json
|= a/json ^- action
|= a/json
^- action:talk
=- (need ((of -) a))
:~ create+ul
:~ create+(ot nom+so des+so sec+pres ~)
delete+(ot nom+so why+(mu so) ~)
depict+(ot nom+so des+so ~)
filter+(ot nom+so fit+filt ~)
permit+(ot nom+so inv+bo sis+audi ~)
source+(ot nom+so aub+bo srs+(as sorc) ~)
::
convey+(ar thot)
phrase+(ot aud+audi ses+(ar spec) ~)
::
notify+(ot aud+audi pes+prec ~)
naming+(ot aud+audi man+huma ~)
::
glyph+(ot gyf+so aud+audi bin+bo ~)
nick+(ot who+ship nic+so ~)
==
--
::
++ grow ::> convert to
|%
++ json ::> to %json
=, en-json:talk-json
=, enjs:format
%+ frond -.act
::> only %convey has just a single piece of data.
?: ?=($convey -.act) a+(turn tos.act thot)
%- pairs
?- -.act
$create ~[nom+s+nom.act des+s+des.act sec+s+sec.act]
$delete ~[nom+s+nom.act why+?~(why.sec ~ s+why.sec)]
$depict ~[nom+s+nom.act des+s+des.act]
$filter ~[nom+s+nom.act fit+(filt fit.act)]
$permit ~[nom+s+nom.act inv+b+inv.act sis+(sa sis.act ship)]
$source ~[nom+s+nom.act sub+b+sub.act srs+(sa srs.act sorc)]
::
$phrase ~[aud+(sa aud.act circ) ses+a+(turn ses.act spec)]
::
$notify ~[aud+(sa cis.act circ) pes+(prec pes.act)]
$naming ~[aud+(sa cis.act circ) man+(huma man.act)]
::
$glyph ~[gyf+s+gyf.act aud+(sa circ) bin+b+bin.act]
$nick ~[who+s+(ship who.act) nic+s+nic.act]
==
--
--