nx_json.nx
buildroot/runtime/nx_json.nx
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
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
structs
| 64 | struct NxJsonTok { |
consts
| 50 | const NX_JSON_LBRACE: i64 = 1 |
| 51 | const NX_JSON_RBRACE: i64 = 2 |
| 52 | const NX_JSON_LBRACKET: i64 = 3 |
| 53 | const NX_JSON_RBRACKET: i64 = 4 |
| 54 | const NX_JSON_COMMA: i64 = 5 |
| 55 | const NX_JSON_COLON: i64 = 6 |
| 56 | const NX_JSON_STRING: i64 = 7 |
| 57 | const NX_JSON_NUMBER: i64 = 8 |
| 58 | const NX_JSON_TRUE: i64 = 9 |
| 59 | const NX_JSON_FALSE: i64 = 10 |
| 60 | const NX_JSON_NULL: i64 = 11 |
| 61 | const NX_JSON_EOF: i64 = 12 |
| 62 | const NX_JSON_ERROR: i64 = 13 |
| 74 | const NX_JSONTOK_BYTES: i64 = 48 |
functions
| 76 | func nx_json_new(src: *u8, len: i64) -> *NxJsonTok { |
| 93 | func nx_json_skip_ws(t: *NxJsonTok) -> i64 { |
| 103 | func nx_json_lit(t: *NxJsonTok, lit: *u8, n: i64) -> i64 {
called by 1: nx_json_next |
| 116 | func nx_json_next(t: *NxJsonTok) -> i64 {
called by 4: maindrain_tokmainnx_json_get_str calls 4: nx_json_skip_wsnx_ascii_is_digitsys_mmapnx_json_lit |
| 252 | func main() -> i64 { |