Moved spat/spud/stab, refactored json

This commit is contained in:
Anton Dyudin 2014-10-28 11:55:44 -07:00 committed by Anton Dyudin
parent b26deda123
commit 5798c490b1
2 changed files with 22 additions and 47 deletions

View File

@ -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)

View File

@ -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,7 +541,7 @@
(mayb (piec hep))
;~ pose
(piec (just '0'))
;~((comp twel) (piec (shim '1' '9')) digs)
;~(plug (shim '1' '9') digs)
==
(mayb frac)
(mayb expo)
@ -573,16 +553,11 @@
(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"