Expand description
A pest-based parser and typed AST for the deq (.deq)
quantum error correction file format.
Most users need only the typed, roundtrip-fidelity API in ast:
ast::DeqFile implements FromStr with
ParseError, so input.parse::<DeqFile>() is the intended entry point.
use deqagram::ast::DeqFile;
let src = "CODE Rep [[3,1,1]] {\n LOGICAL X0*X1*X2 Z0\n STABILIZER Z0*Z1 Z1*Z2\n}\n";
let file: DeqFile = src.parse().unwrap();
assert_eq!(file.definitions.len(), 1);
// Round-trips: displaying then re-parsing yields an equal AST.
assert_eq!(file, file.to_string().parse().unwrap());DeqParser and the generated Rule enum are also public, as a
deliberate lower-level escape hatch for consumers that want to walk pest’s
raw concrete parse tree (Pairs/Tokens) directly rather than the typed
AST. This mirrors pest’s own design and is not incidental:
- pest’s parsing entry point is
Parser::parse(Rule, &str) -> Result<Pairs, Error<Rule>>, soRuleis the handle every pest consumer uses to name a start rule and to inspect pairs (see the pest book’s Parser API chapter, https://pest.rs/book/parser_api.html). #[derive(Parser)]generates theRuleenum with the same visibility as the parser struct (see thepest_derivedocs, https://docs.rs/pest_derive). ExposingDeqParsertherefore necessarily exposesRule; they are coupled by pest’s API, so a public parser can only be offered together with a publicRule.
Two semver consequences follow, and are accepted for the low-level access:
Rule mirrors the grammar’s rule names, so renaming or removing a grammar
rule is a breaking change; and ParseError’s pest-typed conversions
(From<pest::error::Error<Rule>> and ParseError::into_inner) tie the
public API to pest’s major version. Callers who only use the typed AST are
insulated from both.
Modules§
- ast
- Typed AST for the DEQ file format, mirroring deqagram’s Python dataclasses.
- decorators
- Decorator attachment: an opt-in transform that folds standalone body decorators onto the statement that follows them, producing a fully-attached tree.
- imports
- IMPORT resolution: an opt-in transform that flattens a file’s
IMPORTstatements by parsing the referenced files and merging their definitions.
Structs§
- DeqParser
- The pest parser for the
.deqgrammar. - Parse
Error - An error produced while parsing a
.deqsource. - Span
- A byte-offset range into the original
.deqsource (start..end). - Spanned
- An AST node paired with the source
Spanit was parsed from.