silk/toml_scanner
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc.
TOML 1.1.0 lexical scanning and document syntax validation.
When to use
Validate a complete UTF-8 document with TomlScanner.validate, then use
TomlScanner.next to inspect its source tokens and byte spans.
Details
Tokens retain their source spelling. Validation checks keys, scalar forms, strings, arrays, inline tables, and headers. Defining and reconciling document keys belongs to the document reader.
Import as TomlScanner with import silk.toml_scanner { TomlScanner }.
Public declarations: 7.
MAX_DEPTH
pub const MAX_DEPTH: usizeMaximum nested arrays and inline tables.
TomlSpan
pub struct TomlSpanA half-open source byte range.
Field offset
pub offset: usizeFirst byte in the complete input.
Field length
pub length: usizeNumber of source bytes.
Implementation Copy for TomlSpan
impl Copy for TomlSpanImplementation Copy for TomlError
impl Copy for TomlErrorTomlReason
pub enum TomlReasonStable scanner failure categories.
UnexpectedByte
UnexpectedByte = 0A byte is not permitted in the current construct.
UnexpectedEnd
UnexpectedEnd = 1The document ended before the construct was complete.
InvalidUtf8
InvalidUtf8 = 2The input is not well-formed UTF-8.
InvalidString
InvalidString = 3A string delimiter or unescaped control character is invalid.
InvalidEscape
InvalidEscape = 4A basic string escape is invalid.
InvalidNumber
InvalidNumber = 5An unquoted numeric or boolean spelling is invalid.
InvalidDateTime
InvalidDateTime = 6A date or time spelling has an invalid field or structure.
TypeMismatch
TypeMismatch = 7A typed conversion expected another TOML value kind.
NumberOutOfRange
NumberOutOfRange = 8A valid TOML number does not fit the requested numeric type.
DuplicateKey
DuplicateKey = 9A key is defined more than once in one table.
TableConflict
TableConflict = 10A table definition conflicts with an earlier value or table.
DepthExceeded
DepthExceeded = 11More than MAX_DEPTH arrays or inline tables are nested.
TomlError
pub struct TomlErrorA scanner failure at a source byte offset.
Field reason
pub reason: TomlReasonStable category of the first syntax failure.
Field offset
pub offset: usizeAbsolute byte position of the failure.
TomlScalarKind
pub enum TomlScalarKindThe validated type of an unquoted TOML scalar.
Integer
Integer = 0A decimal or base-prefixed whole number.
Float
Float = 1A decimal, exponent, infinity, or NaN spelling.
Boolean
Boolean = 2The literal true or false.
OffsetDateTime
OffsetDateTime = 3A date and time with an explicit UTC offset.
LocalDateTime
LocalDateTime = 4A date and time without an offset.
LocalDate
LocalDate = 5A calendar date without a time.
LocalTime
LocalTime = 6A clock time without a date.
TomlToken
pub union TomlTokenSource-level token. Text is classified by TomlScanner.scalarKind in value position.
Text
TomlToken.Text { span: TomlSpan }: TomlTokenA bare key or unquoted value spelling, including any interior decimal points.
Field span
pub span: TomlSpanThe raw source range.
String
TomlToken.String { span: TomlSpan, literal: bool, multiline: bool }: TomlTokenA quoted string or key, including its source delimiters.
Field span
pub span: TomlSpanThe raw quoted source range.
Field literal
pub literal: boolWhether the quote character is an apostrophe.
Field multiline
pub multiline: boolWhether the source uses triple quotes.
Equals
TomlToken.Equals: TomlTokenA key/value separator.
Dot
TomlToken.Dot: TomlTokenA dot between quoted or bare key parts.
Comma
TomlToken.Comma: TomlTokenA separator between array elements or inline table entries.
ArrayBegin
TomlToken.ArrayBegin: TomlTokenAn opening square bracket.
ArrayEnd
TomlToken.ArrayEnd: TomlTokenA closing square bracket.
InlineBegin
TomlToken.InlineBegin: TomlTokenAn opening inline table brace.
InlineEnd
TomlToken.InlineEnd: TomlTokenA closing inline table brace.
Newline
TomlToken.Newline: TomlTokenAn LF or CRLF source newline.
EndOfInput
TomlToken.EndOfInput: TomlTokenThe end of the complete input.
Implementation Copy for TomlToken
impl Copy for TomlTokenTomlScanner
pub struct TomlScanner<'input>A complete-input scanner. validate starts from the beginning and does not consume tokens.
Associated function TomlScanner.make
pub fn make<'input>(input: &'input [u8]) -> silk/toml_scanner.TomlScanner<'input>Creates a scanner borrowing a complete TOML source.
Method TomlScanner.validate
pub fn validate<'life1, 'life2>(self: &'life1 mut silk/toml_scanner.TomlScanner<'life2>) -> silk/result.Result<bool, silk/toml_scanner.TomlError>Validates the complete document; key equality is handled by the document reader.
Method TomlScanner.next
pub fn next<'life1, 'life2>(self: &'life1 mut silk/toml_scanner.TomlScanner<'life2>) -> silk/result.Result<silk/toml_scanner.TomlToken, silk/toml_scanner.TomlError>Returns the next lexical source token.
Method TomlScanner.scalarKind
pub fn scalarKind<'life1, 'life2>(self: &'life1 silk/toml_scanner.TomlScanner<'life2>, span: TomlSpan) -> silk/option.Option<silk/toml_scanner.TomlScalarKind>Classifies an unquoted scalar spelling.
Method TomlScanner.slice
pub fn slice<'input, 'life1>(self: &'life1 silk/toml_scanner.TomlScanner<'input>, span: TomlSpan) -> &'input [u8]Borrows the raw source bytes of a token span.
Method TomlScanner.offset
pub fn offset<'life1, 'life2>(self: &'life1 silk/toml_scanner.TomlScanner<'life2>) -> usizeReturns the byte offset of the next lexical token.