tor_netdoc/parse.rs
1//! Parsing support for the network document meta-format
2//!
3//! The meta-format used by Tor network documents evolved over time
4//! from a legacy line-oriented format. It's described more fully
5//! in Tor's
6//! [dir-spec.txt](https://spec.torproject.org/dir-spec).
7//!
8//! In brief, a network document is a sequence of [tokenize::Item]s.
9//! Each Item starts with a [keyword::Keyword], takes a number of
10//! _arguments_ on the same line, and is optionally followed by a
11//! PEM-like base64-encoded _object_.
12//!
13//! Individual document types define further restrictions on the
14//! Items. They may require Items with a particular keyword to have a
15//! certain number of arguments, to have (or not have) a particular
16//! kind of object, to appear a certain number of times, and so on.
17//!
18//! More complex documents can be divided into [parser::Section]s. A
19//! Section might correspond to the header or footer of a longer
20//! document, or to a single stanza in a longer document.
21//!
22//! To parse a document into a Section, the programmer defines a type
23//! of keyword that the document will use, using the
24//! `decl_keyword!` macro. The programmer then defines a
25//! [parser::SectionRules] object, containing a [rules::TokenFmt]
26//! describing the rules for each allowed keyword in the
27//! section. Finally, the programmer uses a [tokenize::NetDocReader]
28//! to tokenize the document, passing the stream of tokens to the
29//! SectionRules object to validate and parse it into a Section.
30//!
31//! For multiple-section documents, this crate uses
32//! [`Itertools::peeking_take_while`](itertools::Itertools::peeking_take_while)
33//! (via a `[.pause_at`](NetDocReader::pause_at) convenience method)
34//! and a [batching_split_before](crate::util::batching_split_before)
35//! module which can split
36//! a document item iterator into sections..
37
38pub(crate) mod keyword;
39pub(crate) mod parser;
40pub(crate) mod rules;
41pub(crate) mod tokenize;
42#[macro_use]
43pub(crate) mod macros;