on d452c09 help sign in
170 lines 3.1 kB history raw
1# 4g: parsing (outside caller)
2### `++rash`
4Parse or crash
6Parse a cord with a given `++rule` and crash if the `++cord` isn't entirely
7parsed.
9Accepts
10-------
12`naf` is an atom.
14`sab` is a `++rule`.
16Produces
17--------
19The value of the parse result, or crash.
21Source
22------
24 ++ rash |*({naf/@ sab/rule} (scan (trip naf) sab)) ::
27Examples
28--------
30 > (rash 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
31 "I was the world in which I walked, and what I saw"
32 > (rash 'abc' (just 'a'))
33 ! {1 2}
34 ! 'syntax-error'
35 ! exit
36 > (rash 'abc' (jest 'abc'))
37 'abc'
38 `> (rash 'abc' (jest 'ab'))
39 ! {1 3}
40 ! 'syntax-error'
41 ! exit
45***
46### `++rush`
48Parse or null
50Parse a given with a given rule and produce null if the cord isn't
51entirely parsed.
53Accepts
54-------
56`naf` is an atom.
58`sab` is a rule.
60Produces
61--------
63The value of the parse result, or null.
65Source
66------
68 ++ rush |*({naf/@ sab/rule} (rust (trip naf) sab))
71Examples
72--------
74 > (rush 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
75 [~ "I was the world in which I walked, and what I saw"]
76 > (rush 'abc' (just 'a'))
77 ~
78 > (rush 'abc' (jest 'abc'))
79 [~ 'abc']
80 > (rush 'abc' (jest 'ac'))
81 ~
82 > (rush 'abc' (jest 'ab'))
83 ~
87***
88### `++rust`
90Parse tape or null
92Parse a `++tape` with a given `++rule` and produce null if the `++tape` isn't
93entirely parsed.
95Accepts
96-------
98`los` is a `++tape`.
100`sab` is a `++rule`.
102Produces
103--------
105A `(unit ,@t)`
107Source
108------
110 ++ rust |* {los/tape sab/rule}
111 =+ vex=((full sab) [[1 1] los])
112 ?~(q.vex ~ [~ u=p.u.q.vex])
115Examples
116--------
118 > (rust "I was the world in which I walked, and what I saw" (star (shim 0 200)))
119 [~ "I was the world in which I walked, and what I saw"]
120 > (rust "Or heard or felt came not but from myself;" (star (shim 0 200)))
121 [~ "Or heard or felt came not but from myself;"]
122 > (rust "And there I found myself more truly and more strange." (jest 'And there I'))
123 ~
127***
128### `++scan`
130Parse tape or crash
132Parse a `++tape` with a given `++rule` and crash if the `++tape` isn't entirely
133parsed.
135Accepts
136-------
138`los` is a tape.
140`sab` is a rule.
142Produces
143--------
145Either a `++tape` or a crash.
147Source
148------
150 ++ scan |* {los/tape sab/rule}
151 =+ vex=((full sab) [[1 1] los])
152 ?~ q.vex
153 ~_ (show [%m '{%d %d}'] p.p.vex q.p.vex ~)
154 ~|('syntax-error' !!)
155 p.u.q.vex
157Examples
158--------
160 > (scan "I was the world in which I walked, and what I saw" (star (shim 0 200)))
161 "I was the world in which I walked, and what I saw"
162 > (scan "Or heard or felt came not but from myself;" (star (shim 0 200)))
163 "Or heard or felt came not but from myself;"
164 > (scan "And there I found myself more truly and more strange." (jest 'And there I'))
165 ! {1 12}
166 ! 'syntax-error'
167 ! exit
170***