JsonParser structv0.1.0

Source
A parser over a document.
pub struct JsonParser {
    // private fields
}

Constructors

JsonParser

pub func JsonParser(
    allocator: Allocator,
    input: char8[..],
    limits: JsonLimits
) -> JsonParser

A parser over input under limits, rejecting duplicate names.

NameTypeDescription
allocatorAllocatorwhere the storage comes from
inputchar8[..]the text to read
limitsJsonLimitsthe bounds the parse refuses to exceed

Returns: a parser ready to read the input

Source

Methods

SetDuplicatePolicy

pub func SetDuplicatePolicy(
    self: &var JsonParser,
    policy: DuplicateKeyPolicy
)

Chooses what to do about duplicate object names.

NameTypeDescription
policyDuplicateKeyPolicywhat to do when a name appears twice

Source

Failure

pub func Failure(self: &JsonParser) -> JsonParseError?

Whether parsing stopped, and why. none while nothing has gone wrong, which for a parser that has finished means the document was read. A caller using Parse never needs this: the failure comes back in the result.

Returns: the failure, positioned, or none

Source

Parse

pub func Parse(self: &var JsonParser) -> JsonValue ! JsonParseError

Parses the whole document and returns its top-level value, or why it could not. Anything after that value is TrailingContent — a document is one value, and two concatenated ones are not a document however well-formed each is. A failure gives back nothing at all. Whatever had been built when the parser stopped is released here, which is the only place that can be done once: an array that failed at its third element owns two, and handing those back beside an error would leave a caller holding a document that is not one. Fails with any case of JsonParseError, positioned at the byte where parsing stopped.

Returns: the document, or the failure that stopped it

Source