5JSON parser core: parses a [`++cord`]() `a` to the hoon structure for JSON,
22 ++ poja :: JSON parser core
23 =< |=(a=cord (rush a apex))
29 ~zod/try=> (poja '[1,2,3]')
30 [~ [%a p=~[[%n p=~.1] [%n p=~.2] [%n p=~.3]]]]
31 ~zod/try=> (poja 'null')
33 ~zod/try=> (poja 'invalid{json')
40Top level parsing [`++rule`](). Parses either a single JSON object, or an array
41of JSON objects to a [`++json`](). See also: [`++abox`](), [`++obox`]().
56 ++ apex ;~(pose abox obox) :: JSON object
61 ~zod/try=> (rash '[1,2]' apex:poja)
62 [%a p=~[[%n p=~.1] [%n p=~.2]]]
63 ~zod/try=> (rash '{"sam": "kot"}' apex:poja)
64 [%o p={[p=~.sam q=[%s p=~.kot]]}]
65 ~zod/try=> (rash 'null' apex:poja)
73Parsing [`++rule`](). Parses JSON values to [`++json`]().
92 (cold ~ (jest 'null'))
95 (cook |=(s=tape [%n p=(rap 3 s)]) numb)
104 ~zod/try=> (rash '[1,2]' valu:poja)
105 [%a p=~[[%n p=~.1] [%n p=~.2]]]
106 ~zod/try=> (rash '{"sam": "kot"}' valu:poja)
107 [%o p={[p='sam' q=[%s p=~.kot]]}]
108 ~zod/try=> (rash 'null' valu:poja)
110 ~zod/try=> (rash '20' valu:poja)
112 ~zod/try=> (rash '"str"' valu:poja)
114 ~zod/try=> (rash 'true' valu:poja)
121Parsing rule. Parses a JSON array with values enclosed within `[]` and
137 ++ abox (stag %a (ifix [sel (ws ser)] (more (ws com) valu)))
142 ~zod/try=> (rash '[1, 2,4]' abox:poja)
143 [[%n p=~.1] ~[[%n p=~.2] [%n p=~.4]]]
152Parsing rule. Parses a [`++json`]() from a JSON key-value pair of a
153string and value delimited by `:`.
168 ++ pair ;~(plug ;~(sfix (ws stri) (ws col)) valu)
173 ~zod/try=> (rash '"ham": 2' pair:poja)
178Parse array of objects
180Parsing rule. Parses a [`++json`]() from an array of JSON object
181key-value pairs that are enclosed within `{}` and separated by `,`.
191A `(like ,[%o p=(map ,@t json)])`
196 ++ obje (ifix [(ws kel) (ws ker)] (more (ws com) pair))
201 ~zod/try=> (rash '{"ham": 2, "lam":true}' obje:poja)
202 [['ham' [%n p=~.2]] ~[['lam' [%b p=%.y]]]]
208Parsing rule. Parses an array of JSON objects to an object of [`++json`](). See also: [`++json`]().
218A `(like ,[%o p=(map ,@t json)])`
223 ++ obox (stag %o (cook mo obje))
228 ~zod/try=> (rash '{"ham": 2, "lam":true}' obox:poja)
229 [%o {[p='lam' q=[%b p=%.y]] [p='ham' q=[%n p=~.2]]}]
238Parsing rule. Parses a string of either `true` or `false` to a
256 ++ bool ;~(pose (cold & (jest 'true')) (cold | (jest 'false')))
261 ~zod/try=> (rash 'true' bool:poja)
263 ~zod/try=> (rash 'false' bool:poja)
265 ~zod/try=> (rash 'null' bool:poja)
276Parsing rule. Parse a string to a [`++cord`](). A JSON string is a list
277of characters enclosed in double quotes along with escaping `\`s, to a
278[`++cord`](). See also [`++jcha`]().
288A `(like ,[%s p=@t])`.
294 (cook crip (ifix [doq doq] (star jcha)))
299 ~zod/try=> (rash '"ham"' stri:poja)
301 ~zod/try=> (rash '"h\\nam"' stri:poja)
304 ~zod/try=> (rash '"This be \\"quoted\\""' stri:poja)
309Parse char from string
311Parsing rule. Parses either a literal or escaped character from a JSON
312string to a [`++cord`]().
328 ++ jcha ;~(pose ;~(less doq bas prn) esca) :: character in string
333 ~zod/try=> (rash 'a' jcha:poja)
335 ~zod/try=> (rash '!' jcha:poja)
337 ~zod/try=> (rash '\\"' jcha:poja)
339 ~zod/try=> (rash '\\u00a4' jcha:poja)
341 ~zod/try=> (rash '\\n' jcha:poja)
349Parsing rule. Parses a backslash-escaped special character, low ASCII,
350or UTF16 codepoint, to a [`++cord`]().
366 ++ esca :: Escaped character
370 (sear ~(get by `(map ,@t ,@)`(mo b/8 t/9 n/10 f/12 r/13 ~)) low)
371 ;~(pfix (just 'u') (cook tuft qix:ab)) :: 4-digit hex to UTF-8
377 ~zod/try=> (rash 'b' esca:poja)
380 ~zod/try=> (rash '\n' esca:poja)
381 ~ <syntax error at [1 9]>
382 ~zod/try=> (rash '\\n' esca:poja)
385 ~zod/try=> `@`(rash '\\r' esca:poja)
387 ~zod/try=> (rash '\\u00c4' esca:poja)
389 ~zod/try=> (rash '\\u00df' esca:poja)
395A JSON numbers are stored as cords internally in lieu of full float
396support, so ++numb and subarms are really more *validators* than parsers
403Parsing rule. Parses decimal numbers with an optional `-`, fractional
404part, or exponent part, to a [`++tape`]().
414An [`++edge`]() of a [`++tape`]().
424 ;~(plug (shim '1' '9') digs)
433 ~zod/try=> (rash '0' numb:poja)
435 ~zod/try=> (rash '1' numb:poja)
437 ~zod/try=> `tape`(rash '1' numb:poja)
439 ~zod/try=> `tape`(rash '12.6' numb:poja)
441 ~zod/try=> `tape`(rash '-2e20' numb:poja)
443 ~zod/try=> `tape`(rash '00e20' numb:poja)
451Parsing rule. Parses digits `0` through `9` to a [`++tape`]().
461The [`++edge`]() of a `++tape`.
466 ++ digs (star (shim '0' '9'))
471 ~zod/try=> (rash '' digs:poja)
473 ~zod/try=> (rash '25' digs:poja)
475 ~zod/try=> (rash '016' digs:poja)
477 ~zod/try=> (rash '7' digs:poja)
484Parsing rule. Parses an exponent to a [`++tape`]() .An exponent is an
485`e` or 'E', followed by an optional `+` or `-`, and then by digits.
495The [`++edge`]() of a `++tape`.
500 ++ expo :: Exponent part
503 (mayb (piec (mask "+-")))
510 ~zod/try=> `tape`(rash 'e7' expo:poja)
512 ~zod/try=> `tape`(rash 'E17' expo:poja)
514 ~zod/try=> `tape`(rash 'E-4' expo:poja)
521Parsing rule. Parses a dot followed by digits to a [`++cord`]().
531The [`++edge`]() of a `++tape`.
536 ++ frac ;~(plug dot digs) :: Fractional part
541 ~zod/try=> (rash '.25' frac:poja)
543 ~zod/try=> (rash '.016' frac:poja)
545 ~zod/try=> (rash '.7' frac:poja)
555Parsing rule. Parses a whitespace to a [`++tape`]().
570 ++ spac (star (mask [`@`9 `@`10 `@`13 ' ' ~]))
575 ~zod/try=> (scan "" spac:poja)
577 ~zod/try=> (scan " " spac:poja)
579 ~zod/try=> `*`(scan `tape`~[' ' ' ' ' ' `@`9 ' ' ' ' `@`13] spac:poja)
580 [32 32 32 9 32 32 13 0]
581 ~zod/try=> (scan " m " spac:poja)
587Allow prefix whitespace
589Parser modifier. Produces a rule that allows for a whitespace before
595`sef` is a [`++rule`]().
605 ++ ws |*(sef=_rule ;~(pfix spac sef))
610 ~zod/try=> (rash ' 4' digs:poja)
613 ~zod/try=> (rash ' 4' (ws digs):poja)
628Parser modifier. Need to document, an example showing failure.
643 ++ mayb |*(bus=_rule ;~(pose bus (easy "")))
648 ~zod/try=> (abox:poja 1^1 "not-an-array")
650 ~zod/try=> ((mayb abox):poja 1^1 "not-an-array")
651 [p=[p=1 q=1] q=[~ [p="" q=[p=[p=1 q=1] q="not-an-array"]]]]
657Concatenates two tapes, `a` and `b`, producing a [`++tape`]().
662`a` is a [`++tape`]().
664`b` is a [`++tape`]().
669The [`++edge`]() of a `++tape`.
674 ++ twel |=([a=tape b=tape] (weld a b))
679 ~zod/try=> (twel "sam" "hok"):poja
680 ~[~~s ~~a ~~m ~~h ~~o ~~k]
681 ~zod/try=> (twel "kre" ""):poja
688Parser modifer. Parses an atom with `bus` and then wraps it in a
694`bus` is a [`++rule`]().
706 (cook |=(a=@ [a ~]) bus)
712 d~zod/try=> (scan "4" (piec:poja dem:ag))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list