Expand description
Fortification against sin. A new kind of parser for procedural macros.
This crate aims to be a (not-quite) drop-in replacement for
David Tolnay’s proc-macro2 and quote crates,
and an opinionated alternative to syn.
Opposing syn,
this crate is designed around the philosophy that malformed input
should be handled gracefully by procedural macros.
See our quote macro and the TokenQueue type
for stream-building operations.
See the Parser type for structural documentation on parsing.
The design of this crate is still in flux. Expect frequent breaking changes and temporary (🤞) API inconsistencies.
§Stable Features
complete— Enables the complete suite of parsing utilities.quote(enabled by default) — Enables quasi quoting.parse— Enables parsing.attributes— Provides support and utilities for parsing and handling Rust attributes.warnings— Enables emitting diagnostic warnings through theDiagnosticAPI.
§Unstable Features
Tread lightly. These features may require a nightly compiler, and enabling any of them in a crate’s dependencies explicitly voids all semver guarantees your crate may promise.
-
proc-macro2— Rewires this crate to build on top of theproc-macro2crate, instead of the default, officially supportedproc_macrocrate.You may use this to build testing infrastructure for your proc-macros, but are advised against enabling this in a library.
-
unstable-diagnostics-backend-stdlib— Enables the standard library’s experimentalproc_macro_diagnosticfeature for higher quality diagnostics. -
unstable-diagnostics-backend-format-json— Enables experimental support for custom diagnostics through passing JSON messages directly to cargo.
§MSRV
Note that while we don’t have an official policy with regards to our MSRV, expect it to be tied high for some time.
Modules§
- attributes
attributes - Provides utilities for parsing attributes.
Macros§
- for_
all_ punct_ seqs - Expands a macro with every distinct (supported) sequence of punctuation.
- punct_
decompose - Decomposes a larger token into a sequence of
chars. - punct_
pat parse - Transforms a sequence of punctuation (e.g.
&&or..=) into aPunctPat. - quote
quote - Lazy quasi-quoting for Rust source.
- verbatim
quote - Quotes a single token (either a literal, an identifier, or a lifetime) in exactly the format supplied.
Structs§
- Checkpoint
parse - A location in the stream of a
Parser. - Diagnostic
parse - The universal type used for parsing diagnostics.
- Dr
quote - The dollar doctor. Evaluates to
$. Useful for escaping. - Eos
parse - Matches the end of the stream.
- Expected
parse - Builds a diagnostic which represents some syntax which was expected.
- Parser
parse - A simple parser for Rust source which traverses
TokenTrees. - Parser
Pos parse - A reference to a position within the internal stream of a
Parser. - Punct
Pat parse - A pattern representing a sequence of
Puncts. - Spanned
- A simple wrapper which provides span information for any value.
- Token
Queue - General purpose buffer for token composition.
- Transcriber
quote - A lazily-evaluated sequence of quoted tokens (what
quoteevaluates to). - Verbatim
- A verbatim token. See the
verbatimmacro.
Enums§
- Diagnostic
Level parse - The severity level of a custom
Diagnostic. - Verbatim
Kind - What sort of token this
Verbatimrepresents.
Traits§
- Into
Tokens - Methods for converting by-value into
TokenQueue. - Parse
parse - A common interface for parsing values from a
Parser. - Pattern
parse - Performs simple pattern-matched parsing through a
Parserobject. - Push
Token - A marker trait indicating that this
IntoTokensimplementation executes in amortized constant time. - RefTo
Tokens - Marks a type as cheaply-clonable and suitable for
an automatic
&T: IntoTokensimplementation. - ToSpan
- Enables conversion between different span formats.
- Token
Tree Ext - A trait extending the behaviour of
TokenTrees.