techy 0.1.1

A fast, extensible LaTeX parser for Rust
Documentation
# List of panicking items

Parsing never panics on document input: problems in the parsed content surface as
diagnostics or as an `Err` (see [`error`](crate::error)), and every fallible operation
of the API returns a `Result`. The panicking items of the public API are exactly the two
families below; those panics guard against programming errors in calling code — no
document content can trigger them.

**Precondition asserts.** Four span and position functions, the seven scan helpers of
[`core::token`](crate::core::token), the seven span-taking
[`StdToken`](crate::core::token::StdToken) constructors, and the five location methods of
[`TokenReader`](crate::core::token::TokenReader) document a precondition on their
arguments and panic, in all builds, when calling code violates it. These functions are
either deliberately infallible (there is no error channel to prefer), or they report
about the scanned content through their own error channel, which a mistake in calling
code does not belong in; the checks are cheap, and the immediate panic keeps invalid
values unrepresentable instead of letting them cause misbehavior far from the mistake:

- [`Span::new`]crate::source::Span::new — requires `start <= end`; the
  `From<Range<usize>>` conversion for [`Span`]crate::source::Span delegates here, so
  `Span::from(7..3)` panics on the same assert;
- [`Span::extend_to`]crate::source::Span::extend_to — requires the new end not to
  precede the span's current end;
- [`SourceSpan::new`]crate::source::SourceSpan::new — requires the range to lie within
  the source content, on `char` boundaries;
- [`SourcePos::new`]crate::source::SourcePos::new — requires the offset to lie within
  the source content, on a `char` boundary;
- the token constructors [`StdToken::char`]crate::core::token::StdToken::char,
  [`group_open`]crate::core::token::StdToken::group_open,
  [`group_close`]crate::core::token::StdToken::group_close,
  [`command`]crate::core::token::StdToken::command,
  [`specials`]crate::core::token::StdToken::specials,
  [`comment`]crate::core::token::StdToken::comment and
  [`paragraph_break`]crate::core::token::StdToken::paragraph_break — each requires
  the documented coherence of the spans it is given: the pre-space ends exactly where the
  token's span starts; a post-space (`command`, `comment`) is a trailing sub-range of
  that span; a comment's start delimiter is a leading sub-range of it, ending no later
  than the post-space begins. The eighth constructor,
  [`end_of_stream`]crate::core::token::StdToken::end_of_stream, takes no span of its
  own and never panics;
- the scan helpers [`skip_whitespace`]crate::core::token::skip_whitespace,
  [`scan_paragraph_break`]crate::core::token::scan_paragraph_break,
  [`scan_group_delimiter`]crate::core::token::scan_group_delimiter,
  [`command_rule_at`]crate::core::token::command_rule_at,
  [`scan_command`]crate::core::token::scan_command,
  [`scan_comment`]crate::core::token::scan_comment and
  [`scan_specials_trigger`]crate::core::token::scan_specials_trigger — each requires
  `pos` to lie within the content, on a `char` boundary; `scan_command` additionally
  requires `rule.escape_char` to stand at `pos`;
- the location methods of [`TokenReader`]crate::core::token::TokenReader —
  [`source_span_between`]crate::core::token::TokenReader::source_span_between,
  [`source_span_of`]crate::core::token::TokenReader::source_span_of,
  [`source_position_at`]crate::core::token::TokenReader::source_position_at,
  [`source_span_within`]crate::core::token::TokenReader::source_span_within and
  [`source_span_describing`]crate::core::token::TokenReader::source_span_describing —
  each requires the token or the stream position it is given to be one this reader
  produced. An implementation is free to panic on a foreign one, and
  [`StdTokenReader`]crate::core::token::StdTokenReader does: it passes the stored
  offsets straight to `SourceSpan::new` / `SourcePos::new`, whose asserts then fire.
  [`ParseContext::here`]crate::core::constructs::ParseContext::here ends in
  `source_position_at` and inherits this.

**Indexing-style accessors.** Accessors that follow the standard library's
slice-indexing convention: the panicking form is for ids, spans, and regions
obtained from the very tree or source in hand, and each panic is stated in a
"Panics" section on the item's own page; for values of unknown provenance, use
the non-panicking companion:

- [`NodeTree::node`]crate::core::node::NodeTree::node — panics on an id another tree
  minted (the non-panicking companion is
  [`NodeTree::get`]crate::core::node::NodeTree::get);
- [`NodeTree::nodes_in`]crate::core::node::NodeTree::nodes_in — panics on a range
  outside the tree's storage;
- [`Span::slice`]crate::source::Span::slice — panics on a span invalid for the given
  content (the non-panicking companion is [`Span::get`]crate::source::Span::get);
- [`TextContent::resolve`]crate::source::TextContent::resolve — panics on a stored
  range invalid for the given source's content (a broken invariant, which no
  parsed input can cause; every operation that resolves or materializes a tree's
  span-backed text — among others
  [`TextContent::materialized`]crate::source::TextContent::materialized,
  [`NodeRef::chars`]crate::core::node::NodeRef::chars,
  [`NodeRef::group_delimiters`]crate::core::node::NodeRef::group_delimiters,
  [`NodeRef::post_space`]crate::core::node::NodeRef::post_space,
  [`NodeRef::summary`]crate::core::node::NodeRef::summary,
  [`NodeTree::materialize`]crate::core::node::NodeTree::materialize,
  [`display_tree`]crate::core::node::display_tree, the content-reading helpers of
  [`extract`]crate::extract,
  [`core_source_instruction`]crate::recompose::core_source_instruction, the preset's
  source recomposer and its environment-syntax writers
  ([`EnvironmentSyntax::write_begin`]crate::latexlike::EnvironmentSyntax::write_begin
  and [`write_end`]crate::latexlike::EnvironmentSyntax::write_end), and the tree
  serialization of [`serialize`]crate::serialize — namely
  [`TreeSerialization::serialize_tree`]crate::serialize::TreeSerialization::serialize_tree,
  [`ParseResultSerialization::serialize_parse_result`]crate::serialize::ParseResultSerialization::serialize_parse_result
  and the [`SerializableObject`]crate::serialize::SerializableObject implementation
  for [`ParseResult`]crate::core::ParseResult, each of which states the panic on its
  own page —
  reaches this panic on a consumer-built tree that breaks the invariant, and on no other
  input. [`validate_tree`]crate::core::node::validate_tree checks a tree for this,
  with one gap: it does not inspect a language's invocation-syntax payload, so the
  span-backed fields recorded there — a callable's post-space, an environment's
  begin/end syntax — are the language's own responsibility to keep valid);
- [`ChildRegion::children`]crate::core::node::ChildRegion::children,
  [`ChildRegion::content_range`]crate::core::node::ChildRegion::content_range, and
  [`ChildRegion::content_parent`]crate::core::node::ChildRegion::content_parent —
  panic on a staged (never finished) region, which no finished tree can contain
  (guard with [`ChildRegion::is_resolved`]crate::core::node::ChildRegion::is_resolved;
  the non-panicking companion answering the staged coordinates is
  [`ChildRegion::staged`]crate::core::node::ChildRegion::staged).

These two families are the complete list of documented panics in the public API;
no other public item panics on documented use.

Read next: back to the [Developer Guide](crate::guide#developer-guide) index —
the other chapters on extending and embedding techy.