TomlParseFailure structv0.1.0
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
| Name | Type | Description |
|---|---|---|
reason | TomlParseError | Why parsing stopped. |
offset | uint | The zero-based byte offset into the document where it stopped. |
line | uint | Which line, counting from one. |
column | uint | Which 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
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole description was accepted
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.
| Name | Type | Description |
|---|---|---|
writer | &var TextWriter | the destination |
spec | FormatSpec | what the placeholder asked for |
Returns: success when the whole rendering was accepted
Related
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.
Cases
| Name | Description |
|---|---|
Lexical(TomlLexError) | The lexer refused the input, for the reason carried. |
Unexpected | A token that cannot appear where it did. |
Truncated | The document ended in the middle of something. |
DuplicateKey | A key given a value twice in the same table. |
RedefinedTable | A table defined by a header that had already been defined by one. |
ExtendedInlineTable | An attempt to add to a table that was written inline, which its closing brace ended. |
ExtendedDottedTable | An attempt to add to a table that a dotted key created, which its line ended. |
NotATable | A key path that runs through something that is not a table. |
NotATableArray | A [[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. |
BadText | A string whose escapes name no scalar value. |
TooDeep | Values nested deeper than the limit allowed. |
OutOfMemory | The allocator refused. |