on 6d45ede help sign in
175 lines 3.1 kB history raw
1---
2navhome: /docs
3---
6# 4g: parsing (outside caller)
7### `++rash`
9Parse or crash
11Parse a cord with a given `++rule` and crash if the `++cord` isn't entirely
12parsed.
14Accepts
15-------
17`naf` is an atom.
19`sab` is a `++rule`.
21Produces
22--------
24The value of the parse result, or crash.
26Source
27------
29 ++ rash |*({naf/@ sab/rule} (scan (trip naf) sab)) ::
32Examples
33--------
35 > (rash 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
36 "I was the world in which I walked, and what I saw"
37 > (rash 'abc' (just 'a'))
38 ! {1 2}
39 ! 'syntax-error'
40 ! exit
41 > (rash 'abc' (jest 'abc'))
42 'abc'
43 `> (rash 'abc' (jest 'ab'))
44 ! {1 3}
45 ! 'syntax-error'
46 ! exit
50***
51### `++rush`
53Parse or null
55Parse a given with a given rule and produce null if the cord isn't
56entirely parsed.
58Accepts
59-------
61`naf` is an atom.
63`sab` is a rule.
65Produces
66--------
68The value of the parse result, or null.
70Source
71------
73 ++ rush |*({naf/@ sab/rule} (rust (trip naf) sab))
76Examples
77--------
79 > (rush 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
80 [~ "I was the world in which I walked, and what I saw"]
81 > (rush 'abc' (just 'a'))
82 ~
83 > (rush 'abc' (jest 'abc'))
84 [~ 'abc']
85 > (rush 'abc' (jest 'ac'))
86 ~
87 > (rush 'abc' (jest 'ab'))
88 ~
92***
93### `++rust`
95Parse tape or null
97Parse a `++tape` with a given `++rule` and produce null if the `++tape` isn't
98entirely parsed.
100Accepts
101-------
103`los` is a `++tape`.
105`sab` is a `++rule`.
107Produces
108--------
110A `(unit ,@t)`
112Source
113------
115 ++ rust |* {los/tape sab/rule}
116 =+ vex=((full sab) [[1 1] los])
117 ?~(q.vex ~ [~ u=p.u.q.vex])
120Examples
121--------
123 > (rust "I was the world in which I walked, and what I saw" (star (shim 0 200)))
124 [~ "I was the world in which I walked, and what I saw"]
125 > (rust "Or heard or felt came not but from myself;" (star (shim 0 200)))
126 [~ "Or heard or felt came not but from myself;"]
127 > (rust "And there I found myself more truly and more strange." (jest 'And there I'))
128 ~
132***
133### `++scan`
135Parse tape or crash
137Parse a `++tape` with a given `++rule` and crash if the `++tape` isn't entirely
138parsed.
140Accepts
141-------
143`los` is a tape.
145`sab` is a rule.
147Produces
148--------
150Either a `++tape` or a crash.
152Source
153------
155 ++ scan |* {los/tape sab/rule}
156 =+ vex=((full sab) [[1 1] los])
157 ?~ q.vex
158 ~_ (show [%m '{%d %d}'] p.p.vex q.p.vex ~)
159 ~|('syntax-error' !!)
160 p.u.q.vex
162Examples
163--------
165 > (scan "I was the world in which I walked, and what I saw" (star (shim 0 200)))
166 "I was the world in which I walked, and what I saw"
167 > (scan "Or heard or felt came not but from myself;" (star (shim 0 200)))
168 "Or heard or felt came not but from myself;"
169 > (scan "And there I found myself more truly and more strange." (jest 'And there I'))
170 ! {1 12}
171 ! 'syntax-error'
172 ! exit
175***