Silk

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: usize

Maximum nested arrays and inline tables.

TomlSpan

pub struct TomlSpan

A half-open source byte range.

Field offset

pub offset: usize

First byte in the complete input.

Field length

pub length: usize

Number of source bytes.

Implementation Copy for TomlSpan

impl Copy for TomlSpan

Implementation Copy for TomlError

impl Copy for TomlError

TomlReason

pub enum TomlReason

Stable scanner failure categories.

UnexpectedByte

UnexpectedByte = 0

A byte is not permitted in the current construct.

UnexpectedEnd

UnexpectedEnd = 1

The document ended before the construct was complete.

InvalidUtf8

InvalidUtf8 = 2

The input is not well-formed UTF-8.

InvalidString

InvalidString = 3

A string delimiter or unescaped control character is invalid.

InvalidEscape

InvalidEscape = 4

A basic string escape is invalid.

InvalidNumber

InvalidNumber = 5

An unquoted numeric or boolean spelling is invalid.

InvalidDateTime

InvalidDateTime = 6

A date or time spelling has an invalid field or structure.

TypeMismatch

TypeMismatch = 7

A typed conversion expected another TOML value kind.

NumberOutOfRange

NumberOutOfRange = 8

A valid TOML number does not fit the requested numeric type.

DuplicateKey

DuplicateKey = 9

A key is defined more than once in one table.

TableConflict

TableConflict = 10

A table definition conflicts with an earlier value or table.

DepthExceeded

DepthExceeded = 11

More than MAX_DEPTH arrays or inline tables are nested.

TomlError

pub struct TomlError

A scanner failure at a source byte offset.

Field reason

pub reason: TomlReason

Stable category of the first syntax failure.

Field offset

pub offset: usize

Absolute byte position of the failure.

TomlScalarKind

pub enum TomlScalarKind

The validated type of an unquoted TOML scalar.

Integer

Integer = 0

A decimal or base-prefixed whole number.

Float

Float = 1

A decimal, exponent, infinity, or NaN spelling.

Boolean

Boolean = 2

The literal true or false.

OffsetDateTime

OffsetDateTime = 3

A date and time with an explicit UTC offset.

LocalDateTime

LocalDateTime = 4

A date and time without an offset.

LocalDate

LocalDate = 5

A calendar date without a time.

LocalTime

LocalTime = 6

A clock time without a date.

TomlToken

pub union TomlToken

Source-level token. Text is classified by TomlScanner.scalarKind in value position.

Text

TomlToken.Text { span: TomlSpan }: TomlToken

A bare key or unquoted value spelling, including any interior decimal points.

Field span

pub span: TomlSpan

The raw source range.

String

TomlToken.String { span: TomlSpan, literal: bool, multiline: bool }: TomlToken

A quoted string or key, including its source delimiters.

Field span

pub span: TomlSpan

The raw quoted source range.

Field literal

pub literal: bool

Whether the quote character is an apostrophe.

Field multiline

pub multiline: bool

Whether the source uses triple quotes.

Equals

TomlToken.Equals: TomlToken

A key/value separator.

Dot

TomlToken.Dot: TomlToken

A dot between quoted or bare key parts.

Comma

TomlToken.Comma: TomlToken

A separator between array elements or inline table entries.

ArrayBegin

TomlToken.ArrayBegin: TomlToken

An opening square bracket.

ArrayEnd

TomlToken.ArrayEnd: TomlToken

A closing square bracket.

InlineBegin

TomlToken.InlineBegin: TomlToken

An opening inline table brace.

InlineEnd

TomlToken.InlineEnd: TomlToken

A closing inline table brace.

Newline

TomlToken.Newline: TomlToken

An LF or CRLF source newline.

EndOfInput

TomlToken.EndOfInput: TomlToken

The end of the complete input.

Implementation Copy for TomlToken

impl Copy for TomlToken

TomlScanner

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>) -> usize

Returns the byte offset of the next lexical token.

On this page