parse2
only.Expand description
New netdoc parsing arrangements, with derive
§Parsing principles
A parseable network document is a type implementing NetdocParseable
.
usually via the
NetdocParseable
derive=deftly macro`.
A document type is responsible for recognising its own heading item. Its parser will also be told other of structural items that it should not consume. The structural lines can then be used to pass control to the appropriate parser.
§Ordering
We don’t parse things into a sorted order. Sorting will be done on output.
§Types, and signature handling
Most top-level network documents are signed somehow. In this case there are three types:
-
FooSigned
: a signedFoo
, with its signatures, not yet verified. Implements [NetdocSigned
], typically by invoking theNetdocSigned
derive macro onFoo
.Type-specific methods are provided for verification, to obtain a
Foo
. -
Foo
: the body data for the document. This doesn’t contain any signatures. Having one of these to play with means signatures have already been validated. ImplementNetdocParseable
, via derive. -
FooSignatures
: the signatures for aFoo
. ImplementNetdocParseable
, via derive, with#[deftly(netdoc(signatures))]
.
§Naming conventions
DocumentName
: important types, including network documents or sub-documents, egNetworkStatsuMd
andRouterVote
, and types that are generally useful.NddDoucmnetSection
: sections and sub-documents that the user won’t normally need to name.NdiItemValue
: parsed value for a network document Item. egNdiVoteStatus
representing the whole of the RHS of avote-status
Item. Often not needed sinceItemValueParseable
is implemented for suitable tuples.NdaArgumentValue
: parsed value for a single argument; egNdaVoteStatus
representing thevote
orstatus
argument.
§Relationship to tor_netdoc::parse
This is a completely new parsing approach, based on different principles.
The key principle is the recognition of “structural keywords”,
recursively within a parsing stack, via the pNetdocParseable
] trait.
This allows the parser to be derived. We have type-driven parsing of whole Documents, Items, and their Arguments and Objects, including of their multiplicity.
The different keyword handling means we can’t use most of the existing lexer, and need new item parsing API:
NetdocParseable
trait.KeywordRef
type.ItemStream
,UnparsedItem
,ArgumentStream
,UnparsedObject
.
The different error handling means we have our own error types. (The crate’s existing parse errors have information that we don’t track, and is also a portmanteau error for parsing, writing, and other functions.)
Document signing is handled in a more abstract way.
Some old netdoc constructs are not supported.
For example, the obsolete opt
prefix on safe-to-ignore Items.
The parser may make different decisions about netdocs with anomalous item ordering.
Re-exports§
pub use keyword::KeywordRef;
Modules§
- keyword
- Keywords in netdocs
- multiplicity
- Multiplicity of fields (Items and Arguments)
- poc
- Proof-of-concept parser using parse2 for network status documents
- sig_
hash_ methods - Methods suitable for use with
#[deftly(netdoc(sig_hash = "METHOD"))]
Structs§
- Argument
Stream - Reader for arguments on an Item
- Item
Stream - Top-level reader: Netdoc text interpreted as a stream of items
- Lines
- Version of
std::str::Lines
that tracks line numbers and hasremainder()
- NdaSystem
Time Deprecated Syntax - Date and time in deprecated ISO8601-with-space separate arguments syntax
- NoFurther
Arguments - End of an argument list that does not accept any further (unknown) arguments
- Parse
Error - Error encountered when parsing a document, including its location
- Peeked
- Information about the next line we have peeked
- Signature
Hash Inputs - Inputs needed to calculate a specific signature hash for a specific Item
- StopAt
- Predicate for testing whether a keyword is a structural one that we should stop at
- Unparsed
Item - An Item that has been lexed but not parsed
- Unparsed
Object - An Object that has been lexed but not parsed
Enums§
- Error
Problem - Problem found when parsing a document
- Verify
Failed - Error from signature verification (and timeliness check)
Traits§
- Item
Argument Parseable - An (individual) argument that can appear in a netdoc
- Item
Object Parseable - A possibly-optional Object value that can appear in netdoc
- Item
Value Parseable - An item (value) that can appear in a netdoc
- Netdoc
Parseable - A document or section that can be parsed
- Signature
Item Parseable - A signature item that can appear in a netdoc
- Stop
Predicate - Raw predicate, usually a closure, that can appear within
StopAt
. - StrExt
- Extension trait adding a method to
str
Functions§
- check_
validity_ time - Utility function to check that a time is within a validity period
- parse_
netdoc - Parse a network document - toplevel entrypoint
- parse_
netdoc_ multiple - Parse a network document - toplevel entrypoint