code wiki / (root) / nx_json.nx

nx_json.nx

buildroot/runtime/nx_json.nx

12598 B306 linesdepth 5pulls 6 transitivereach 150 importersview sourcekind tooltopic json
docsdependenciesstructsconstsfunctions

about

nx_json.nx -- JSON tokenizer (RFC 8259 subset). Streaming token-stream API: caller drives nx_json_next which reports the next token kind + span within the input buffer. A second pass (or the caller's own state machine) builds the tree. Token kinds: NX_JSON_LBRACE { NX_JSON_RBRACE } NX_JSON_LBRACKET [ NX_JSON_RBRACKET ] NX_JSON_COMMA , NX_JSON_COLON : NX_JSON_STRING "..." (span includes quotes) NX_JSON_NUMBER -123.4e5 (span covers all digits + sign + exp) NX_JSON_TRUE true NX_JSON_FALSE false NX_JSON_NULL null NX_JSON_EOF end of input NX_JSON_ERROR malformed input String content escapes (\n, \t, \uXXXX) are NOT decoded by the tokenizer -- the span includes the raw bytes between the quotes. A separate nx_pct-style decoder can be added later. nx_safety_envelope: intended_use: "JSON decoder -- substrate-native parsing of structured data per cardinal feedback-no-pdfs- no-proprietary-binary-formats" sil_target: SIL2 (input parsing; malformed JSON must not crash callers) asil_target: QM dal_target: DAL C evidence: [RFC_8259_canonical_basis, no_FP, sealed_token_kind_enum, bounded_recursion_depth] hazard_register: [bug-tape-JSON-bomb-via-deep-nesting, bug-tape-billion-laughs-style-amplification, bug-tape-Unicode-escape-handling-bug]

dependencies 3 imports · 4 importers

nx_syscalls.nx nx_lex.nx nx_ascii.nx nx_json.nx nx_js_eval.nx nx_json_adversarial_test.nx nx_json_test.nx nx_lib_parse.nx

imports: nx_syscalls.nxnx_lex.nxnx_ascii.nx

imported by: nx_js_eval.nxnx_json_adversarial_test.nxnx_json_test.nxnx_lib_parse.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nx_json_new sys_mmap ↻ nx_json_next nx_json_skip_ws nx_lex_is_ws nx_ascii_is_digit sys_mmap ↻ nx_json_lit

structs

64struct NxJsonTok {

consts

50const NX_JSON_LBRACE: i64 = 1
51const NX_JSON_RBRACE: i64 = 2
52const NX_JSON_LBRACKET: i64 = 3
53const NX_JSON_RBRACKET: i64 = 4
54const NX_JSON_COMMA: i64 = 5
55const NX_JSON_COLON: i64 = 6
56const NX_JSON_STRING: i64 = 7
57const NX_JSON_NUMBER: i64 = 8
58const NX_JSON_TRUE: i64 = 9
59const NX_JSON_FALSE: i64 = 10
60const NX_JSON_NULL: i64 = 11
61const NX_JSON_EOF: i64 = 12
62const NX_JSON_ERROR: i64 = 13
74const NX_JSONTOK_BYTES: i64 = 48

functions

76func nx_json_new(src: *u8, len: i64) -> *NxJsonTok {
93func nx_json_skip_ws(t: *NxJsonTok) -> i64 {
called by 1: nx_json_next calls 1: nx_lex_is_ws
103func nx_json_lit(t: *NxJsonTok, lit: *u8, n: i64) -> i64 {
called by 1: nx_json_next
116func nx_json_next(t: *NxJsonTok) -> i64 {
252func main() -> i64 {