TomlParseFailure structv0.1.0

Source
Why a document was refused, and where in it.
pub struct TomlParseFailure {
    pub reason: TomlParseError;
    pub offset: uint;
    pub line: uint;
    pub column: uint;
}

Three positions for one place, because the three are wanted by different readers: offset is what a program slices the input with, and line and column are what a person is shown. They always name the same byte.

Fields

NameTypeDescription
reasonTomlParseErrorWhy parsing stopped.
offsetuintThe zero-based byte offset into the document where it stopped.
lineuintWhich line, counting from one.
columnuintWhich column, counting from one, in bytes.

Implements ParseFailure

TomlParseFailure conforms to ParseFailure.

Offset

pub func Offset(self: &TomlParseFailure) -> uint

Where in the document parsing stopped. Borrows the failure and leaves it untouched. Cannot fail; runs in constant time and allocates nothing.

Returns: the zero-based byte offset into the document

Source

Implements Display

TomlParseFailure conforms to Display.

WriteDisplay

pub func WriteDisplay(
    self: &TomlParseFailure,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Writes the description of why parsing stopped, without the position. The line and column are numbers a caller places where it makes sense for them, so they are not written into the middle of a sentence here. Debug carries them. Reports whatever the writer reported, and UnsupportedRequest for any style or precision.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole description was accepted

Source

Implements Debug

TomlParseFailure conforms to Debug.

WriteDebug

pub func WriteDebug(
    self: &TomlParseFailure,
    writer: &var TextWriter,
    spec: FormatSpec
) -> ! FormatError

Names the case and where it happened: TomlParseError::DuplicateKey at 2:1. A case that carries something names that too, so nothing has to be looked up elsewhere: TomlParseError::BadValue(TomlScalarError::Malformed(4)) at 1:8. Reports whatever the writer reported, and UnsupportedRequest for any style or precision.

NameTypeDescription
writer&var TextWriterthe destination
specFormatSpecwhat the placeholder asked for

Returns: success when the whole rendering was accepted

Source

TomlParseError

pub variant TomlParseError {
    Lexical(TomlLexError),
    Unexpected,
    Truncated,
    DuplicateKey,
    RedefinedTable,
    ExtendedInlineTable,
    ExtendedDottedTable,
    NotATable,
    NotATableArray,
    BadValue(TomlScalarError),
    BadText,
    TooDeep,
    OutOfMemory
}

Why parsing stopped. Failure-only: a parse that did not stop hands back a document instead. The distinctions between the four table-definition cases are the ones worth keeping — DuplicateKey, RedefinedTable, ExtendedInlineTable and ExtendedDottedTable are four different mistakes with four different fixes, and a reader told only that a key was defined twice would have to work out which rule they had met. The two cases that have something more to say carry it rather than reporting it beside themselves, so a caller holding the failure cannot be holding half of one.

Source

Cases

NameDescription
Lexical(TomlLexError)The lexer refused the input, for the reason carried.
UnexpectedA token that cannot appear where it did.
TruncatedThe document ended in the middle of something.
DuplicateKeyA key given a value twice in the same table.
RedefinedTableA table defined by a header that had already been defined by one.
ExtendedInlineTableAn attempt to add to a table that was written inline, which its closing brace ended.
ExtendedDottedTableAn attempt to add to a table that a dotted key created, which its line ended.
NotATableA key path that runs through something that is not a table.
NotATableArrayA [[name]] header naming an array that was not built from headers, or a table.
BadValue(TomlScalarError)A scalar whose text is not the number or date TOML's grammar defines, for the reason carried. The scalar failure's own offset is into the scalar's text; the failure around it is positioned in the document.
BadTextA string whose escapes name no scalar value.
TooDeepValues nested deeper than the limit allowed.
OutOfMemoryThe allocator refused.