code wiki / (root) / json.nx

json.nx

buildroot/runtime/json.nx

8516 B257 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind librarytopic json
docsdependenciesstructsconstsfunctions

about

json.nx -- pull-style JSON parser (Phase G12, RFC 8259). Research / reference: RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format Crockford 2002 — json.org, the original spec Design: pull-style / event-driven parser. The caller invokes json_next(p) in a loop; each call emits one event: JSON_NULL / JSON_BOOL / JSON_INT / JSON_STRING JSON_ARRAY_BEGIN / JSON_ARRAY_END JSON_OBJECT_BEGIN / JSON_OBJECT_END JSON_KEY (for object member names) JSON_END (end of input) JSON_ERROR (malformed input) Zero heap allocation per event. String values are returned as (start, len) slices into the original input buffer; the caller copies if they need persistence. Scope: RFC 8259 compliant for well-formed input. Skips whitespace per spec, supports \" \\ \/ \b \f \n \r \t escape sequences in strings. Number parsing handles integers; \uXXXX unicode escapes and fractional numbers deferred to a follow-up.

dependencies 1 imports · 1 importers

syscalls.nx json.nx _api_extract.nx

imports: syscalls.nx

imported by: _api_extract.nx

structs

40struct JsonParser {

consts

28const JSON_END: i64 = 0
29const JSON_NULL: i64 = 1
30const JSON_BOOL: i64 = 2
31const JSON_INT: i64 = 3
32const JSON_STRING: i64 = 4
33const JSON_ARRAY_BEGIN: i64 = 5
34const JSON_ARRAY_END: i64 = 6
35const JSON_OBJECT_BEGIN: i64 = 7
36const JSON_OBJECT_END: i64 = 8
37const JSON_KEY: i64 = 9
38const JSON_ERROR: i64 = 10

functions

53func json_new(src: *u8, len: i64) -> *JsonParser {
called by 1: main
64func json_skip_ws(p: *JsonParser) -> i64 {
called by 1: json_next
83func json_peek(p: *JsonParser) -> i64 {
called by 1: json_next
91func json_read_string(p: *JsonParser) -> i64 {
called by 1: json_next
117func json_read_int(p: *JsonParser) -> i64 {
called by 1: json_next
141func json_skip_digits(p: *JsonParser) -> i64 {
called by 1: json_skip_frac
156func json_skip_frac(p: *JsonParser) -> i64 {
called by 1: json_next calls 1: json_skip_digits
174func json_match(p: *JsonParser, word: *u8, len: i64) -> i64 {
called by 1: json_next
187func json_next(p: *JsonParser) -> i64 {