Skip to content

JSONToken

[Source]

A single token emitted by JSONTokenParser.

The structural tokens ({ } [ ]) and the literals (true, false, null) are primitives — the type is the whole value. The three tokens that carry data — a key, a string, a number — are classes whose value field holds it, so a token is a value you can hold: match it and read value, with nothing shared or overwritten between tokens.

A key or string value that fits within a single fed chunk with no escapes is a zero-copy view into that chunk. Holding such a token (or its value) keeps the chunk's bytes in memory until you drop it — extracting one small field from a large chunk and holding it pins the whole chunk. A view is also not NUL-terminated, so passing its cpointer() to C that expects a C string reads past the value; use it as a Pony String. Strings with escapes, or split across a chunk boundary, are decoded copies that hold nothing and are NUL-terminated.

match token
| let k: JSONTokenKey    => // k.value : String
| let s: JSONTokenString => // s.value : String
| let n: JSONTokenNumber => // n.value : (I64 | F64)
| JSONTokenObjectStart   => // ...
end
type JSONToken is
  (JSONTokenObjectStart val | JSONTokenObjectEnd val | JSONTokenArrayStart val | JSONTokenArrayEnd val | JSONTokenTrue val | JSONTokenFalse val | JSONTokenNull val | JSONTokenKey val | JSONTokenString val | JSONTokenNumber val)

Type Alias For