qvnt_qasm/
ast.rs

1/// AST Nodes. These can pattern matched to evaluate the ast.
2///
3/// The nodes are representative of what operation should be done,
4/// please look at their documentation.
5#[derive(Debug, PartialEq, Clone)]
6pub enum AstNode<'t> {
7    /// Represents the initialization of a Quantum Register.
8    /// The String is the identifier, and the integer is the number of qubits.
9    QReg(&'t str, i32),
10    /// Represents the initialization of a Classical Register.
11    /// The String is the identifier, and the integer is the number of bits.
12    CReg(&'t str, i32),
13    /// Represents a barrier to a qubit / register
14    Barrier(Argument<'t>),
15    /// Represents reseting a qubit / register
16    Reset(Argument<'t>),
17    /// Representing measuremnt of a qubit/register to a bit/register
18    Measure(Argument<'t>, Argument<'t>),
19    /// Represents application of a gate
20    /// String is the name of the gate.
21    /// The first arguments is the qubits that the gates are being applied to
22    /// The second is the parameters (mathematical expressions).
23    /// Note the mathematic expressions are strings, and must be evaluated
24    ApplyGate(&'t str, Vec<Argument<'t>>, Vec<&'t str>),
25    /// Represents an opaque gate
26    /// String is the name of the gate.
27    /// The first arguments is the qubits that the gates are being applied to
28    /// The second is the parameters (mathematical expressions)
29    Opaque(&'t str, Vec<Argument<'t>>, Vec<&'t str>),
30    /// Represents the creation of a gate
31    /// String is the name of the gate
32    /// The first is the qubits it acts on,
33    /// The seconds is the ids of the params.
34    /// finally, a list of nodes, which the gate applies
35    Gate(&'t str, Vec<&'t str>, Vec<&'t str>, Vec<AstNode<'t>>),
36    /// Represents a conditional
37    /// String is classical register
38    /// i32 is the value to to check if equal.
39    /// If equal, AstNode is applied.
40    If(&'t str, i32, Box<AstNode<'t>>),
41}
42
43/// Representation of arguments to the ASTNodes.
44/// These are never top level, thus they have been
45/// left to a seperate enum.
46#[derive(Debug, PartialEq, Clone)]
47pub enum Argument<'t> {
48    /// Represents a single qubit / bit argument.
49    /// The string is the name of the register, and the integer is the index
50    Qubit(&'t str, i32),
51    /// Represents a register argument.
52    /// The string is the name of the register.
53    Register(&'t str),
54}