on b93c19b help sign in
178 lines 3.2 kB history raw
1+++
2title = "4g: Parsing (Outside Caller)"
3weight = 34
4template = "doc.html"
5+++
6### `++rash`
8Parse or crash
10Parse a cord with a given `++rule` and crash if the `++cord` isn't entirely
11parsed.
13#### Accepts
15`naf` is an atom.
17`sab` is a `++rule`.
19#### Produces
21The value of the parse result, or crash.
23#### Source
25```
26 ++ rash |*({naf/@ sab/rule} (scan (trip naf) sab)) ::
27```
29#### Examples
31```
32 > (rash 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
33 "I was the world in which I walked, and what I saw"
35 > (rash 'abc' (just 'a'))
36 ! {1 2}
37 ! 'syntax-error'
38 ! exit
40 > (rash 'abc' (jest 'abc'))
41 'abc'
43 > (rash 'abc' (jest 'ab'))
44 ! {1 3}
45 ! 'syntax-error'
46 ! exit
47```
50---
51### `++rush`
53Parse or null
55Parse an atom with a given rule and produce null if the cord isn't
56entirely parsed.
58#### Accepts
60`naf` is an atom.
62`sab` is a rule.
64#### Produces
66The value of the parse result, or null.
68#### Source
70```
71 ++ rush |*({naf/@ sab/rule} (rust (trip naf) sab))
72```
74#### Examples
76```
77 > (rush 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
78 [~ "I was the world in which I walked, and what I saw"]
80 > (rush 'abc' (just 'a'))
81 ~
83 > (rush 'abc' (jest 'abc'))
84 [~ 'abc']
86 > (rush 'abc' (jest 'ac'))
87 ~
89 > (rush 'abc' (jest 'ab'))
90 ~
91```
94---
95### `++rust`
97Parse tape or null
99Parse a `++tape` with a given `++rule` and produce null if the `++tape` isn't
100entirely parsed.
102#### Accepts
104`los` is a `++tape`.
106`sab` is a `++rule`.
108#### Produces
110A `(unit ,@t)`
112#### Source
114```
115 ++ rust |* {los/tape sab/rule}
116 =+ vex=((full sab) [[1 1] los])
117 ?~(q.vex ~ [~ u=p.u.q.vex])
118```
120#### Examples
122```
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"]
126 > (rust "Or heard or felt came not but from myself;" (star (shim 0 200)))
127 [~ "Or heard or felt came not but from myself;"]
129 > (rust "And there I found myself more truly and more strange." (jest 'And there I'))
130 ~
131```
134---
135### `++scan`
137Parse tape or crash
139Parse a `++tape` with a given `++rule` and crash if the `++tape` isn't entirely
140parsed.
142#### Accepts
144`los` is a tape.
146`sab` is a rule.
148#### Produces
150Either a `++tape` or a crash.
152#### Source
154```
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
161```
163#### Examples
165```
166 > (scan "I was the world in which I walked, and what I saw" (star (shim 0 200)))
167 "I was the world in which I walked, and what I saw"
169 > (scan "Or heard or felt came not but from myself;" (star (shim 0 200)))
170 "Or heard or felt came not but from myself;"
172 > (scan "And there I found myself more truly and more strange." (jest 'And there I'))
173 ! {1 12}
174 ! 'syntax-error'
175 ! exit
176```
178---