5 ++ scanf :: formatted scan
6 |* [tape (pole ,_:/(*$&(_rule tape)))]
10Scan with `;"`-interpolated parsers.
12A- here there be monsters, monsters of my making. But the basic idea is
13you use `;"` (which currently is parsed by sail but shouldn't be) to mix
14literal text and [++rule]s, and apply this to text which is a
15correspending mixture of aforementioned literals and sections parsable
16by the relevant rules. ++parsf is the parser form that combines a
17tape-rule mix into one big ++rule, ++norm being a parsf internal that
18winnows the `;"` result into a list of discriminate literals and rules,
19and ++bill doing the actual composing: ++\$:parsf just adds a layer that
20collapses the result list to a tuple, such that (scanf "foo 1 2 bar"
21;"foo {dem} {dem} bar") parses [1 2] and not [1 2 \~].
23 ~zod/try=> `[p=@ud q=@ud]`(scanf "Score is 5 to 2" [;"Score is {n} to {n}"]:n=dim:ag)
26 ~zod/try=> =n ;~(pfix (star (just '0')) (cook |=(@ud +<) dim:ag))
27 ~zod/try=> (scanf "2014-08-12T23:10:58.931Z" ;"{n}\-{n}\-{n}T{n}:{n}:{n}.{n}Z")
28 [2.014 8 12 23 10 58 931]
29 ~zod/try=> =dat (scanf "2014-08-12T23:10:58.931Z" ;"{n}\-{n}\-{n}T{n}:{n}:{n}.{n}Z")
30 ~zod/try=> `@da`(year `date`dat(- [%& -.dat], |6 ~[(div (mul |6.dat (bex 16)) 1.000)]))
31 ~2014.8.12..23.10.58..ee56
35 ++ parsf :: make parser from:
36 |^ |* a=(pole ,_:/(*$&(_rule tape))) :: ;"chars{rule}chars"
37 %- cook :_ (bill (norm a))
44`parsf` generates a `_rule` from a tape with rules embedded in it,
45literal sections being matched verbatim. The parsed type is a tuple of
46the embedded rules' results.
48Two intermediate arms are used:
52 :: .= (norm [;"{n}, {n}"]:n=dim:ag) ~[[& dim] [| ", "] [& dim]]:ag
54 |* (pole ,_:/(*$&(_rule tape)))
56 => .(+< [i=+<- t=+<+])
62 ?@ &2.rul [%| p=;;(tape rul)]
66`norm` converts a `;"` pole of `[[%~. [%~. ?(tape _rule)] ~] ~]` into a
67more convenient list of discriminated tapes and rules.
71 :: .= (bill ~[[& dim] [| ", "] [& dim]]:ag)
72 :: ;~(plug dim ;~(pfix com ace ;~(plug dim (easy)))):ag
74 |* (list (each ,_rule tape))
76 ?: ?=(| -.i) ;~(pfix (jest (crip p.i)) $(+< t))
77 %+ cook |*([* *] [i t]=+<)
82`bill` builds a parser out of rules and tapes, ignoring the literal
83sections and producing a list of the rules' results.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list