From 5798c490b1c485dbc9aafde6c0e0c38c2ff7c3fe Mon Sep 17 00:00:00 2001 From: Anton Dyudin Date: Tue, 28 Oct 2014 11:55:44 -0700 Subject: [PATCH] Moved spat/spud/stab, refactored json --- arvo/hoon.hoon | 12 +++++------ arvo/zuse.hoon | 57 ++++++++++++++------------------------------------ 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/arvo/hoon.hoon b/arvo/hoon.hoon index d4652b3793..45ea71d598 100644 --- a/arvo/hoon.hoon +++ b/arvo/hoon.hoon @@ -3672,6 +3672,12 @@ :+ %rose [['/' ~] ['/' ~] ['/' ~]] |- ^- (list tank) (turn bon |=(a=@ [%leaf (rip 3 a)])) +:: +++ spat |=(pax=path (crip (spud pax))) :: path to cord +++ spud |=(pax=path ~(ram re (smyt pax))) :: path to tape +++ stab :: parse span to path + |= zep=@ta ^- path + (rash zep ;~(pfix fas (more fas urs:ab))) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: section 2eM, regular-expressions :: :: @@ -6096,7 +6102,6 @@ |= typ=type ^- tank ~(duck ut typ) :: -++ spat |=(pax=path (rap 3 (spud pax))) :: path to cord ++ spec :: reconstruct type |= vax=vase ^- vase @@ -6108,7 +6113,6 @@ [%wtgr [%wtts [%leaf %tas -.q.vax] [%$ 2]~] [%$ 1]] (~(fuse ut p.vax) [%cell %noun %noun]) :: -++ spud |=(pax=path ~(ram re (dish:ut [~ %path] pax))) :: path to tape ++ slew :: get axis in vase |= [axe=@ vax=vase] ^- (unit vase) ?. |- ^- ? @@ -6144,10 +6148,6 @@ [* * *] $(wad [n.wad ~ r.wad], vax $(wad l.wad)) == :: -++ stab :: parse cord to path - |= zep=@ta ^- path - (need (rush zep ;~(pfix fas ;~(sfix (more fas urs:ab) fas)))) -:: ++ wash :: render tank at width |= [[tab=@ edg=@] tac=tank] ^- wall (~(win re tac) tab edg) diff --git a/arvo/zuse.hoon b/arvo/zuse.hoon index 33adf24c23..66c58d5e44 100644 --- a/arvo/zuse.hoon +++ b/arvo/zuse.hoon @@ -501,58 +501,38 @@ $(a +.a) == :: -++ poja :: parse JSON +++ poja !: :: parse JSON |% - ++ apex :: JSON object - ;~(pose abox obox) + ++ apex ;~(pose abox obox) :: JSON object ++ valu :: JSON value %+ knee *json |. ~+ ;~ pfix spac ;~ pose (cold ~ (jest 'null')) - (jify %b bool) - (jify %s stri) + (stag %b bool) + (stag %s stri) (cook |=(s=tape [%n p=(rap 3 s)]) numb) abox obox == == :: JSON arrays - ++ arra (ifix [sel (ws ser)] (more (ws com) valu)) - ++ abox (cook |=(elts=(list json) [%a p=elts]) arra) + ++ abox (stag %a (ifix [sel (ws ser)] (more (ws com) valu))) :: JSON objects - ++ pair ;~((comp |=([k=@ta v=json] [k v])) ;~(sfix (ws stri) (ws col)) valu) + ++ pair ;~(plug ;~(sfix (ws stri) (ws col)) valu) ++ obje (ifix [(ws kel) (ws ker)] (more (ws com) pair)) - ++ obox (cook |=(s=(list ,[@ta json]) [%o p=(mo s)]) obje) + ++ obox (stag %o (cook mo obje)) :: JSON booleans ++ bool ;~(pose (cold & (jest 'true')) (cold | (jest 'false'))) :: JSON strings - ++ stri - (cook |=(s=(list ,@) (rap 3 s)) (ifix [doq doq] (star jcha))) - ++ jcha :: character in string - ;~ pose - esca - ;~ pose - :: Non-escape string characters - (shim 32 33) - (shim 35 91) - (shim 93 126) - (shim 128 255) - == - == + ++ stri (cook crip (ifix [doq doq] (star jcha))) + ++ jcha ;~(pose ;~(less doq bas prn) esca) :: character in string ++ esca :: Escaped character ;~ pfix bas ;~ pose - doq - fas - soq - bas - (cold 8 (just 'b')) - (cold 9 (just 't')) - (cold 10 (just 'n')) - (cold 12 (just 'f')) - (cold 13 (just 'r')) - ;~(pfix (just 'u') (cook tuft qix:ab)) :: Convert 4-digit hex to UTF-8 + doq fas soq bas + (sear ~(get by `(map ,@t ,@)`(mo b/8 t/9 n/10 f/12 r/13 ~)) low) + ;~(pfix (just 'u') (cook tuft qix:ab)) :: 4-digit hex to UTF-8 == == :: JSON numbers @@ -561,28 +541,23 @@ (mayb (piec hep)) ;~ pose (piec (just '0')) - ;~((comp twel) (piec (shim '1' '9')) digs) + ;~(plug (shim '1' '9') digs) == (mayb frac) (mayb expo) == ++ digs (star (shim '0' '9')) - ++ expo :: Exponent part + ++ expo :: Exponent part ;~ (comp twel) (piec (mask "eE")) (mayb (piec (mask "+-"))) digs == - ++ frac :: Fractional part - ;~ (comp twel) - (piec dot) - digs - == + ++ frac ;~(plug dot digs) :: Fractional part :: whitespace ++ spac (star (mask [`@`9 `@`10 `@`13 ' ' ~])) ++ ws |*(sef=_rule ;~(pfix spac sef)) :: plumbing - ++ jify |*([t=@ta r=_rule] (cook |*([v=*] [t p=v]) r)) ++ mayb |*(bus=_rule ;~(pose bus (easy ""))) ++ twel |=([a=tape b=tape] (weld a b)) ++ piec @@ -2311,7 +2286,7 @@ [p.one [%& [*cart (weld q.q.q.one q.q.q.two)]]] :: ++ glam - |= zar=@p ^- tape + |= zar=@pD ^- tape %+ snag zar ^- (list tape) :~ "Tianming" "Pepin the Short" "Haile Selassie" "Alfred the Great"