UNPKG

q-sharp-ts

Version:

A parser for Q# language features, implemented in TypeScript.

1,345 lines (1,344 loc) 45.1 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Mutable = exports.Import = exports.Borrow = exports.Use = exports.BitwiseXor = exports.BitwiseOr = exports.BitwiseNot = exports.BitwiseAnd = exports.Dummy = exports.Meq = exports.Peq = exports.Eq = exports.Pauli = exports.Unit = exports.Double = exports.Result = exports.BigInt = exports.Function = exports.Operation = exports.Struct = exports.Range = exports.SetParam = exports.Let = exports.Variable = exports.Right = exports.Left = exports.Not = exports.And = exports.More = exports.Less = exports.Or = exports.Qubit = exports.Expression = exports.Neq = exports.Leq = exports.Geq = exports.Str = exports.Exp = exports.Divide = exports.Times = exports.Plus = exports.Minus = exports.Condition = exports.Parameter = exports.Mod = exports.Bool = exports.Int = exports.Arr = exports.Id = exports.AstNode = void 0; exports.ResultType = exports.QubitType = exports.StringType = exports.BoolType = exports.DoubleType = exports.BigIntType = exports.IntType = exports.UnitType = exports.Message = exports.ApplyUnitary = exports.CZ = exports.Z = exports.Y = exports.X = exports.T = exports.SWAP = exports.S = exports.Rzz = exports.Rz = exports.Ryy = exports.Ry = exports.Rxx = exports.Rx = exports.RFrac = exports.ResetAll = exports.Reset = exports.R1Frac = exports.R1 = exports.R = exports.Measure = exports.M = exports.I = exports.H = exports.Ex = exports.CNOT = exports.CCNOT = exports.AND = exports.PossibleCompatibleScope = exports.OpenQASMCompatible = exports.Is = exports.Modifier = exports.Tuple = exports.Paulis = exports.Conjugation = exports.Return = exports.Fail = exports.Repeat = exports.While = exports.For = exports.Unwrap = void 0; exports.Controlled = exports.Adjoint = exports.Continue = exports.ApplyOperator = exports.Comment = exports.GetParam = exports.IndexedSet = exports.AstType = exports.FunctionType = exports.OperationType = exports.StructType = exports.TupleType = exports.ArrayType = exports.RangeType = exports.PauliType = void 0; var errors_js_1 = require("./errors.js"); var token_js_1 = require("./token.js"); /** Base class representing a basic AST node. */ var AstNode = /** @class */ (function () { function AstNode() { } return AstNode; }()); exports.AstNode = AstNode; /** Base class representing a type. */ var AstType = /** @class */ (function (_super) { __extends(AstType, _super); function AstType() { return _super !== null && _super.apply(this, arguments) || this; } return AstType; }(AstNode)); exports.AstType = AstType; /** Base class representing an OpenQASM compatible operation. */ var OpenQASMCompatible = /** @class */ (function (_super) { __extends(OpenQASMCompatible, _super); function OpenQASMCompatible() { return _super !== null && _super.apply(this, arguments) || this; } return OpenQASMCompatible; }(AstNode)); exports.OpenQASMCompatible = OpenQASMCompatible; /** Base class representing a scope that may be composed of OpenQASM compatible operations. */ var PossibleCompatibleScope = /** @class */ (function (_super) { __extends(PossibleCompatibleScope, _super); function PossibleCompatibleScope() { return _super !== null && _super.apply(this, arguments) || this; } return PossibleCompatibleScope; }(AstNode)); exports.PossibleCompatibleScope = PossibleCompatibleScope; /** Class representing an OpenQASM compatible AND operation. */ var AND = /** @class */ (function (_super) { __extends(AND, _super); function AND() { return _super.call(this) || this; } return AND; }(OpenQASMCompatible)); exports.AND = AND; /** Class representing an OpenQASM compatible CCNOT operation. */ var CCNOT = /** @class */ (function (_super) { __extends(CCNOT, _super); function CCNOT(first_control, second_control, target) { var _this = _super.call(this) || this; _this.first_control = first_control; _this.second_control = second_control; _this.target = target; return _this; } return CCNOT; }(OpenQASMCompatible)); exports.CCNOT = CCNOT; /** Class representing an OpenQASM compatible CNOT operation. */ var CNOT = /** @class */ (function (_super) { __extends(CNOT, _super); function CNOT(control, target) { var _this = _super.call(this) || this; _this.control = control; _this.target = target; return _this; } return CNOT; }(OpenQASMCompatible)); exports.CNOT = CNOT; /** Class representing an OpenQASM compatible CZ operation. */ var CZ = /** @class */ (function (_super) { __extends(CZ, _super); function CZ(control, target) { var _this = _super.call(this) || this; _this.control = control; _this.target = target; return _this; } return CZ; }(OpenQASMCompatible)); exports.CZ = CZ; /** Class representing an Exp operation. */ var Ex = /** @class */ (function (_super) { __extends(Ex, _super); function Ex() { return _super.call(this) || this; } return Ex; }(AstNode)); exports.Ex = Ex; /** Class representing an OpenQASM compatible H operation. */ var H = /** @class */ (function (_super) { __extends(H, _super); function H(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return H; }(OpenQASMCompatible)); exports.H = H; /** Class representing an OpenQASM compatible I operation. */ var I = /** @class */ (function (_super) { __extends(I, _super); function I(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return I; }(OpenQASMCompatible)); exports.I = I; /** Class representing an OpenQASM compatible M operation. */ var M = /** @class */ (function (_super) { __extends(M, _super); function M(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return M; }(OpenQASMCompatible)); exports.M = M; /** Class representing an OpenQASM compatible Measure operation. */ var Measure = /** @class */ (function (_super) { __extends(Measure, _super); function Measure(basis, qubits) { var _this = _super.call(this) || this; _this.basis = basis; _this.qubits = qubits; return _this; } return Measure; }(OpenQASMCompatible)); exports.Measure = Measure; /** Class representing an OpenQASM compatible R operation. */ var R = /** @class */ (function (_super) { __extends(R, _super); function R(pauli_axis, rads, qubit) { var _this = _super.call(this) || this; _this.pauli_axis = pauli_axis; _this.rads = rads; _this.qubit = qubit; return _this; } return R; }(OpenQASMCompatible)); exports.R = R; /** Class representing an R1 operation. */ var R1 = /** @class */ (function (_super) { __extends(R1, _super); function R1(rads, qubit) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit = qubit; return _this; } return R1; }(OpenQASMCompatible)); exports.R1 = R1; /** Class representing an OpenQASM compatible R1Frac operation. */ var R1Frac = /** @class */ (function (_super) { __extends(R1Frac, _super); function R1Frac(numerator, power, qubit) { var _this = _super.call(this) || this; _this.numerator = numerator; _this.power = power; _this.qubit = qubit; return _this; } return R1Frac; }(OpenQASMCompatible)); exports.R1Frac = R1Frac; /** Class representing an OpenQASM compatible Reset operation. */ var Reset = /** @class */ (function (_super) { __extends(Reset, _super); function Reset(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return Reset; }(OpenQASMCompatible)); exports.Reset = Reset; /** Class representing an OpenQASM compatible ResetAll operation. */ var ResetAll = /** @class */ (function (_super) { __extends(ResetAll, _super); function ResetAll(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return ResetAll; }(OpenQASMCompatible)); exports.ResetAll = ResetAll; /** Class representing an OpenQASM compatible RFrac operation. */ var RFrac = /** @class */ (function (_super) { __extends(RFrac, _super); function RFrac(pauli, numerator, power, qubit) { var _this = _super.call(this) || this; _this.pauli = pauli; _this.numerator = numerator; _this.power = power; _this.qubit = qubit; return _this; } return RFrac; }(OpenQASMCompatible)); exports.RFrac = RFrac; /** Class representing an OpenQASM compatible Rx operation. */ var Rx = /** @class */ (function (_super) { __extends(Rx, _super); function Rx(rads, qubit) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit = qubit; return _this; } return Rx; }(OpenQASMCompatible)); exports.Rx = Rx; /** Class representing an OpenQASM compatible Rxx operation. */ var Rxx = /** @class */ (function (_super) { __extends(Rxx, _super); function Rxx(rads, qubit0, qubit1) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit0 = qubit0; _this.qubit1 = qubit1; return _this; } return Rxx; }(OpenQASMCompatible)); exports.Rxx = Rxx; /** Class representing an OpenQASM compatible Ry operation. */ var Ry = /** @class */ (function (_super) { __extends(Ry, _super); function Ry(rads, qubit) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit = qubit; return _this; } return Ry; }(OpenQASMCompatible)); exports.Ry = Ry; /** Class representing an OpenQASM compatible Ryy operation. */ var Ryy = /** @class */ (function (_super) { __extends(Ryy, _super); function Ryy(rads, qubit0, qubit1) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit0 = qubit0; _this.qubit1 = qubit1; return _this; } return Ryy; }(OpenQASMCompatible)); exports.Ryy = Ryy; /** Class representing an OpenQASM compatible Rz operation. */ var Rz = /** @class */ (function (_super) { __extends(Rz, _super); function Rz(rads, qubit) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit = qubit; return _this; } return Rz; }(OpenQASMCompatible)); exports.Rz = Rz; /** Class representing an OpenQASM compatible Rzz operation. */ var Rzz = /** @class */ (function (_super) { __extends(Rzz, _super); function Rzz(rads, qubit0, qubit1) { var _this = _super.call(this) || this; _this.rads = rads; _this.qubit0 = qubit0; _this.qubit1 = qubit1; return _this; } return Rzz; }(OpenQASMCompatible)); exports.Rzz = Rzz; /** Class representing an OpenQASM compatible S operation. */ var S = /** @class */ (function (_super) { __extends(S, _super); function S(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return S; }(OpenQASMCompatible)); exports.S = S; /** Class representing an OpenQASM compatible SWAP operation. */ var SWAP = /** @class */ (function (_super) { __extends(SWAP, _super); function SWAP(qubit0, qubit1) { var _this = _super.call(this) || this; _this.qubit0 = qubit0; _this.qubit1 = qubit1; return _this; } return SWAP; }(OpenQASMCompatible)); exports.SWAP = SWAP; /** Class representing an OpenQASM compatible T operation. */ var T = /** @class */ (function (_super) { __extends(T, _super); function T(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return T; }(OpenQASMCompatible)); exports.T = T; /** Class representing an OpenQASM compatible X operation. */ var X = /** @class */ (function (_super) { __extends(X, _super); function X(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return X; }(OpenQASMCompatible)); exports.X = X; /** Class representing an OpenQASM compatible Y operation. */ var Y = /** @class */ (function (_super) { __extends(Y, _super); function Y(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return Y; }(OpenQASMCompatible)); exports.Y = Y; /** Class representing an OpenQASM compatible Z operation. */ var Z = /** @class */ (function (_super) { __extends(Z, _super); function Z(target) { var _this = _super.call(this) || this; _this.target = target; return _this; } return Z; }(OpenQASMCompatible)); exports.Z = Z; /** Class representing an OpenQASM compatible ApplyUnitary operation. */ var ApplyUnitary = /** @class */ (function (_super) { __extends(ApplyUnitary, _super); function ApplyUnitary(unitary, qubits) { var _this = _super.call(this) || this; _this.unitary = unitary; _this.qubits = qubits; return _this; } return ApplyUnitary; }(AstNode)); exports.ApplyUnitary = ApplyUnitary; /** Class representing an OpenQASM compatible Meassage operation. */ var Message = /** @class */ (function (_super) { __extends(Message, _super); function Message() { return _super.call(this) || this; } return Message; }(AstNode)); exports.Message = Message; /** Class representing a use statement. */ var Use = /** @class */ (function (_super) { __extends(Use, _super); function Use(name, qubits) { var _this = _super.call(this) || this; _this.name = name; _this.qubits = qubits; return _this; } return Use; }(OpenQASMCompatible)); exports.Use = Use; /** Class representing a borrow statement. */ var Borrow = /** @class */ (function (_super) { __extends(Borrow, _super); function Borrow(name, qubits) { var _this = _super.call(this) || this; _this.name = name; _this.qubits = qubits; return _this; } return Borrow; }(AstNode)); exports.Borrow = Borrow; /** Class representing an import. */ var Import = /** @class */ (function (_super) { __extends(Import, _super); function Import(val) { var _this = _super.call(this) || this; _this.val = val; return _this; } return Import; }(AstNode)); exports.Import = Import; /** Base class representing a basic parameter. */ var Parameter = /** @class */ (function (_super) { __extends(Parameter, _super); function Parameter(repr) { var _this = _super.call(this) || this; _this.repr = repr; return _this; } return Parameter; }(AstNode)); exports.Parameter = Parameter; /** Class representing an identifier. */ var Id = /** @class */ (function (_super) { __extends(Id, _super); function Id(id) { var _this = _super.call(this, id) || this; _this.id = id; return _this; } return Id; }(Parameter)); exports.Id = Id; /** Class representing an array. */ var Arr = /** @class */ (function (_super) { __extends(Arr, _super); function Arr(vals, size) { var _this = this; var isRange = (!((vals.length == 1) && ((vals[0] instanceof GetParam) || (vals[0] instanceof IndexedSet)))); var repr = ''; if (isRange) { repr = '['; } for (var _i = 0, vals_1 = vals; _i < vals_1.length; _i++) { var param = vals_1[_i]; repr += "".concat(param.repr, ","); } if (isRange) { repr += ']'; } _this = _super.call(this, repr) || this; _this.vals = vals; _this.size = size; return _this; } return Arr; }(Parameter)); exports.Arr = Arr; /** Class representing a tuple. */ var Tuple = /** @class */ (function (_super) { __extends(Tuple, _super); function Tuple(vals, size) { var _this = this; var repr = '('; for (var _i = 0, vals_2 = vals; _i < vals_2.length; _i++) { var param = vals_2[_i]; repr += "".concat(param.repr, ","); } repr += ')'; _this = _super.call(this, repr) || this; _this.vals = vals; _this.size = size; return _this; } return Tuple; }(Parameter)); exports.Tuple = Tuple; /** Class representing a struct. */ var Struct = /** @class */ (function (_super) { __extends(Struct, _super); function Struct(vals, names) { var _this = this; var repr = '{'; for (var i = 0; i < vals.length; i++) { repr += "".concat(names[i], ": ").concat(vals[i].repr, ","); } repr += '}'; _this = _super.call(this, repr) || this; _this.vals = vals; _this.names = names; return _this; } return Struct; }(Parameter)); exports.Struct = Struct; /** Class representing a function. */ var Function = /** @class */ (function (_super) { __extends(Function, _super); function Function(name, nodes, params, returnType) { var _this = _super.call(this) || this; _this.name = name; _this.nodes = nodes; _this.params = params; _this.returnType = returnType; return _this; } return Function; }(PossibleCompatibleScope)); exports.Function = Function; /** Operation modifiers. */ var Modifier; (function (Modifier) { Modifier[Modifier["Adjoint"] = 0] = "Adjoint"; Modifier[Modifier["Controlled"] = 1] = "Controlled"; })(Modifier || (exports.Modifier = Modifier = {})); /** Class representing a operator modifier. */ var Adjoint = /** @class */ (function (_super) { __extends(Adjoint, _super); function Adjoint() { return _super !== null && _super.apply(this, arguments) || this; } return Adjoint; }(AstNode)); exports.Adjoint = Adjoint; /** Class representing a operator modifier. */ var Controlled = /** @class */ (function (_super) { __extends(Controlled, _super); function Controlled() { return _super !== null && _super.apply(this, arguments) || this; } return Controlled; }(AstNode)); exports.Controlled = Controlled; /** Class representing an operation. */ var Operation = /** @class */ (function (_super) { __extends(Operation, _super); function Operation(name, nodes, params, modifiers, returnType) { var _this = _super.call(this) || this; _this.name = name; _this.nodes = nodes; _this.params = params; _this.modifiers = modifiers; _this.returnType = returnType; return _this; } return Operation; }(PossibleCompatibleScope)); exports.Operation = Operation; /** Class representing a float. */ var Double = /** @class */ (function (_super) { __extends(Double, _super); function Double(val) { var _this = this; if (!(val instanceof Expression)) { _this = _super.call(this, val.toString()) || this; } else { _this = _super.call(this, val.repr) || this; } _this.val = val; return _this; } return Double; }(Parameter)); exports.Double = Double; /** Class representing an integer. */ var BigInt = /** @class */ (function (_super) { __extends(BigInt, _super); function BigInt(val) { var _this = this; if (!(val instanceof Expression)) { _this = _super.call(this, val.toString()) || this; } else { _this = _super.call(this, val.repr) || this; } _this.val = val; return _this; } return BigInt; }(Parameter)); exports.BigInt = BigInt; /** Class representing a unit. */ var Unit = /** @class */ (function (_super) { __extends(Unit, _super); function Unit() { return _super.call(this, '()') || this; } return Unit; }(Parameter)); exports.Unit = Unit; /** Class representing a string. */ var Str = /** @class */ (function (_super) { __extends(Str, _super); function Str(val) { var _this = _super.call(this, val) || this; _this.val = val; return _this; } return Str; }(Parameter)); exports.Str = Str; /** Class representing a comment. */ var Comment = /** @class */ (function (_super) { __extends(Comment, _super); function Comment(val) { var _this = _super.call(this) || this; _this.val = val; return _this; } return Comment; }(OpenQASMCompatible)); exports.Comment = Comment; /** Class representing an iterator. */ var For = /** @class */ (function (_super) { __extends(For, _super); function For(inside, vals, variable) { var _this = _super.call(this) || this; _this.variable = variable; _this.inside = inside; if (vals instanceof Array) { _this.vals = new Arr(vals, vals.length); } else { _this.vals = vals; } return _this; } return For; }(PossibleCompatibleScope)); exports.For = For; /** Class representing an iterator. */ var Repeat = /** @class */ (function (_super) { __extends(Repeat, _super); function Repeat(inside, until, fixup) { var _this = _super.call(this) || this; _this.inside = inside; _this.until = until; _this.fixup = fixup; return _this; } return Repeat; }(PossibleCompatibleScope)); exports.Repeat = Repeat; /** Class representing an iterator. */ var While = /** @class */ (function (_super) { __extends(While, _super); function While(inside, until) { var _this = _super.call(this) || this; _this.inside = inside; _this.until = until; return _this; } return While; }(PossibleCompatibleScope)); exports.While = While; /** Class representing a range. */ var Range = /** @class */ (function (_super) { __extends(Range, _super); function Range(lower, upper, step) { var _this = this; var repr = ''; if (step == undefined && !(lower instanceof Continue) && !(upper instanceof Continue)) { repr = "".concat(lower.repr, "..").concat(upper.repr); } else if (step != undefined && !(lower instanceof Continue) && !(upper instanceof Continue)) { repr = "".concat(lower.repr, "..").concat(step.repr, "..").concat(upper.repr); } else if ((lower instanceof Continue) && (step != undefined) && !(upper instanceof Continue)) { repr = "...".concat(step.repr, "..").concat(upper.repr); } else if (!(lower instanceof Continue) && (step != undefined) && (upper instanceof Continue)) { repr = "".concat(lower.repr, "..").concat(step.repr, "..."); } else if ((lower instanceof Continue) && (step == undefined) && !(upper instanceof Continue)) { repr = "...".concat(upper.repr); } else if (!(lower instanceof Continue) && (step == undefined) && (upper instanceof Continue)) { repr = "".concat(lower.repr, "..."); } else if ((lower instanceof Continue) && (upper instanceof Continue) && (step != undefined)) { repr = "...".concat(step.repr, "..."); } else if ((lower instanceof Continue) && (upper instanceof Continue) && (step == undefined)) { repr = '...1...'; } _this = _super.call(this, repr) || this; _this.lower = lower; _this.upper = upper; return _this; } return Range; }(Parameter)); exports.Range = Range; /** Class representing a continuation. */ var Continue = /** @class */ (function (_super) { __extends(Continue, _super); function Continue() { return _super.call(this) || this; } return Continue; }(AstNode)); exports.Continue = Continue; /** Class representing an integer. */ var Int = /** @class */ (function (_super) { __extends(Int, _super); function Int(val) { var _this = _super.call(this, val.toString()) || this; _this.val = val; return _this; } return Int; }(Parameter)); exports.Int = Int; /** Class representing a boolean. */ var Bool = /** @class */ (function (_super) { __extends(Bool, _super); function Bool(val) { var _this = _super.call(this, val.toString()) || this; _this.val = val; return _this; } return Bool; }(Parameter)); exports.Bool = Bool; /** Class representing a qubit. */ var Qubit = /** @class */ (function (_super) { __extends(Qubit, _super); function Qubit(name, length) { var _this = _super.call(this, name) || this; _this.name = name; if (typeof length !== 'undefined') { _this.length = length; } else { _this.length = new Int(1); } return _this; } return Qubit; }(Parameter)); exports.Qubit = Qubit; /** Class representing a result. */ var Result = /** @class */ (function (_super) { __extends(Result, _super); function Result(val) { var _this = _super.call(this, val.toString()) || this; _this.val = val; return _this; } return Result; }(Parameter)); exports.Result = Result; /** Class representing a Unit type. */ var UnitType = /** @class */ (function (_super) { __extends(UnitType, _super); function UnitType() { return _super !== null && _super.apply(this, arguments) || this; } return UnitType; }(AstType)); exports.UnitType = UnitType; /** Class representing an Int type. */ var IntType = /** @class */ (function (_super) { __extends(IntType, _super); function IntType() { return _super !== null && _super.apply(this, arguments) || this; } return IntType; }(AstType)); exports.IntType = IntType; /** Class representing a BigInt type. */ var BigIntType = /** @class */ (function (_super) { __extends(BigIntType, _super); function BigIntType() { return _super !== null && _super.apply(this, arguments) || this; } return BigIntType; }(AstType)); exports.BigIntType = BigIntType; /** Class representing a Double type. */ var DoubleType = /** @class */ (function (_super) { __extends(DoubleType, _super); function DoubleType() { return _super !== null && _super.apply(this, arguments) || this; } return DoubleType; }(AstType)); exports.DoubleType = DoubleType; /** Class representing a Bool type. */ var BoolType = /** @class */ (function (_super) { __extends(BoolType, _super); function BoolType() { return _super !== null && _super.apply(this, arguments) || this; } return BoolType; }(AstType)); exports.BoolType = BoolType; /** Class representing a String type. */ var StringType = /** @class */ (function (_super) { __extends(StringType, _super); function StringType() { return _super !== null && _super.apply(this, arguments) || this; } return StringType; }(AstType)); exports.StringType = StringType; /** Class representing a Qubit type. */ var QubitType = /** @class */ (function (_super) { __extends(QubitType, _super); function QubitType() { return _super !== null && _super.apply(this, arguments) || this; } return QubitType; }(AstType)); exports.QubitType = QubitType; /** Class representing a Result type. */ var ResultType = /** @class */ (function (_super) { __extends(ResultType, _super); function ResultType() { return _super !== null && _super.apply(this, arguments) || this; } return ResultType; }(AstType)); exports.ResultType = ResultType; /** Class representing a Pauli type. */ var PauliType = /** @class */ (function (_super) { __extends(PauliType, _super); function PauliType() { return _super !== null && _super.apply(this, arguments) || this; } return PauliType; }(AstType)); exports.PauliType = PauliType; /** Class representing a Range type. */ var RangeType = /** @class */ (function (_super) { __extends(RangeType, _super); function RangeType() { return _super !== null && _super.apply(this, arguments) || this; } return RangeType; }(AstType)); exports.RangeType = RangeType; /** Class representing an Array type. */ var ArrayType = /** @class */ (function (_super) { __extends(ArrayType, _super); function ArrayType() { return _super !== null && _super.apply(this, arguments) || this; } return ArrayType; }(AstType)); exports.ArrayType = ArrayType; /** Class representing a Tuple type. */ var TupleType = /** @class */ (function (_super) { __extends(TupleType, _super); function TupleType() { return _super !== null && _super.apply(this, arguments) || this; } return TupleType; }(AstType)); exports.TupleType = TupleType; /** Class representing a struct type. */ var StructType = /** @class */ (function (_super) { __extends(StructType, _super); function StructType() { return _super !== null && _super.apply(this, arguments) || this; } return StructType; }(AstType)); exports.StructType = StructType; /** Class representing an Operation type. */ var OperationType = /** @class */ (function (_super) { __extends(OperationType, _super); function OperationType() { return _super !== null && _super.apply(this, arguments) || this; } return OperationType; }(AstType)); exports.OperationType = OperationType; /** Class representing a Function type. */ var FunctionType = /** @class */ (function (_super) { __extends(FunctionType, _super); function FunctionType() { return _super !== null && _super.apply(this, arguments) || this; } return FunctionType; }(AstType)); exports.FunctionType = FunctionType; /** Pauli basis */ var Paulis; (function (Paulis) { Paulis[Paulis["PauliX"] = 0] = "PauliX"; Paulis[Paulis["PauliY"] = 1] = "PauliY"; Paulis[Paulis["PauliZ"] = 2] = "PauliZ"; Paulis[Paulis["PauliI"] = 3] = "PauliI"; })(Paulis || (exports.Paulis = Paulis = {})); /** Class representing a result. */ var Pauli = /** @class */ (function (_super) { __extends(Pauli, _super); function Pauli(val) { var _this = this; if (val == Paulis.PauliI) { _this = _super.call(this, 'PauliI') || this; } else if (val == Paulis.PauliX) { _this = _super.call(this, 'PauliX') || this; } else if (val == Paulis.PauliY) { _this = _super.call(this, 'PauliY') || this; } else if (val == Paulis.PauliZ) { _this = _super.call(this, 'PauliZ') || this; } else { throw errors_js_1.BadArgumentError; } _this.val = val; return _this; } return Pauli; }(Parameter)); exports.Pauli = Pauli; /** Class representing a variable. */ var Variable = /** @class */ (function (_super) { __extends(Variable, _super); function Variable(name) { var _this = _super.call(this, name) || this; _this.name = name; return _this; } return Variable; }(Parameter)); exports.Variable = Variable; /** Class representing a parameter assignment. */ var IndexedSet = /** @class */ (function (_super) { __extends(IndexedSet, _super); function IndexedSet(name, index, val) { var _this = _super.call(this) || this; _this.index = index; _this.name = name; _this.val = val; return _this; } return IndexedSet; }(AstNode)); exports.IndexedSet = IndexedSet; /** Class representing a parameter assignment. */ var SetParam = /** @class */ (function (_super) { __extends(SetParam, _super); function SetParam(instance, val) { var _this = _super.call(this) || this; _this.instance = instance; _this.val = val; return _this; } return SetParam; }(AstNode)); exports.SetParam = SetParam; /** Class representing a parameter reference. */ var GetParam = /** @class */ (function (_super) { __extends(GetParam, _super); function GetParam(instance, index) { var _this = _super.call(this, "".concat(instance, "[").concat(index.repr, "]")) || this; _this.instance = instance; _this.index = index; return _this; } return GetParam; }(Parameter)); exports.GetParam = GetParam; /** Class representing a condition. */ var Condition = /** @class */ (function (_super) { __extends(Condition, _super); function Condition(condition, ifClause, elseClause) { var _this = _super.call(this) || this; _this.condition = condition; _this.ifClause = ifClause; _this.elseClause = elseClause; return _this; } return Condition; }(PossibleCompatibleScope)); exports.Condition = Condition; /** Class representing exponential. */ var Exp = /** @class */ (function (_super) { __extends(Exp, _super); function Exp() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Ex)) || this; } return Exp; }(Parameter)); exports.Exp = Exp; /** Class representing minus. */ var Minus = /** @class */ (function (_super) { __extends(Minus, _super); function Minus() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Minus)) || this; } return Minus; }(Parameter)); exports.Minus = Minus; /** Class representing a union. */ var Or = /** @class */ (function (_super) { __extends(Or, _super); function Or() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Or)) || this; } return Or; }(Parameter)); exports.Or = Or; /** Class representing an intersection. */ var And = /** @class */ (function (_super) { __extends(And, _super); function And() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.And)) || this; } return And; }(Parameter)); exports.And = And; /** Class representing an inversion. */ var Not = /** @class */ (function (_super) { __extends(Not, _super); function Not() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Not)) || this; } return Not; }(Parameter)); exports.Not = Not; /** Class representing plus. */ var Plus = /** @class */ (function (_super) { __extends(Plus, _super); function Plus() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Plus)) || this; } return Plus; }(Parameter)); exports.Plus = Plus; /** Class representing times. */ var Times = /** @class */ (function (_super) { __extends(Times, _super); function Times() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Times)) || this; } return Times; }(Parameter)); exports.Times = Times; /** Class representing divide. */ var Divide = /** @class */ (function (_super) { __extends(Divide, _super); function Divide() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Divide)) || this; } return Divide; }(Parameter)); exports.Divide = Divide; /** Class representing less than. */ var Less = /** @class */ (function (_super) { __extends(Less, _super); function Less() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Less)) || this; } return Less; }(Parameter)); exports.Less = Less; /** Class representing bitwise or. */ var BitwiseOr = /** @class */ (function (_super) { __extends(BitwiseOr, _super); function BitwiseOr() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.BitwiseOr)) || this; } return BitwiseOr; }(Parameter)); exports.BitwiseOr = BitwiseOr; /** Class representing bitwise and. */ var BitwiseAnd = /** @class */ (function (_super) { __extends(BitwiseAnd, _super); function BitwiseAnd() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.BitwiseAnd)) || this; } return BitwiseAnd; }(Parameter)); exports.BitwiseAnd = BitwiseAnd; /** Class representing bitwise not. */ var BitwiseNot = /** @class */ (function (_super) { __extends(BitwiseNot, _super); function BitwiseNot() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.BitwiseNot)) || this; } return BitwiseNot; }(Parameter)); exports.BitwiseNot = BitwiseNot; /** Class representing bitwise xor. */ var BitwiseXor = /** @class */ (function (_super) { __extends(BitwiseXor, _super); function BitwiseXor() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.BitwiseXor)) || this; } return BitwiseXor; }(Parameter)); exports.BitwiseXor = BitwiseXor; /** Class representing greater than. */ var More = /** @class */ (function (_super) { __extends(More, _super); function More() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.More)) || this; } return More; }(Parameter)); exports.More = More; /** Class representing left angle bracket. */ var Left = /** @class */ (function (_super) { __extends(Left, _super); function Left() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Left)) || this; } return Left; }(Parameter)); exports.Left = Left; /** Class representing right angle bracket. */ var Right = /** @class */ (function (_super) { __extends(Right, _super); function Right() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Right)) || this; } return Right; }(Parameter)); exports.Right = Right; /** Class representing modulus. */ var Mod = /** @class */ (function (_super) { __extends(Mod, _super); function Mod() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Mod)) || this; } return Mod; }(Parameter)); exports.Mod = Mod; /** Class representing an unwrap. */ var Unwrap = /** @class */ (function (_super) { __extends(Unwrap, _super); function Unwrap() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Unwrap)) || this; } return Unwrap; }(Parameter)); exports.Unwrap = Unwrap; /** Class representing equality. */ var Eq = /** @class */ (function (_super) { __extends(Eq, _super); function Eq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Eq)) || this; } return Eq; }(Parameter)); exports.Eq = Eq; /** Class representing plus equals. */ var Peq = /** @class */ (function (_super) { __extends(Peq, _super); function Peq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Peq)) || this; } return Peq; }(Parameter)); exports.Peq = Peq; /** Class representing minus equals. */ var Meq = /** @class */ (function (_super) { __extends(Meq, _super); function Meq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Meq)) || this; } return Meq; }(Parameter)); exports.Meq = Meq; /** Class representing not equals. */ var Neq = /** @class */ (function (_super) { __extends(Neq, _super); function Neq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Neq)) || this; } return Neq; }(Parameter)); exports.Neq = Neq; /** Class representing dummy variable. */ var Dummy = /** @class */ (function (_super) { __extends(Dummy, _super); function Dummy() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Dummy)) || this; } return Dummy; }(Parameter)); exports.Dummy = Dummy; /** Class representing greater than or equal to. */ var Geq = /** @class */ (function (_super) { __extends(Geq, _super); function Geq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Geq)) || this; } return Geq; }(Parameter)); exports.Geq = Geq; /** Class representing less than or equal to. */ var Leq = /** @class */ (function (_super) { __extends(Leq, _super); function Leq() { return _super.call(this, (0, token_js_1.inverseParamLookup)(token_js_1.Token.Leq)) || this; } return Leq; }(Parameter)); exports.Leq = Leq; /** Class representing an is keyword. */ var Is = /** @class */ (function (_super) { __extends(Is, _super); function Is() { return _super !== null && _super.apply(this, arguments) || this; } return Is; }(AstNode)); exports.Is = Is; /** Class representing assignment. */ var Let = /** @class */ (function (_super) { __extends(Let, _super); function Let(expression, variable) { var _this = _super.call(this) || this; _this.expression = expression; _this.variable = variable; return _this; } return Let; }(AstNode)); exports.Let = Let; /** Class representing a conjugation. */ var Conjugation = /** @class */ (function (_super) { __extends(Conjugation, _super); function Conjugation(within, applies) { var _this = _super.call(this) || this; _this.within = within; _this.applies = applies; return _this; } return Conjugation; }(PossibleCompatibleScope)); exports.Conjugation = Conjugation; /** Class representing mutable assignment. */ var Mutable = /** @class */ (function (_super) { __extends(Mutable, _super); function Mutable(expression, variable) { var _this = _super.call(this) || this; _this.expression = expression; _this.variable = variable; return _this; } return Mutable; }(AstNode)); exports.Mutable = Mutable; /** Class representing expression. */ var Expression = /** @class */ (function (_super) { __extends(Expression, _super); function Expression(elements) { var _this = this; var repr = ''; for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { var elem = elements_1[_i]; repr += elem.repr; } _this = _super.call(this, repr) || this; _this.elements = elements; return _this; } return Expression; }(Parameter)); exports.Expression = Expression; /** A program termination. */ var Fail = /** @class */ (function (_super) { __extends(Fail, _super); function Fail(msg) { var _this = _super.call(this) || this; _this.msg = msg; return _this; } return Fail; }(AstNode)); exports.Fail = Fail; /** A return statement. */ var Return = /** @class */ (function (_super) { __extends(Return, _super); function Return(expr) { var _this = _super.call(this) || this; _this.expr = expr; return _this; } return Return; }(AstNode)); exports.Return = Return; /** Class representing an operator application. */ var ApplyOperator = /** @class */ (function (_super) { __extends(ApplyOperator, _super); // TODO: add modifiers function ApplyOperator(name, params, registers) { var _this = this; var paramRepr = ''; for (var _i = 0, params_1 = params; _i < params_1.length; _i++) { var p = params_1[_i]; for (var _a = 0, p_1 = p; _a < p_1.length; _a++) { var elem = p_1[_a]; paramRepr += elem.repr; } paramRepr += ', '; } if (registers != undefined) { var regRepr = ''; for (var _b = 0, registers_1 = registers; _b < registers_1.length; _b++) { var reg = registers_1[_b]; regRepr += reg.name; regRepr += ','; } _this = _super.call(this, "".concat(name, "(").concat(paramRepr, ") ").concat(regRepr)) || this; } else { _this = _super.call(this, "".concat(name, "(").concat(paramRepr, ")")) || this; } _this.name = name; _this.registers = registers; _this.params = params; return _this; } return ApplyOperator; }(Parameter)); exports.ApplyOperator = ApplyOperator;