UNPKG

qasm-ts

Version:

QASM, the low-level programming language for quantum circuit specification, implemented in TypeScript.

275 lines (274 loc) 11.7 kB
"use strict"; /** * Error classes for QASM parsing and validation * * This module provides specific error types for different parsing failures, * enabling precise error handling and debugging. Each error includes contextual * information about where the error occurred in the source code. * * @module Error Handling */ 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.BadQuantumInstructionError = exports.BadLoopError = exports.BadSubroutineError = exports.BadExpressionError = exports.BadClassicalTypeError = exports.BadStringLiteralError = exports.UnsupportedOpenQASMVersionError = exports.MissingBraceError = exports.MissingSemicolonError = exports.BadParameterError = exports.BadEqualsError = exports.BadGateError = exports.BadMeasurementError = exports.BadBarrierError = exports.BadConditionalError = exports.BadQregError = exports.BadCregError = exports.BadIncludeError = exports.BadArgumentError = void 0; /** Class representing a bad argument exception. */ var BadArgumentError = /** @class */ (function (_super) { __extends(BadArgumentError, _super); function BadArgumentError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadArgumentError.name; return _this; } return BadArgumentError; }(Error)); exports.BadArgumentError = BadArgumentError; /** Class representing a bad include statement */ var BadIncludeError = /** @class */ (function (_super) { __extends(BadIncludeError, _super); function BadIncludeError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadIncludeError.name; return _this; } return BadIncludeError; }(Error)); exports.BadIncludeError = BadIncludeError; /** Class representing a bad quantum register exception. */ var BadQregError = /** @class */ (function (_super) { __extends(BadQregError, _super); function BadQregError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadQregError.name; return _this; } return BadQregError; }(Error)); exports.BadQregError = BadQregError; /** Class representing a bad equality exception. */ var BadEqualsError = /** @class */ (function (_super) { __extends(BadEqualsError, _super); function BadEqualsError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadEqualsError.name; return _this; } return BadEqualsError; }(Error)); exports.BadEqualsError = BadEqualsError; /** Class representing a bad classical register exception. */ var BadCregError = /** @class */ (function (_super) { __extends(BadCregError, _super); function BadCregError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadCregError.name; return _this; } return BadCregError; }(Error)); exports.BadCregError = BadCregError; /** Class representing a bad conditional exception. */ var BadConditionalError = /** @class */ (function (_super) { __extends(BadConditionalError, _super); function BadConditionalError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadConditionalError.name; return _this; } return BadConditionalError; }(Error)); exports.BadConditionalError = BadConditionalError; /** Class representing a bad barrier exception. */ var BadBarrierError = /** @class */ (function (_super) { __extends(BadBarrierError, _super); function BadBarrierError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadBarrierError.name; return _this; } return BadBarrierError; }(Error)); exports.BadBarrierError = BadBarrierError; /** Class representing a bad measurement exception. */ var BadMeasurementError = /** @class */ (function (_super) { __extends(BadMeasurementError, _super); function BadMeasurementError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadMeasurementError.name; return _this; } return BadMeasurementError; }(Error)); exports.BadMeasurementError = BadMeasurementError; /** Class representing a bad gate exception. */ var BadGateError = /** @class */ (function (_super) { __extends(BadGateError, _super); function BadGateError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadGateError.name; return _this; } return BadGateError; }(Error)); exports.BadGateError = BadGateError; /** Class representing a bad parameter exception. */ var BadParameterError = /** @class */ (function (_super) { __extends(BadParameterError, _super); function BadParameterError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadParameterError.name; return _this; } return BadParameterError; }(Error)); exports.BadParameterError = BadParameterError; /** Class representing a missing semicolon exception. */ var MissingSemicolonError = /** @class */ (function (_super) { __extends(MissingSemicolonError, _super); function MissingSemicolonError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = MissingSemicolonError.name; return _this; } return MissingSemicolonError; }(Error)); exports.MissingSemicolonError = MissingSemicolonError; /** Class representing a missing opening or closing parenthesis, bracket, or curly brakcet. */ var MissingBraceError = /** @class */ (function (_super) { __extends(MissingBraceError, _super); function MissingBraceError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = MissingSemicolonError.name; return _this; } return MissingBraceError; }(Error)); exports.MissingBraceError = MissingBraceError; /** Class representing an unsupported OpenQASM version exception. */ var UnsupportedOpenQASMVersionError = /** @class */ (function (_super) { __extends(UnsupportedOpenQASMVersionError, _super); function UnsupportedOpenQASMVersionError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = UnsupportedOpenQASMVersionError.name; return _this; } return UnsupportedOpenQASMVersionError; }(Error)); exports.UnsupportedOpenQASMVersionError = UnsupportedOpenQASMVersionError; /** Class representing an error parsing an expected string literal. */ var BadStringLiteralError = /** @class */ (function (_super) { __extends(BadStringLiteralError, _super); function BadStringLiteralError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadStringLiteralError.name; return _this; } return BadStringLiteralError; }(Error)); exports.BadStringLiteralError = BadStringLiteralError; /** Class representing an error parsing scalar types. */ var BadClassicalTypeError = /** @class */ (function (_super) { __extends(BadClassicalTypeError, _super); function BadClassicalTypeError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadClassicalTypeError.name; return _this; } return BadClassicalTypeError; }(Error)); exports.BadClassicalTypeError = BadClassicalTypeError; /** Class representing an error parsing an expression. */ var BadExpressionError = /** @class */ (function (_super) { __extends(BadExpressionError, _super); function BadExpressionError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadExpressionError.name; return _this; } return BadExpressionError; }(Error)); exports.BadExpressionError = BadExpressionError; /** Class representing an error in defining or calling a custom subroutine. */ var BadSubroutineError = /** @class */ (function (_super) { __extends(BadSubroutineError, _super); function BadSubroutineError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadSubroutineError.name; return _this; } return BadSubroutineError; }(Error)); exports.BadSubroutineError = BadSubroutineError; /** Class representing a bad loop statement declaration. */ var BadLoopError = /** @class */ (function (_super) { __extends(BadLoopError, _super); function BadLoopError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadLoopError.name; return _this; } return BadLoopError; }(Error)); exports.BadLoopError = BadLoopError; /** Class representing a bad quantum instruction. */ var BadQuantumInstructionError = /** @class */ (function (_super) { __extends(BadQuantumInstructionError, _super); function BadQuantumInstructionError(message) { var _newTarget = this.constructor; var _this = _super.call(this, message) || this; Object.setPrototypeOf(_this, _newTarget.prototype); _this.name = BadQuantumInstructionError.name; return _this; } return BadQuantumInstructionError; }(Error)); exports.BadQuantumInstructionError = BadQuantumInstructionError;