Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions crates/stim-parser/src/ast/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::sync::Arc;

use crate::ast::shared::{AnnotationOp, Axis, GateOp, MeasureOp, MppOp, NoiseOp, Tag};
use crate::ast::shared::{AnnotationOp, Axis, GateOp, MeasureOp, MppOp, NoiseOp};
use crate::diagnostics::{LineMap, Span};

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -51,12 +51,13 @@ pub enum ExtendedInstruction {
span: Span,
},
MPad {
tags: Vec<Tag>,
tag: String,
prob: Option<f64>,
bits: Vec<bool>,
span: Span,
},
Repeat {
tag: String,
count: u64,
body: Vec<ExtendedInstruction>,
span: Span,
Expand Down Expand Up @@ -167,13 +168,14 @@ mod tests {
fn measurement_count_scales_with_repeat() {
let m = ExtendedInstruction::Measure(MeasureOp {
name: MeasureName::M,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![0, 1],
span: span(),
});
let prog = ExtendedProgram {
instructions: vec![ExtendedInstruction::Repeat {
tag: String::new(),
count: 3,
body: vec![m],
span: span(),
Expand All @@ -190,14 +192,14 @@ mod tests {
instructions: vec![
ExtendedInstruction::Gate(GateOp {
name: GateName::H,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![Target::Qubit(0), Target::Qubit(4)],
span: span(),
}),
ExtendedInstruction::Measure(MeasureOp {
name: MeasureName::M,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![2],
span: span(),
Expand All @@ -212,10 +214,11 @@ mod tests {
fn num_qubits_recurses_into_repeat() {
let prog = ExtendedProgram {
instructions: vec![ExtendedInstruction::Repeat {
tag: String::new(),
count: 3,
body: vec![ExtendedInstruction::Measure(MeasureOp {
name: MeasureName::M,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![7],
span: span(),
Expand All @@ -241,7 +244,7 @@ mod tests {
fn gate_op_is_shared_with_vanilla() {
let _ = ExtendedInstruction::Gate(GateOp {
name: GateName::H,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![],
span: span(),
Expand Down
28 changes: 5 additions & 23 deletions crates/stim-parser/src/ast/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ pub struct PauliFactor {
pub qubit: usize,
}

#[derive(Debug, Clone, PartialEq)]
pub struct Tag {
pub name: String,
pub params: Vec<TagParam>,
}

#[derive(Debug, Clone, PartialEq)]
pub enum TagParam {
Positional(f64),
/// A `key=value` tag parameter. `had_pi` records whether the value was
/// written as a `<n>[*]pi` (or bare `pi`) expression — rotation/U3 tags
/// require it (half-turn convention), and the printer re-emits `*pi`.
Named {
key: String,
value: f64,
had_pi: bool,
},
}

/// The rotation axis for an extended-dialect `R_X` / `R_Y` / `R_Z` rotation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Axis {
Expand All @@ -99,7 +80,7 @@ pub enum Axis {
#[derive(Debug, Clone, PartialEq)]
pub struct GateOp {
pub name: GateName,
pub tags: Vec<Tag>,
pub tag: String,
pub args: Vec<f64>,
pub targets: Vec<Target>,
pub span: Span,
Expand All @@ -108,7 +89,7 @@ pub struct GateOp {
#[derive(Debug, Clone, PartialEq)]
pub struct NoiseOp {
pub name: NoiseName,
pub tags: Vec<Tag>,
pub tag: String,
pub args: Vec<f64>,
pub targets: Vec<usize>,
pub span: Span,
Expand All @@ -117,7 +98,7 @@ pub struct NoiseOp {
#[derive(Debug, Clone, PartialEq)]
pub struct MeasureOp {
pub name: MeasureName,
pub tags: Vec<Tag>,
pub tag: String,
pub args: Vec<f64>,
pub targets: Vec<usize>,
pub span: Span,
Expand All @@ -126,14 +107,15 @@ pub struct MeasureOp {
#[derive(Debug, Clone, PartialEq)]
pub struct AnnotationOp {
pub kind: AnnotationKind,
pub tag: String,
pub args: Vec<f64>,
pub targets: Vec<usize>,
pub span: Span,
}

#[derive(Debug, Clone, PartialEq)]
pub struct MppOp {
pub tags: Vec<Tag>,
pub tag: String,
pub args: Vec<f64>,
pub products: Vec<Vec<PauliFactor>>,
pub span: Span,
Expand Down
13 changes: 7 additions & 6 deletions crates/stim-parser/src/ast/vanilla.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-FileCopyrightText: 2026 The PPVM Authors
// SPDX-License-Identifier: Apache-2.0

//! Vanilla Stim AST. Tags are preserved verbatim; the parser does not
//! resolve the Stim dialect — that is the consumer's responsibility.
//! Vanilla Stim AST. Tags are preserved as decoded opaque strings; the parser
//! does not resolve the Stim dialect.

use std::sync::Arc;

use crate::ast::shared::{AnnotationOp, GateOp, MeasureOp, MppOp, NoiseOp, Tag};
use crate::ast::shared::{AnnotationOp, GateOp, MeasureOp, MppOp, NoiseOp};
use crate::diagnostics::{LineMap, Span};

#[derive(Debug, Clone, PartialEq)]
Expand All @@ -17,12 +17,13 @@ pub enum Instruction {
Annotation(AnnotationOp),
Mpp(MppOp),
MPad {
tags: Vec<Tag>,
tag: String,
prob: Option<f64>,
bits: Vec<usize>,
span: Span,
},
Repeat {
tag: String,
count: u64,
body: Vec<Instruction>,
span: Span,
Expand Down Expand Up @@ -57,7 +58,7 @@ mod tests {
let p = Program {
instructions: vec![Instruction::Gate(GateOp {
name: GateName::H,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![],
span: Span::new(0, 1),
Expand All @@ -72,7 +73,7 @@ mod tests {
let g = || {
Instruction::Gate(GateOp {
name: GateName::H,
tags: vec![],
tag: String::new(),
args: vec![],
targets: vec![],
span: Span::new(0, 1),
Expand Down
2 changes: 1 addition & 1 deletion crates/stim-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn parse_extended(src: &str) -> Result<ExtendedProgram, Diagnostics> {
pub mod prelude {
pub use crate::ast::{
AnnotationOp, Axis, ExtendedInstruction, ExtendedProgram, GateOp, Instruction, MeasureOp,
MppOp, NoiseOp, PauliAxis, PauliFactor, Program, Tag, TagParam, Target,
MppOp, NoiseOp, PauliAxis, PauliFactor, Program, Target,
};
pub use crate::diagnostics::{
Diagnostic, DiagnosticSink, Diagnostics, Flow, LineMap, Severity, Span,
Expand Down
Loading
Loading