on 473f005 help sign in
179 lines 3.2 kB history raw
1+++
2title = "4g: Parsing (Outside Caller)"
3weight = 34
4template = "doc.html"
5+++
7### `++rash`
9Parse or crash
11Parse a cord with a given `++rule` and crash if the `++cord` isn't entirely
12parsed.
14#### Accepts
16`naf` is an atom.
18`sab` is a `++rule`.
20#### Produces
22The value of the parse result, or crash.
24#### Source
26```hoon
27 ++ rash |*({naf/@ sab/rule} (scan (trip naf) sab)) ::
28```
30#### Examples
32```
33 > (rash 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
34 "I was the world in which I walked, and what I saw"
36 > (rash 'abc' (just 'a'))
37 ! {1 2}
38 ! 'syntax-error'
39 ! exit
41 > (rash 'abc' (jest 'abc'))
42 'abc'
44 > (rash 'abc' (jest 'ab'))
45 ! {1 3}
46 ! 'syntax-error'
47 ! exit
48```
51---
52### `++rush`
54Parse or null
56Parse an atom with a given rule and produce null if the cord isn't
57entirely parsed.
59#### Accepts
61`naf` is an atom.
63`sab` is a rule.
65#### Produces
67The value of the parse result, or null.
69#### Source
71```hoon
72 ++ rush |*({naf/@ sab/rule} (rust (trip naf) sab))
73```
75#### Examples
77```
78 > (rush 'I was the world in which I walked, and what I saw' (star (shim 0 200)))
79 [~ "I was the world in which I walked, and what I saw"]
81 > (rush 'abc' (just 'a'))
82 ~
84 > (rush 'abc' (jest 'abc'))
85 [~ 'abc']
87 > (rush 'abc' (jest 'ac'))
88 ~
90 > (rush 'abc' (jest 'ab'))
91 ~
92```
95---
96### `++rust`
98Parse tape or null
100Parse a `++tape` with a given `++rule` and produce null if the `++tape` isn't
101entirely parsed.
103#### Accepts
105`los` is a `++tape`.
107`sab` is a `++rule`.
109#### Produces
111A `(unit ,@t)`
113#### Source
115```hoon
116 ++ rust |* {los/tape sab/rule}
117 =+ vex=((full sab) [[1 1] los])
118 ?~(q.vex ~ [~ u=p.u.q.vex])
119```
121#### Examples
123```
124 > (rust "I was the world in which I walked, and what I saw" (star (shim 0 200)))
125 [~ "I was the world in which I walked, and what I saw"]
127 > (rust "Or heard or felt came not but from myself;" (star (shim 0 200)))
128 [~ "Or heard or felt came not but from myself;"]
130 > (rust "And there I found myself more truly and more strange." (jest 'And there I'))
131 ~
132```
135---
136### `++scan`
138Parse tape or crash
140Parse a `++tape` with a given `++rule` and crash if the `++tape` isn't entirely
141parsed.
143#### Accepts
145`los` is a tape.
147`sab` is a rule.
149#### Produces
151Either a `++tape` or a crash.
153#### Source
155```hoon
156 ++ scan |* {los/tape sab/rule}
157 =+ vex=((full sab) [[1 1] los])
158 ?~ q.vex
159 ~_ (show [%m '{%d %d}'] p.p.vex q.p.vex ~)
160 ~|('syntax-error' !!)
161 p.u.q.vex
162```
164#### Examples
166```
167 > (scan "I was the world in which I walked, and what I saw" (star (shim 0 200)))
168 "I was the world in which I walked, and what I saw"
170 > (scan "Or heard or felt came not but from myself;" (star (shim 0 200)))
171 "Or heard or felt came not but from myself;"
173 > (scan "And there I found myself more truly and more strange." (jest 'And there I'))
174 ! {1 12}
175 ! 'syntax-error'
176 ! exit
177```
179---