Valid parser states.
Valid parser states.
Access a byte range as a string.
Access a byte range as a string.
Since the underlying data are UTF-8 encoded, i and k must occur on unicode boundaries. Also, the resulting String is not guaranteed to have length (k - i).
Read the byte/char at 'i' as a Char.
Read the byte/char at 'i' as a Char.
Note that this should not be used on potential multi-byte sequences.
Return true iff 'i' is at or beyond the end of the input (EOF).
Return true iff 'i' is at or beyond the end of the input (EOF).
This is a specialized accessor for the case where our underlying data are bytes not chars.
This is a specialized accessor for the case where our underlying data are bytes not chars.
We use this to keep track of the last recoverable place we've seen.
We use this to keep track of the last recoverable place we've seen. If we hit an AsyncException, we can later resume from this point.
This method is called during every loop of rparse, and the arguments are the exact arguments we can pass to rparse to continue where we left off.
Should be called when parsing is finished.
Should be called when parsing is finished.
Generate a Char from the hex digits of "ሴ" (i.e.
Generate a Char from the hex digits of "ሴ" (i.e. "1234").
NOTE: This is only capable of generating characters from the basic plane. This is why it can only return Char instead of Int.
Used to generate error messages with character info and byte addresses.
Used to generate error messages with character info and byte addresses.
Used to generate messages for internal errors.
Used to generate messages for internal errors.
Return true iff the bytes/chars from 'i' until 'j' are equal to 'str'.
Return true iff the bytes/chars from 'i' until 'j' are equal to 'str'.
Return true iff the byte/char at 'i' is equal to 'c'.
Return true iff the byte/char at 'i' is equal to 'c'.
Parse and return the "next" JSON value as well as the position beyond it.
Parse and return the "next" JSON value as well as the position beyond it. This method is used by both parse() as well as parseMany().
Parse the JSON constant "false".
Parse the JSON constant "false".
Parse the JSON constant "null".
Parse the JSON constant "null".
Parse the given number, and add it to the given context.
Parse the given number, and add it to the given context.
We don't actually instantiate a number here, but rather save the string for future use. This ends up being way faster and has the nice side-effect that we know exactly how the user represented the number.
It would probably be possible to keep track of the whether the number is expected to be whole, decimal, etc. but we don't do that at the moment.
This number parser is a bit slower because it has to be sure it doesn't run off the end of the input.
This number parser is a bit slower because it has to be sure it doesn't run off the end of the input. Normally (when operating in rparse in the context of an outer array or objedct) we don't have to worry about this and can just grab characters, because if we run out of characters that would indicate bad input.
This method has all the same caveats as the previous method.
Parse the string according to JSON rules, and add to the given context.
Parse the string according to JSON rules, and add to the given context.
This method expects the data to be in UTF-8 and accesses it as bytes.
See if the string has any escape sequences.
See if the string has any escape sequences. If not, return the end of the string. If so, bail out and return -1.
This method expects the data to be in UTF-8 and accesses it as bytes. Thus we can just ignore any bytes with the highest bit set.
Parse the JSON constant "true".
Parse the JSON constant "true".
The reset() method is used to signal that we're working from the given position, and any previous data can be released.
The reset() method is used to signal that we're working from the given position, and any previous data can be released. Some parsers (e.g. StringParser) will ignore release, while others (e.g. PathParser) will need to use this information to release and allocate different areas.
Tail-recursive parsing method to do the bulk of JSON parsing.
Tail-recursive parsing method to do the bulk of JSON parsing.
This single method manages parser states, data, etc. Except for parsing non-recursive values (like strings, numbers, and constants) all important work happens in this loop (or in methods it calls, like reset()).
Currently the code is optimized to make use of switch statements. Future work should consider whether this is better or worse than manually constructed if/else statements or something else.