JsonLexer structv0.1.0
A JSON lexer over a byte slice.
pub struct JsonLexer {
pub position: uint;
// private fields
}
Fields
| Name | Type | Description |
|---|---|---|
position | uint | How far reading has reached. |
Constructors
JsonLexer
pub func JsonLexer(
input: char8[..],
limits: JsonLimits
) -> JsonLexer
A lexer over input under limits.
| Name | Type | Description |
|---|---|---|
input | char8[..] | the text to read |
limits | JsonLimits | the bounds the parse refuses to exceed |
Returns: a lexer positioned at the start of the input
Methods
Position
pub func Position(self: &JsonLexer) -> uint
Where reading has reached, as a byte offset.
Returns: how many bytes have been consumed
Next
pub func Next(self: &var JsonLexer) -> JsonToken
The next token.
Returns: the next token, or the end-of-input token
Related
JsonTokenKind
pub enum JsonTokenKind: int32 {
End = 0,
ObjectStart = 1,
ObjectEnd = 2,
ArrayStart = 3,
ArrayEnd = 4,
Colon = 5,
Comma = 6,
Text = 7,
Number = 8,
True = 9,
False = 10,
Null = 11,
Error = 12
}
What kind of token this is.
Cases
| Name | Value | Description |
|---|---|---|
End | 0 | The input is exhausted. |
ObjectStart | 1 | { |
ObjectEnd | 2 | } |
ArrayStart | 3 | [ |
ArrayEnd | 4 | ] |
Colon | 5 | : |
Comma | 6 | , |
Text | 7 | A string, whose span excludes the quotes. |
Number | 8 | A number, whose span is its whole text. |
True | 9 | true |
False | 10 | false |
Null | 11 | null |
Error | 12 | Something that is not JSON, or a limit that was reached. |
JsonLexError
pub enum JsonLexError: int32 {
None = 0,
UnexpectedByte = 1,
UnterminatedText = 2,
BadEscape = 3,
BadUnicodeEscape = 4,
MalformedNumber = 5,
InvalidUtf8 = 6,
UnescapedControl = 7,
TooManyBytes = 8,
TextTooLong = 9,
TooDeep = 10,
TooManyEntries = 11
}
Why lexing stopped.
Cases
| Name | Value | Description |
|---|---|---|
None | 0 | Nothing went wrong. |
UnexpectedByte | 1 | A byte that begins no token. |
UnterminatedText | 2 | A string that the input ended before closing. |
BadEscape | 3 | An escape sequence JSON does not define. |
BadUnicodeEscape | 4 | A \u escape that is not four hexadecimal digits. |
MalformedNumber | 5 | A number whose shape JSON's grammar does not allow. |
InvalidUtf8 | 6 | Bytes that are not well-formed UTF-8. |
UnescapedControl | 7 | A control character appearing unescaped inside a string, which JSON forbids. |
TooManyBytes | 8 | The document is longer than the configured limit. |
TextTooLong | 9 | A string is longer than the configured limit. |
TooDeep | 10 | Containers are nested deeper than the configured limit. |
TooManyEntries | 11 | A container holds more entries than the configured limit. |
JsonToken
pub struct JsonToken {
pub kind: JsonTokenKind;
pub start: uint;
pub end: uint;
pub escaped: bool;
pub error: JsonLexError;
}
One token, and where in the input it came from.
Fields
| Name | Type | Description |
|---|---|---|
kind | JsonTokenKind | What kind of token this is. |
start | uint | Where its text starts, as a byte offset into the input. |
end | uint | Where its text ends. |
escaped | bool | For a string, whether it contains any escape that must be resolved. A string without one can be used directly from the input, which is what keeps ordinary documents free of copying. |
error | JsonLexError | Why lexing stopped, when the kind is Error. |