JsonParser structv0.1.0
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.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from |
input | char8[..] | the text to read |
limits | JsonLimits | the bounds the parse refuses to exceed |
Returns: a parser ready to read the input
Methods
SetDuplicatePolicy
pub func SetDuplicatePolicy(
self: &var JsonParser,
policy: DuplicateKeyPolicy
)
Chooses what to do about duplicate object names.
| Name | Type | Description |
|---|---|---|
policy | DuplicateKeyPolicy | what to do when a name appears twice |
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
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