on 4fdc19d help sign in
323 lines 4.4 kB history raw
1+++
2title = "5d: Parser"
3weight = 46
4template = "doc.html"
5+++
7## `++vang`
9Set `++vast` parameters
11#### Source
13```hoon
14++ vang :: set ++vast params
15 |= [bug=? wer=path] :: bug: debug mode
16 %*(. vast bug bug, wer wer) :: wer: where we are
17```
19---
21## `++vast`
23Main parsing core
25### Source
27This core is too large to include here, please refer to `hoon.hoon` for the
28source.
30---
32### `++vest`
34Parse hoon
36Parsing `rule`. Parse hoon of any form.
38#### Source
40```hoon
41++ vest
42 ~/ %vest
43 |= tub=nail
44 ^- (like hoon)
45 %. tub
46 %- full
47 (ifix [gay gay] tall:vast)
48```
50#### Examples
52```
53> (rash '(add 1 1)' vest)
54[%cncl p=[%wing p=~[%add]] q=~[[%sand p=%ud q=1] [%sand p=%ud q=1]]]
56> (rash '%+ add\0a 1\0a1' vest)
57[%cnls p=[%wing p=~[%add]] q=[%sand p=%ud q=1] r=[%sand p=%ud q=1]]
58```
60---
62### `++vice`
64Parse wide-form hoon
66Parse `txt`, a `knot` containing wide-form hoon, to `hoon`.
68#### Accepts
70`txt` is a `@ta`.
72#### Produces
74`hoon`.
76#### Source
78```hoon
79++ vice
80 |= txt=@ta
81 ^- hoon
82 (rash txt wide:vast)
83```
85#### Examples
87```
88> (vice '(add 1 1)')
89[%cncl p=[%wing p=~[%add]] q=~[[%sand p=%ud q=1] [%sand p=%ud q=1]]]
91> (vice '%+ add\0a 1\0a1')
92{1 3}
93syntax error
94```
96---
98## `++make`
100Compile cord to nock
102Compile `txt`, an `atom` containing hoon source code as little-endian UTF-8
103text, to `nock`.
105#### Accepts
107`txt` is a `@`.
109#### Produces
111`nock`.
113#### Source
115```hoon
116++ make
117 |= txt=@
118 q:(~(mint ut %noun) %noun (ream txt))
119```
121#### Examples
123```
124> (make '[. . .]')
125[p=[%0 p=1] q=[p=[%0 p=1] q=[%0 p=1]]]
127> .*(42 (make '[. . .]'))
128[42 42 42]
129```
131---
133## `++rain`
135Parse with % path
137Parse `txt`, an `atom` containing hoon source code as little-endian UTF-8 text,
138to `hoon`. Any `%` path short-hands are replaced with the path given in `bon`.
139If parsing fails, `bon` is also printed to the terminal.
141#### Accepts
143`bon` is a `path`.
145`txt` is an atom.
147#### Produces
149`hoon`.
151#### Source
153```hoon
154++ rain
155 |= [bon=path txt=@]
156 ^- hoon
157 =+ vaz=vast
158 ~| bon
159 (scan (trip txt) (full (ifix [gay gay] tall:vaz(wer bon))))
160```
162#### Examples
164```
165> (rain /a/b/c '%')
166[%clsg p=~[[%sand p=%ta q=97] [%sand p=%ta q=98] [%sand p=%ta q=99]]]
168> !<(path (slap !>(~) (rain /a/b/c '%')))
169/a/b/c
171> (rain / '(add 1 1)')
172[%cncl p=[%wing p=~[%add]] q=~[[%sand p=%ud q=1] [%sand p=%ud q=1]]]
174> !<(@ud (slap !>(add=add) (rain / '(add 1 1)')))
176```
178---
180## `++ream`
182Parse cord to hoon
184Parse `txt`, an `atom` containing hoon source code as little-endian UTF-8 text,
185to `hoon`.
187#### Accepts
189`txt` is an atom.
191#### Produces
193`hoon`.
195#### Source
197```hoon
198++ ream
199 |= txt=@
200 ^- hoon
201 (rash txt vest)
202```
204#### Examples
206```
207> !<(tape (slap !>(~) (ream '"foobar"')))
208"foobar"
209```
211---
213## `++reck`
215Parse hoon file
217Parse `bon` to `hoon`. `bon` is a `path` to a .hoon file without the mark.
219#### Accepts
221`bon` is a `path`.
223#### Produces
225`hoon`.
227#### Source
229```hoon
230++ reck
231 |= bon=path
232 (rain bon .^(@t %cx (weld bon `path`[%hoon ~])))
233```
235#### Examples
237```
238> (reck %/gen/code)
239[ %clhp
240 p=[%rock p=%tas q=7.954.803]
241 q
242 [ %brts
243 p
244 [ %bccl
245 p
246 [ i
247 [ %bccl
248 p
249 [ i
250 [%bcts p=term=%now q=[%base p=[%atom p=~.da]]]
251 t
252......(truncated for brevity)..........
253```
255---
257## `++ride`
259End-to-end compiler
261Parse and compile cord `txt`, producing a pair of its `type` and compiled
262`nock`. The `typ` argument specifies the `type` of the subject.
264#### Accepts
266`typ` is a `type`
268`txt` is an atom.
270#### Produces
272A `(pair type nock)`.
274#### Source
276```hoon
277++ ride
278 |= [typ=type txt=@]
279 ^- (pair type nock)
280 ~> %slog.[0 leaf/"ride: parsing"]
281 =/ gen (ream txt)
282 ~> %slog.[0 leaf/"ride: compiling"]
283 ~< %slog.[0 leaf/"ride: compiled"]
284 (~(mint ut typ) %noun gen)
285```
287#### Examples
289```
290ride: parsing
291ride: compiling
292ride: compiled
293> (ride -:!>(.) '(add 2 2)')
294[ #t/@
295 q
296 [ %8
297 p=[%9 p=36 q=[%0 p=1.023]]
298 q
299 [ %9
300 p=2
301 q
302 [ %10
303 p
304 [ p=6
305 q
306 [ p=[%7 p=[%0 p=3] q=[%1 p=2]]
307 q=[%7 p=[%0 p=3] q=[%1 p=2]]
308 ]
309 ]
310 q=[%0 p=2]
311 ]
312 ]
313 ]
316ride: parsing
317ride: compiling
318> (ride %noun '(add 2 2)')
319-find.add
320dojo: hoon expression failed
321```
323---