Added ++scanf, beginnings of 3b doc

This commit is contained in:
Anton Dyudin 2014-08-12 16:16:30 -07:00 committed by Anton Dyudin
parent 4016124e87
commit 2526a5c29f
3 changed files with 112 additions and 3 deletions

View File

@ -1769,6 +1769,11 @@
|* c=_+<+.a
(a b c)
::
++ curr
|* [a=_|=(^ _*) c=*]
|* b=_+<+.a
(a b c)
::
++ hard
|* han=$+(* *)
|= fud=* ^- han

View File

@ -815,6 +815,40 @@
92 "\\\\"
==
::
++ scanf :: formatted scan
|* [tape (pole ,_:/(*$&(_rule tape)))]
=> .(+< [a b]=+<)
(scan a (parsf b))
++ parsf :: make parser from:
|^ |* (pole ,_:/(*$&(_rule tape))) :: ;"chars{rule}chars"
=> .(+< a=+<)
%- cook :_ (bill (norm a))
|* (list)
?~ +< ~
?~ t i
[i $(+< t)]
:: .= (norm [;"{n}, {n}"]:n=dim:ag) ~[[& dim] [| ", "] [& dim]]:ag
++ norm
|* (pole ,_:/(*$&(_rule tape)))
?~ +< ~
=> .(+< [i=+<- t=+<+])
:_ t=$(+< t)
=+ rul=->->.i
^= i
?~ rul [%| p=rul]
?~ +.rul [%| p=rul]
?@ &2.rul [%| p=;;(tape rul)]
[%& p=rul]
:: .= (bill ~[[& dim] [| ", "] [& dim]]:ag)
:: ;~(plug dim ;~(pfix com ace ;~(plug dim (easy)))):ag
++ bill
|* (list (each ,_rule tape))
?~ +< (easy ~)
?: ?=(| -.i) ;~(pfix (jest (crip p.i)) $(+< t))
%+ cook |*([* *] [i t]=+<)
;~(plug p.i $(+< t))
--
::
++ taco :: atom to octstream
|= tam=@ ^- octs
[(met 3 tam) tam]
@ -2595,10 +2629,11 @@
?: ?=(| -.mud) mud
(mule |.((slam p.mud sam)))
::
++ numb :: ship display name?
|= [him=@p now=@da] ^- @t
++ numb :: ship display name
|= [him=@p our=@p now=@da] ^- @t
=+ yow=(scot %p him)
=+ woy=((hard ,@t) .^(%a yow %name (scot %da now) ~))
=+ pax=[(scot %p our) %name (scot %da now) yow ~]
=+ woy=((hard ,@t) .^(%a pax))
?: =(%$ woy) yow
(cat 3 yow (cat 3 ' ' woy))
::

View File

@ -0,0 +1,69 @@
##section 3b, standard library
###section 3bD, JSON and XML
####`++jo`, json reparser
Contains converters of ++json to well-typed structures.
```
=> |% ++ grub (unit ,*)
++ fist $+(json grub)
--
```
A `fist` is a gate that produces some manner of unit from json. Most arms in
`++jo` are fists, or produce them.
#####`++ar`
Parse JSON array as typed list.
```
~zod/try=> :type; ((ar ni):jo a/~[n/'1' n/'2'])
[~ u=~[1 2]]
{[%~ u=it(@)] %~}
```
#####`++at`
Parse JSON array as a fixed-length tuple.
```
~zod/try=> :type; ((ar ni):jo a/~[n/'3' s/'to' n/''])
[~ u=[3 'to' 4]]
{[%~ u=[@ @ta @]] %~}
```
#####`++bo`
|=(jon=json ?.(?=([%b *] jon) ~ [~ u=p.jon]))
Parse JSON boolean.
#####`++bo`
|=(jon=json ?.(?=([%b *] jon) ~ [~ u=!p.jon]))
Parse inverse of JSON boolean.
XX Finish
####`++scanf`
Scan with `;"`-interpolated parsers
```
~zod/try=> `[p=@ud q=@ud]`(scanf "Score is 5 to 2" [;"Score is {n} to {n}"]:n=dim:ag)
[p=5 q=2]
```
```
~zod/try=> =n ;~(pfix (star (just '0')) (cook |=(@ud +<) dim:ag))
~zod/try=> (scanf "2014-08-12T23:10:58.931Z" ;"{n}\-{n}\-{n}T{n}:{n}:{n}.{n}Z")
[2.014 8 12 23 10 58 931]
~zod/try=> =dat (scanf "2014-08-12T23:10:58.931Z" ;"{n}\-{n}\-{n}T{n}:{n}:{n}.{n}Z")
~zod/try=> `@da`(year `date`dat(- [%& -.dat], |6 ~[(div (mul |6.dat (bex 16)) 1.000)]))
~2014.8.12..23.10.58..ee56
```