JsonDoc

Top level JSON type containing an entire document. A JSON document consists of exactly 1 value.

class ref JsonDoc

Constructors

create

new iso create()
: JsonDoc iso^

Returns


Public fields


Public Functions

string

Generate string representation of this document.

fun box string(
  indent: String val = seq,
  pretty_print: Bool val = seq)
: String val

Parameters

  • indent: String val = seq
  • pretty_print: Bool val = seq

Returns


parse

Parse the given string as a JSON file, building a document. Raise error on invalid JSON in given source.

fun ref parse(
  source: String val)
: None val ?

Parameters

Returns


parse_report

Give details of the error that occurred last time we attempted to parse. If parse was successful returns (0, "").

fun box parse_report()
: (USize val , String val)

Returns


Private Functions

_parse_value

Parse a single JSON value of any type, which MUST be present. Raise error on invalid or missing value.

fun ref _parse_value(
  context: String val)
: (F64 val | I64 val | Bool val | 
    None val | String val | JsonArray ref | 
    JsonObject ref) ?

Parameters

Returns


_parse_keyword

Parse a keyword, the first letter of which has already been peeked.

fun ref _parse_keyword()
: (Bool val | None val) ?

Returns


_parse_number

Parse a number, the leading character of which has already been peeked.

fun ref _parse_number()
: (F64 val | I64 val) ?

Returns


_parse_decimal

Parse a decimal integer which must appear immediately in the source.

fun ref _parse_decimal()
: (I64 val , U8 val) ?

Returns


_parse_object

Parse a JSON object, the leading { of which has already been peeked.

fun ref _parse_object()
: JsonObject ref ?

Returns


_parse_array

Parse an array, the leading [ of which has already been peeked.

fun ref _parse_array()
: JsonArray ref ?

Returns


_parse_string

Parse a string, which must be the next thing found, other than whitesapce.

fun ref _parse_string(
  context: String val)
: String val ?

Parameters

Returns


_parse_escape

Process a string escape sequence, the leading \ of which has already been consumed.

fun ref _parse_escape()
: String val ?

Returns


_parse_unicode_escape

Process a Unicode escape sequence, the leading \u of which has already been consumed.

fun ref _parse_unicode_escape()
: String val ?

Returns


_parse_unicode_digits

Parse the hex digits of a Unicode escape sequence, the leading \u of which has already been consumed, and return the encoded character value.

fun ref _parse_unicode_digits()
: U32 val ?

Returns


_dump_whitespace

Dump all whitespace at the current read location in source, if any.

fun ref _dump_whitespace()
: None val

Returns


_peek_char

Peek the next char in the source, without consuming it. If an eof_context is given then an error is thrown on eof, setting a suitable message. If eof_context is None then 0 is returned on EOF. It up to the caller to handle this appropriately.

fun ref _peek_char(
  eof_context: (String val | None val) = seq)
: U8 val ?

Parameters

Returns

  • U8 val ?

_get_char

Get and consume the next char in the source. If an eof_context is given then an error is thrown on eof, setting a suitable message. If eof_context is None then 0 is returned on EOF. It up to the caller to handle this appropriately.

fun ref _get_char(
  eof_context: (String val | None val) = seq)
: U8 val ?

Parameters

Returns

  • U8 val ?

_last_char

Get the last character peeked or got from the source as a String. For use generating error messages.

fun ref _last_char()
: String val

Returns


_error

Record an error with the given message.

fun ref _error(
  msg: String val)
: None val

Parameters

Returns