on 492ae2f help sign in
440 lines 7.7 kB history raw
1### `++poxa`
3Parse XML
5Parses an XML node from a [`++cord`](), producing a [`++unit`]() [`++manx`]().
7Accepts
8-------
10`a` is a [`++cord`]().
12Produces
13--------
15A `(unit manx)`.
17Source
18------
20 ++ poxa :: xml parser
21 =< |=(a=cord (rush a apex))
22 |%
24Examples
25--------
27 ~zod/try=> (poxa '<div />')
28 [~ [g=[n=%div a=~] c=~]]
29 ~zod/try=> (poxa '<html><head/> <body/></html>')
30 [~ [g=[n=%html a=~] c=~[[g=[n=%head a=~] c=~] [g=[n=%body a=~] c=~]]]]
31 ~zod/try=> (poxa '<script src="/gep/hart.js"/>')
32 [~ [g=[n=%script a=~[[n=%src v="/gep/hart.js"]]] c=~]]
33 ~zod/try=> (poxa '<<<<')
34 ~
36### `++apex`
38Top level parser
40Parses a node of XML, type [`++manx`]().
42Accepts
43-------
45A [`++nail`]().
47Produces
48--------
50A `++manx`.
52Source
53------
55 ++ apex
56 =+ spa=;~(pose comt whit)
57 %+ knee *manx |. ~+
58 %+ ifix [(star spa) (star spa)]
59 ;~ pose
60 %+ sear |=([a=marx b=marl c=mane] ?.(=(c n.a) ~ (some [a b])))
61 ;~(plug head (more (star comt) ;~(pose apex chrd)) tail)
62 empt
63 ==
64 ::
66Examples
67--------
69 ~zod/try=> (rash '<div />' apex:poxa)
70 [g=[n=%div a=~] c=~]
71 ~zod/try=> (rash '<html><head/> <body/></html>' apex:poxa)
72 [g=[n=%html a=~] c=~[[g=[n=%head a=~] c=~] [g=[n=%body a=~] c=~]]]
73 ~zod/try=> (rash '<script src="/gep/hart.js"/>' apex:poxa)
74 [g=[n=%script a=~[[n=%src v="/gep/hart.js"]]] c=~]
75 ~zod/try=> (rash '<<<<' apex:poxa)
76 ! {1 2}
77 ! exit
79### `++attr`
81Parse XML attributes
83Parses the list of attributes inside the opening XML tag, which is zero
84or more space-prefixed name to string values.
86Accepts
87-------
89A [`++nail`]().
91Produces
92--------
94A [`++mart`]().
96Source
97------
99 ++ attr :: attributes
100 %+ knee *mart |. ~+
101 %- star
102 ;~ plug
103 ;~(sfix name tis)
104 ;~ pose
105 (ifix [doq doq] (star ;~(less doq escp)))
106 (ifix [soq soq] (star ;~(less soq escp)))
107 ==
108 ==
109 ::
111Examples
112--------
114 ~zod/try=> (rash '' attr:poxa)
115 ~
116 ~zod/try=> (rash 'sam=""' attr:poxa)
117 ! {1 1}
118 ! exit
119 ~zod/try=> (rash ' sam=""' attr:poxa)
120 ~[[n=%sam v=""]]
121 ~zod/try=> (rash ' sam="hek"' attr:poxa)
122 ~[[n=%sam v="hek"]]
123 ~zod/try=> (rash ' sam="hek" res="actor"' attr:poxa)
124 ~[[n=%sam v="hek"] [n=%res v="actor"]]
125 ~zod/try=> (rash ' sam=\'hek\' res="actor"' attr:poxa)
126 ~[[n=%sam v="hek"] [n=%res v="actor"]]
127 ~zod/try=> (rash ' sam=\'hek" res="actor"' attr:poxa)
128 ! {1 23}
129 ! exit
131### `++chrd`
133Parse character data
135Parsing rule. Parses XML character data.
137Accepts
138-------
140A [`++nail`]().
142Produces
143--------
145A [`++mars`]().
147Source
148------
150 ++ chrd :: character data
151 %+ cook |=(a=tape ^-(mars :/(a)))
152 (plus ;~(less soq doq ;~(pose (just `@`10) escp)))
153 ::
155Examples
156--------
158 ~zod/try=> (rash 'asa' chrd:poxa)
159 [g=[n=%$ a=~[[n=%$ v="asa"]]] c=~]
160 ~zod/try=> (rash 'asa &gt; are' chrd:poxa)
161 [g=[n=%$ a=~[[n=%$ v="asa > are"]]] c=~]
162 ~zod/try=> (rash 'asa > are' chrd:poxa)
163 ! {1 6}
164 ! exit
166### `++comt`
168Parses comments
170Parsing rule. Parses XML comment blocks.
172Accepts
173-------
175A [`++nail`]().
177Produces
178--------
180A [`++like`]().
182Source
183------
185 ++ comt :: comments
186 =- (ifix [(jest '<!--') (jest '-->')] (star -))
187 ;~ pose
188 ;~(less hep prn)
189 whit
190 ;~(less (jest '-->') hep)
191 ==
192 ::
193A [`++unit`]() of.
195Examples
196--------
198 ~zod/try=> (rash '<!-- bye -->' comt:poxa)
199 " bye "
200 ~zod/try=> (rash '<!-- bye ><<<>< - - -->' comt:poxa)
201 " bye ><<<>< - - "
202 ~zod/try=> (rash '<!-- invalid -->-->' comt:poxa)
203 ! {1 18}
204 ! exit
206### `++escp`
208Parse (possibly) escaped char
210Parsing rule. Parses a nonspecial or escaped character. Result type
211[`++char`]()
213Accepts
214-------
216A [`++nail`]().
218Produces
219--------
221The [`++edge`]() of a [`++cord`]().
223Source
224------
226 ++ escp
227 ;~ pose
228 ;~(less gal gar pam prn)
229 (cold '>' (jest '&gt;'))
230 (cold '<' (jest '&lt;'))
231 (cold '&' (jest '&amp;'))
232 (cold '"' (jest '&quot;'))
233 (cold '\'' (jest '&apos;'))
234 ==
236Examples
237--------
239 ~zod/try=> (rash 'a' escp:poxa)
240 'a'
241 ~zod/try=> (rash 'ab' escp:poxa)
242 ! {1 2}
243 ! exit
244 ~zod/try=> (rash '.' escp:poxa)
245 '.'
246 ~zod/try=> (rash '!' escp:poxa)
247 '!'
248 ~zod/try=> (rash '>' escp:poxa)
249 ! {1 2}
250 ! exit
251 ~zod/try=> (rash '&gt;' escp:poxa)
252 '>'
253 ~zod/try=> (rash '&quot;' escp:poxa)
254 '"'
256### `++empt`
258Parse self-closing tag
260Parsing rule. Parses self-closing XML tags that end in `/>`.
262Accepts
263-------
265A [`++nail`]().
267Produces
268--------
271A `(like tape)`.
273Source
274------
276 ++ empt :: self-closing tag
277 %+ ifix [gal (jest '/>')]
278 ;~(plug ;~(plug name attr) (cold ~ (star whit)))
279 ::
281Examples
282--------
284 ~zod/try=> (rash '<div/>' empt:poxa)
285 [[%div ~] ~]
286 ~zod/try=> (rash '<pre color="#eeffee" />' empt:poxa)
287 [[%pre ~[[n=%color v="#eeffee"]]] ~]
288 ~zod/try=> (rash '<pre color="#eeffee"></pre>' empt:poxa)
289 ! {1 21}
290 ! exit
292### `++head`
294Parse opening tag
296Parsing rule. Parses the opening tag of an XML node. Result type
297[`++marx`]()
299Accepts
300-------
302A [`++nail`]().
304Produces
305--------
307A `(like marx)`.
309Source
310------
312 ++ head :: opening tag
313 (ifix [gal gar] ;~(plug name attr))
314 ::
316Examples
317--------
319 ~zod/try=> (rash '<a>' head:poxa)
320 [n=%a a=~]
321 ~zod/try=> (rash '<div mal="tok">' head:poxa)
322 [n=%div a=~[[n=%mal v="tok"]]]
323 ~zod/try=> (rash '<div mal="tok" />' head:poxa)
324 ! {1 16}
325 ! exit
327### `++name`
329Parse tag name
331Parsing rule. Parses the name of an XML tag.
333Accepts
334-------
336A [`++nail`]().
338Produces
339--------
341An [`++edge`]() of a [`++mane`]().
343Source
344------
346 ++ name :: tag name
347 %+ knee *mane |. ~+
348 =+ ^= chx
349 %+ cook crip
350 ;~ plug
351 ;~(pose cab alf)
352 (star ;~(pose cab dot alp))
353 ==
354 ;~(pose ;~(plug ;~(sfix chx col) chx) chx)
355 ::
357Examples
358--------
360 ~zod/try=> (scan "ham" name:poxa)
361 %ham
362 ~zod/try=> (scan "ham:tor" name:poxa)
363 [%ham %tor]
364 ~zod/try=> (scan "ham-tor" name:poxa)
365 %ham-tor
366 ~zod/try=> (scan "ham tor" name:poxa)
367 ! {1 4}
368 ! exit
370### `++tail`
372Parse closing tag
374Parsing rule. Parses an XML closing tag.
376Accepts
377-------
379A [`++nail`]().
381Produces
382--------
384A `(like tail)`.
386Source
387------
389 ++ tail (ifix [(jest '</') gar] name) :: closing tag
391Examples
392--------
394 ~zod/try=> (scan "</div>" tail:poxa)
395 %div
396 ~zod/try=> (scan "</a>" tail:poxa)
397 %a
398 ~zod/try=> (scan "</>" tail:poxa)
399 ! {1 3}
400 ! exit
402### `++whit`
404Parse whitespace, etc.
406Parsing rule. Parses newlines, tabs, and spaces.
408Accepts
409-------
411A [`++nail`]().
413Produces
414--------
416A `(like char)`.
418Source
419------
421 ++ whit (mask ~[' ' `@`0x9 `@`0xa]) :: whitespace
422 ::
424Examples
425--------
427 ~zod/try=> `@`(scan " " whit:poxa)
428 32
429 ~zod/try=> `@`(scan " " whit:poxa)
430 ! {1 2}
431 ! exit
432 ~zod/try=> `@`(scan "\0a" whit:poxa)
433 10
434 ~zod/try=> `@`(scan "\09" whit:poxa)
435 9
436 ~zod/try=> `@`(scan "\08" whit:poxa)
437 ! {1 1}
438 ! exit