Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

Overview

qasmfmt uses a pipeline architecture inspired by rustfmt:

Source Code
    ↓
┌─────────────┐
│   Parser    │  ← oq3_syntax
└─────────────┘
    ↓
┌─────────────┐
│     AST     │
└─────────────┘
    ↓
┌─────────────┐
│  IR (Doc)   │  ← Intermediate Representation
└─────────────┘
    ↓
┌─────────────┐
│   Printer   │  ← Pretty Printer
└─────────────┘
    ↓
Formatted Code

Modules

ModuleDescription
configConfiguration handling
errorError types
irIntermediate representation (Doc)
printerPretty printer
formatAST to IR conversion
commentComment extraction

IR (Doc)

The intermediate representation is based on Wadler’s “A prettier printer”:

#![allow(unused)]
fn main() {
enum Doc {
    Nil,
    Text(String),
    Hardline,
    Softline,
    Concat(Vec<Doc>),
    Indent(Box<Doc>),
    Group(Box<Doc>),
}
}

Dependencies

  • oq3_syntax - OpenQASM 3.0 parser
  • serde - Serialization
  • thiserror - Error handling