qasm-ts 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/docs-readme.md +13 -9
- package/docs/typedoc/index.html +4 -4
- package/package.json +2 -1
- package/readme.md +4 -3
- package/tsconfig.json +7 -2
- package/dist/errors.js +0 -274
- package/dist/lexer.js +0 -119
- package/dist/main.js +0 -131
- package/dist/parser.js +0 -124
- package/dist/qasm2/ast.js +0 -336
- package/dist/qasm2/lexer.js +0 -489
- package/dist/qasm2/parser.js +0 -659
- package/dist/qasm2/token.js +0 -160
- package/dist/qasm3/ast.js +0 -1081
- package/dist/qasm3/lexer.js +0 -673
- package/dist/qasm3/parser.js +0 -2083
- package/dist/qasm3/token.js +0 -425
- package/dist/version.js +0 -57
package/docs/docs-readme.md
CHANGED
|
@@ -193,16 +193,20 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
|
193
193
|
|
|
194
194
|
## How to Cite
|
|
195
195
|
|
|
196
|
-
If you are using QASM-TS for research we appreciate any citations. Please read and cite our
|
|
196
|
+
If you are using QASM-TS for research we appreciate any citations. Please read and cite our [paper](https://doi.org/10.21105/joss.08696) published with the Journal of Open Source Software.
|
|
197
197
|
|
|
198
198
|
```
|
|
199
|
-
@
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
@article{Kim[2025,
|
|
200
|
+
doi = {10.21105/joss.08696},
|
|
201
|
+
url = {https://doi.org/10.21105/joss.08696},
|
|
202
|
+
year = {2025},
|
|
203
|
+
publisher = {The Open Journal},
|
|
204
|
+
volume = {10},
|
|
205
|
+
number = {113},
|
|
206
|
+
pages = {8696},
|
|
207
|
+
author = {Kim[, Sean and Edwards[, Marcus},
|
|
208
|
+
title = {Enabling the Verification and Formalization of Hybrid Quantum-Classical Computing with OpenQASM 3.0 compatible QASM-TS 2.0},
|
|
209
|
+
journal = {Journal of Open Source Software}
|
|
207
210
|
}
|
|
211
|
+
|
|
208
212
|
```
|
package/docs/typedoc/index.html
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>qasm-ts - v2.
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>qasm-ts - v2.1.2</title><meta name="description" content="Documentation for qasm-ts"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><link rel="stylesheet" href="assets/custom.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="index.html" class="title">qasm-ts - v2.1.2</a><div id="tsd-toolbar-links"><a href="https://github.com/comp-phys-marc/qasm-ts">GitHub</a><a href="https://www.npmjs.com/package/qasm-ts">NPM</a></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>qasm-ts - v2.1.2</h1></div><div class="tsd-panel tsd-typography"><h1 id="qasm-typescript-documentation" class="tsd-anchor-link">QASM TypeScript Documentation<a href="#qasm-typescript-documentation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p>OpenQASM, the low-level programming language for quantum circuit specification, implemented in TypeScript.</p>
|
|
2
2
|
<p>QASM-TS 2.0 is an implementation of a compiler frontend for OpenQASM 2.0 and 3.0. It includes a lexer and a parser of the OpenQASM language. The source is parsed into an Intermediate Representation (IR): an Abstract Syntax Tree (AST) that captures program structure including control flow and data flow.</p>
|
|
3
3
|
<p>The package is aimed at enabling implementations of verification and validation software (such as semantic and static analyzers), compilers and more. These tools may be instrumental in the formalization of hybrid quantum-classical computing.</p>
|
|
4
4
|
<p>Language documentation is provided by IBM <a href="https://openqasm.com">here</a>.</p>
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
<p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:</p>
|
|
70
70
|
<p><code>http://www.apache.org/licenses/LICENSE-2.0</code></p>
|
|
71
71
|
<p>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.</p>
|
|
72
|
-
<h2 id="how-to-cite" class="tsd-anchor-link">How to Cite<a href="#how-to-cite" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>If you are using QASM-TS for research we appreciate any citations. Please read and cite our
|
|
73
|
-
<pre><code><span class="hl-1">@</span><span class="hl-4">
|
|
72
|
+
<h2 id="how-to-cite" class="tsd-anchor-link">How to Cite<a href="#how-to-cite" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>If you are using QASM-TS for research we appreciate any citations. Please read and cite our <a href="https://doi.org/10.21105/joss.08696">paper</a> published with the Journal of Open Source Software.</p>
|
|
73
|
+
<pre><code><span class="hl-1">@</span><span class="hl-4">article</span><span class="hl-1">{Kim</span><span class="hl-4">[</span><span class="hl-8">2025</span><span class="hl-4">,</span><br/><span class="hl-4"> doi </span><span class="hl-1">=</span><span class="hl-4"> {</span><span class="hl-8">10.21105</span><span class="hl-4">/joss.</span><span class="hl-8">08696</span><span class="hl-4">},</span><br/><span class="hl-4"> url </span><span class="hl-1">=</span><span class="hl-4"> {https:</span><span class="hl-7">//doi.org/10.21105/joss.08696},</span><br/><span class="hl-4"> year </span><span class="hl-1">=</span><span class="hl-4"> {</span><span class="hl-8">2025</span><span class="hl-4">},</span><br/><span class="hl-4"> publisher </span><span class="hl-1">=</span><span class="hl-4"> {The Open Journal},</span><br/><span class="hl-4"> volume </span><span class="hl-1">=</span><span class="hl-4"> {</span><span class="hl-8">10</span><span class="hl-4">},</span><br/><span class="hl-4"> number </span><span class="hl-1">=</span><span class="hl-4"> {</span><span class="hl-8">113</span><span class="hl-4">},</span><br/><span class="hl-4"> pages </span><span class="hl-1">=</span><span class="hl-4"> {</span><span class="hl-8">8696</span><span class="hl-4">},</span><br/><span class="hl-4"> author </span><span class="hl-1">=</span><span class="hl-4"> {Kim[, Sean and Edwards[, Marcus},</span><br/><span class="hl-4"> title </span><span class="hl-1">=</span><span class="hl-4"> {Enabling the Verification and Formalization of Hybrid Quantum-Classical Computing with OpenQASM </span><span class="hl-8">3.0</span><span class="hl-4"> compatible QASM-TS </span><span class="hl-8">2.0</span><span class="hl-4">},</span><br/><span class="hl-4"> journal </span><span class="hl-1">=</span><span class="hl-4"> {Journal of Open Source Software}</span><br/><span class="hl-4">}</span><br/><span class="hl-4"> </span>
|
|
74
74
|
</code><button>Copy</button></pre>
|
|
75
75
|
|
|
76
|
-
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#qasm-typescript-documentation"><span>QASM <wbr/>Type<wbr/>Script <wbr/>Documentation</span></a><ul><li><a href="#quick-start"><span>Quick <wbr/>Start</span></a></li><li><ul><li><a href="#installation"><span>Installation</span></a></li><li><a href="#basic-usage"><span>Basic <wbr/>Usage</span></a></li><li><a href="#working-with-the-ast"><span>Working with the <wbr/>AST</span></a></li></ul></li><li><a href="#example-io"><span>Example <wbr/>I/<wbr/>O</span></a></li><li><ul><li><a href="#input-alignmentqasm-source"><span>Input: alignment.qasm (source)</span></a></li><li><a href="#output-abstract-syntax-tree"><span>Output: <wbr/>Abstract <wbr/>Syntax <wbr/>Tree</span></a></li></ul></li><li><a href="#api-documentation-navigation"><span>API <wbr/>Documentation <wbr/>Navigation</span></a></li><li><ul><li><a href="#core-functions"><span>Core <wbr/>Functions</span></a></li><li><a href="#tokenization"><span>Tokenization</span></a></li><li><a href="#lexing"><span>Lexing</span></a></li><li><a href="#ast-structure"><span>AST <wbr/>Structure</span></a></li><li><a href="#parsing"><span>Parsing</span></a></li><li><a href="#utilities-and-internals"><span>Utilities and <wbr/>Internals</span></a></li></ul></li><li><a href="#new-in-version-200"><span>New <wbr/>In <wbr/>Version 2.0.0</span></a></li><li><a href="#source-code"><span>Source <wbr/>Code</span></a></li><li><a href="#references"><span>References</span></a></li><li><a href="#license"><span>License</span></a></li><li><a href="#how-to-cite"><span>How to <wbr/>Cite</span></a></li></ul></div></details></div><div class="site-menu"><nav id="tsd-sidebar-links" class="tsd-navigation"><a href="https://github.com/comp-phys-marc/qasm-ts" class="tsd-nav-link">GitHub</a><a href="https://www.npmjs.com/package/qasm-ts" class="tsd-nav-link">NPM</a></nav><nav class="tsd-navigation"><a href="modules.html">qasm-ts - v2.
|
|
76
|
+
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#qasm-typescript-documentation"><span>QASM <wbr/>Type<wbr/>Script <wbr/>Documentation</span></a><ul><li><a href="#quick-start"><span>Quick <wbr/>Start</span></a></li><li><ul><li><a href="#installation"><span>Installation</span></a></li><li><a href="#basic-usage"><span>Basic <wbr/>Usage</span></a></li><li><a href="#working-with-the-ast"><span>Working with the <wbr/>AST</span></a></li></ul></li><li><a href="#example-io"><span>Example <wbr/>I/<wbr/>O</span></a></li><li><ul><li><a href="#input-alignmentqasm-source"><span>Input: alignment.qasm (source)</span></a></li><li><a href="#output-abstract-syntax-tree"><span>Output: <wbr/>Abstract <wbr/>Syntax <wbr/>Tree</span></a></li></ul></li><li><a href="#api-documentation-navigation"><span>API <wbr/>Documentation <wbr/>Navigation</span></a></li><li><ul><li><a href="#core-functions"><span>Core <wbr/>Functions</span></a></li><li><a href="#tokenization"><span>Tokenization</span></a></li><li><a href="#lexing"><span>Lexing</span></a></li><li><a href="#ast-structure"><span>AST <wbr/>Structure</span></a></li><li><a href="#parsing"><span>Parsing</span></a></li><li><a href="#utilities-and-internals"><span>Utilities and <wbr/>Internals</span></a></li></ul></li><li><a href="#new-in-version-200"><span>New <wbr/>In <wbr/>Version 2.0.0</span></a></li><li><a href="#source-code"><span>Source <wbr/>Code</span></a></li><li><a href="#references"><span>References</span></a></li><li><a href="#license"><span>License</span></a></li><li><a href="#how-to-cite"><span>How to <wbr/>Cite</span></a></li></ul></div></details></div><div class="site-menu"><nav id="tsd-sidebar-links" class="tsd-navigation"><a href="https://github.com/comp-phys-marc/qasm-ts" class="tsd-nav-link">GitHub</a><a href="https://www.npmjs.com/package/qasm-ts" class="tsd-nav-link">NPM</a></nav><nav class="tsd-navigation"><a href="modules.html">qasm-ts - v2.1.2</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer></footer><div class="overlay"></div></body></html>
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qasm-ts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "QASM, the low-level programming language for quantum circuit specification, implemented in TypeScript.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"build": "tsc -p ./tsconfig.json",
|
|
7
8
|
"test": "ts-node node_modules/jasmine/bin/jasmine",
|
|
8
9
|
"docs": "typedoc --options docs/typedoc.json"
|
|
9
10
|
},
|
package/readme.md
CHANGED
|
@@ -12,7 +12,7 @@ The package is aimed at enabling implementations of verification and validation
|
|
|
12
12
|
|
|
13
13
|
Language documentation is provided by IBM [here](https://openqasm.com).
|
|
14
14
|
|
|
15
|
-
## New in Version 2.1.
|
|
15
|
+
## New in Version 2.1.x
|
|
16
16
|
|
|
17
17
|
This release includes several improvements made during the review of the repo by reviewers from the Journal of Open Source Software. These improvements include:
|
|
18
18
|
|
|
@@ -22,6 +22,7 @@ This release includes several improvements made during the review of the repo by
|
|
|
22
22
|
- fix for the compatibility of the test suite with Windows
|
|
23
23
|
- documentation on how to run our benchmarks
|
|
24
24
|
- improvements to the README
|
|
25
|
+
- Type exports
|
|
25
26
|
- etc.
|
|
26
27
|
|
|
27
28
|
|
|
@@ -190,7 +191,7 @@ Unless required by applicable law or agreed to in writing, software distributed
|
|
|
190
191
|
If you are using QASM-TS for research we appreciate any citations. Please read and cite our [paper](https://doi.org/10.21105/joss.08696) published with the Journal of Open Source Software.
|
|
191
192
|
|
|
192
193
|
```
|
|
193
|
-
@article{
|
|
194
|
+
@article{Kim_2025,
|
|
194
195
|
doi = {10.21105/joss.08696},
|
|
195
196
|
url = {https://doi.org/10.21105/joss.08696},
|
|
196
197
|
year = {2025},
|
|
@@ -198,7 +199,7 @@ If you are using QASM-TS for research we appreciate any citations. Please read a
|
|
|
198
199
|
volume = {10},
|
|
199
200
|
number = {113},
|
|
200
201
|
pages = {8696},
|
|
201
|
-
author = {Kim
|
|
202
|
+
author = {Kim, Sean and Edwards, Marcus},
|
|
202
203
|
title = {Enabling the Verification and Formalization of Hybrid Quantum-Classical Computing with OpenQASM 3.0 compatible QASM-TS 2.0},
|
|
203
204
|
journal = {Journal of Open Source Software}
|
|
204
205
|
}
|
package/tsconfig.json
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
"compileOnSave": true,
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"target": "es6",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"declaration": true,
|
|
5
7
|
"moduleResolution": "node",
|
|
6
8
|
"baseUrl": ".",
|
|
7
9
|
"lib": [
|
|
@@ -9,6 +11,9 @@
|
|
|
9
11
|
"es2015",
|
|
10
12
|
"es2016",
|
|
11
13
|
"es2017.object"
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"./src/**/*"
|
|
18
|
+
]
|
|
14
19
|
}
|
package/dist/errors.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Error classes for QASM parsing and validation
|
|
4
|
-
*
|
|
5
|
-
* This module provides specific error types for different parsing failures,
|
|
6
|
-
* enabling precise error handling and debugging. Each error includes contextual
|
|
7
|
-
* information about where the error occurred in the source code.
|
|
8
|
-
*
|
|
9
|
-
* @module Error Handling
|
|
10
|
-
*/
|
|
11
|
-
var __extends = (this && this.__extends) || (function () {
|
|
12
|
-
var extendStatics = function (d, b) {
|
|
13
|
-
extendStatics = Object.setPrototypeOf ||
|
|
14
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
15
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
16
|
-
return extendStatics(d, b);
|
|
17
|
-
};
|
|
18
|
-
return function (d, b) {
|
|
19
|
-
if (typeof b !== "function" && b !== null)
|
|
20
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
21
|
-
extendStatics(d, b);
|
|
22
|
-
function __() { this.constructor = d; }
|
|
23
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
24
|
-
};
|
|
25
|
-
})();
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
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;
|
|
28
|
-
/** Class representing a bad argument exception. */
|
|
29
|
-
var BadArgumentError = /** @class */ (function (_super) {
|
|
30
|
-
__extends(BadArgumentError, _super);
|
|
31
|
-
function BadArgumentError(message) {
|
|
32
|
-
var _newTarget = this.constructor;
|
|
33
|
-
var _this = _super.call(this, message) || this;
|
|
34
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
35
|
-
_this.name = BadArgumentError.name;
|
|
36
|
-
return _this;
|
|
37
|
-
}
|
|
38
|
-
return BadArgumentError;
|
|
39
|
-
}(Error));
|
|
40
|
-
exports.BadArgumentError = BadArgumentError;
|
|
41
|
-
/** Class representing a bad include statement */
|
|
42
|
-
var BadIncludeError = /** @class */ (function (_super) {
|
|
43
|
-
__extends(BadIncludeError, _super);
|
|
44
|
-
function BadIncludeError(message) {
|
|
45
|
-
var _newTarget = this.constructor;
|
|
46
|
-
var _this = _super.call(this, message) || this;
|
|
47
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
48
|
-
_this.name = BadIncludeError.name;
|
|
49
|
-
return _this;
|
|
50
|
-
}
|
|
51
|
-
return BadIncludeError;
|
|
52
|
-
}(Error));
|
|
53
|
-
exports.BadIncludeError = BadIncludeError;
|
|
54
|
-
/** Class representing a bad quantum register exception. */
|
|
55
|
-
var BadQregError = /** @class */ (function (_super) {
|
|
56
|
-
__extends(BadQregError, _super);
|
|
57
|
-
function BadQregError(message) {
|
|
58
|
-
var _newTarget = this.constructor;
|
|
59
|
-
var _this = _super.call(this, message) || this;
|
|
60
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
61
|
-
_this.name = BadQregError.name;
|
|
62
|
-
return _this;
|
|
63
|
-
}
|
|
64
|
-
return BadQregError;
|
|
65
|
-
}(Error));
|
|
66
|
-
exports.BadQregError = BadQregError;
|
|
67
|
-
/** Class representing a bad equality exception. */
|
|
68
|
-
var BadEqualsError = /** @class */ (function (_super) {
|
|
69
|
-
__extends(BadEqualsError, _super);
|
|
70
|
-
function BadEqualsError(message) {
|
|
71
|
-
var _newTarget = this.constructor;
|
|
72
|
-
var _this = _super.call(this, message) || this;
|
|
73
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
74
|
-
_this.name = BadEqualsError.name;
|
|
75
|
-
return _this;
|
|
76
|
-
}
|
|
77
|
-
return BadEqualsError;
|
|
78
|
-
}(Error));
|
|
79
|
-
exports.BadEqualsError = BadEqualsError;
|
|
80
|
-
/** Class representing a bad classical register exception. */
|
|
81
|
-
var BadCregError = /** @class */ (function (_super) {
|
|
82
|
-
__extends(BadCregError, _super);
|
|
83
|
-
function BadCregError(message) {
|
|
84
|
-
var _newTarget = this.constructor;
|
|
85
|
-
var _this = _super.call(this, message) || this;
|
|
86
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
87
|
-
_this.name = BadCregError.name;
|
|
88
|
-
return _this;
|
|
89
|
-
}
|
|
90
|
-
return BadCregError;
|
|
91
|
-
}(Error));
|
|
92
|
-
exports.BadCregError = BadCregError;
|
|
93
|
-
/** Class representing a bad conditional exception. */
|
|
94
|
-
var BadConditionalError = /** @class */ (function (_super) {
|
|
95
|
-
__extends(BadConditionalError, _super);
|
|
96
|
-
function BadConditionalError(message) {
|
|
97
|
-
var _newTarget = this.constructor;
|
|
98
|
-
var _this = _super.call(this, message) || this;
|
|
99
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
100
|
-
_this.name = BadConditionalError.name;
|
|
101
|
-
return _this;
|
|
102
|
-
}
|
|
103
|
-
return BadConditionalError;
|
|
104
|
-
}(Error));
|
|
105
|
-
exports.BadConditionalError = BadConditionalError;
|
|
106
|
-
/** Class representing a bad barrier exception. */
|
|
107
|
-
var BadBarrierError = /** @class */ (function (_super) {
|
|
108
|
-
__extends(BadBarrierError, _super);
|
|
109
|
-
function BadBarrierError(message) {
|
|
110
|
-
var _newTarget = this.constructor;
|
|
111
|
-
var _this = _super.call(this, message) || this;
|
|
112
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
113
|
-
_this.name = BadBarrierError.name;
|
|
114
|
-
return _this;
|
|
115
|
-
}
|
|
116
|
-
return BadBarrierError;
|
|
117
|
-
}(Error));
|
|
118
|
-
exports.BadBarrierError = BadBarrierError;
|
|
119
|
-
/** Class representing a bad measurement exception. */
|
|
120
|
-
var BadMeasurementError = /** @class */ (function (_super) {
|
|
121
|
-
__extends(BadMeasurementError, _super);
|
|
122
|
-
function BadMeasurementError(message) {
|
|
123
|
-
var _newTarget = this.constructor;
|
|
124
|
-
var _this = _super.call(this, message) || this;
|
|
125
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
126
|
-
_this.name = BadMeasurementError.name;
|
|
127
|
-
return _this;
|
|
128
|
-
}
|
|
129
|
-
return BadMeasurementError;
|
|
130
|
-
}(Error));
|
|
131
|
-
exports.BadMeasurementError = BadMeasurementError;
|
|
132
|
-
/** Class representing a bad gate exception. */
|
|
133
|
-
var BadGateError = /** @class */ (function (_super) {
|
|
134
|
-
__extends(BadGateError, _super);
|
|
135
|
-
function BadGateError(message) {
|
|
136
|
-
var _newTarget = this.constructor;
|
|
137
|
-
var _this = _super.call(this, message) || this;
|
|
138
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
139
|
-
_this.name = BadGateError.name;
|
|
140
|
-
return _this;
|
|
141
|
-
}
|
|
142
|
-
return BadGateError;
|
|
143
|
-
}(Error));
|
|
144
|
-
exports.BadGateError = BadGateError;
|
|
145
|
-
/** Class representing a bad parameter exception. */
|
|
146
|
-
var BadParameterError = /** @class */ (function (_super) {
|
|
147
|
-
__extends(BadParameterError, _super);
|
|
148
|
-
function BadParameterError(message) {
|
|
149
|
-
var _newTarget = this.constructor;
|
|
150
|
-
var _this = _super.call(this, message) || this;
|
|
151
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
152
|
-
_this.name = BadParameterError.name;
|
|
153
|
-
return _this;
|
|
154
|
-
}
|
|
155
|
-
return BadParameterError;
|
|
156
|
-
}(Error));
|
|
157
|
-
exports.BadParameterError = BadParameterError;
|
|
158
|
-
/** Class representing a missing semicolon exception. */
|
|
159
|
-
var MissingSemicolonError = /** @class */ (function (_super) {
|
|
160
|
-
__extends(MissingSemicolonError, _super);
|
|
161
|
-
function MissingSemicolonError(message) {
|
|
162
|
-
var _newTarget = this.constructor;
|
|
163
|
-
var _this = _super.call(this, message) || this;
|
|
164
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
165
|
-
_this.name = MissingSemicolonError.name;
|
|
166
|
-
return _this;
|
|
167
|
-
}
|
|
168
|
-
return MissingSemicolonError;
|
|
169
|
-
}(Error));
|
|
170
|
-
exports.MissingSemicolonError = MissingSemicolonError;
|
|
171
|
-
/** Class representing a missing opening or closing parenthesis, bracket, or curly brakcet. */
|
|
172
|
-
var MissingBraceError = /** @class */ (function (_super) {
|
|
173
|
-
__extends(MissingBraceError, _super);
|
|
174
|
-
function MissingBraceError(message) {
|
|
175
|
-
var _newTarget = this.constructor;
|
|
176
|
-
var _this = _super.call(this, message) || this;
|
|
177
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
178
|
-
_this.name = MissingSemicolonError.name;
|
|
179
|
-
return _this;
|
|
180
|
-
}
|
|
181
|
-
return MissingBraceError;
|
|
182
|
-
}(Error));
|
|
183
|
-
exports.MissingBraceError = MissingBraceError;
|
|
184
|
-
/** Class representing an unsupported OpenQASM version exception. */
|
|
185
|
-
var UnsupportedOpenQASMVersionError = /** @class */ (function (_super) {
|
|
186
|
-
__extends(UnsupportedOpenQASMVersionError, _super);
|
|
187
|
-
function UnsupportedOpenQASMVersionError(message) {
|
|
188
|
-
var _newTarget = this.constructor;
|
|
189
|
-
var _this = _super.call(this, message) || this;
|
|
190
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
191
|
-
_this.name = UnsupportedOpenQASMVersionError.name;
|
|
192
|
-
return _this;
|
|
193
|
-
}
|
|
194
|
-
return UnsupportedOpenQASMVersionError;
|
|
195
|
-
}(Error));
|
|
196
|
-
exports.UnsupportedOpenQASMVersionError = UnsupportedOpenQASMVersionError;
|
|
197
|
-
/** Class representing an error parsing an expected string literal. */
|
|
198
|
-
var BadStringLiteralError = /** @class */ (function (_super) {
|
|
199
|
-
__extends(BadStringLiteralError, _super);
|
|
200
|
-
function BadStringLiteralError(message) {
|
|
201
|
-
var _newTarget = this.constructor;
|
|
202
|
-
var _this = _super.call(this, message) || this;
|
|
203
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
204
|
-
_this.name = BadStringLiteralError.name;
|
|
205
|
-
return _this;
|
|
206
|
-
}
|
|
207
|
-
return BadStringLiteralError;
|
|
208
|
-
}(Error));
|
|
209
|
-
exports.BadStringLiteralError = BadStringLiteralError;
|
|
210
|
-
/** Class representing an error parsing scalar types. */
|
|
211
|
-
var BadClassicalTypeError = /** @class */ (function (_super) {
|
|
212
|
-
__extends(BadClassicalTypeError, _super);
|
|
213
|
-
function BadClassicalTypeError(message) {
|
|
214
|
-
var _newTarget = this.constructor;
|
|
215
|
-
var _this = _super.call(this, message) || this;
|
|
216
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
217
|
-
_this.name = BadClassicalTypeError.name;
|
|
218
|
-
return _this;
|
|
219
|
-
}
|
|
220
|
-
return BadClassicalTypeError;
|
|
221
|
-
}(Error));
|
|
222
|
-
exports.BadClassicalTypeError = BadClassicalTypeError;
|
|
223
|
-
/** Class representing an error parsing an expression. */
|
|
224
|
-
var BadExpressionError = /** @class */ (function (_super) {
|
|
225
|
-
__extends(BadExpressionError, _super);
|
|
226
|
-
function BadExpressionError(message) {
|
|
227
|
-
var _newTarget = this.constructor;
|
|
228
|
-
var _this = _super.call(this, message) || this;
|
|
229
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
230
|
-
_this.name = BadExpressionError.name;
|
|
231
|
-
return _this;
|
|
232
|
-
}
|
|
233
|
-
return BadExpressionError;
|
|
234
|
-
}(Error));
|
|
235
|
-
exports.BadExpressionError = BadExpressionError;
|
|
236
|
-
/** Class representing an error in defining or calling a custom subroutine. */
|
|
237
|
-
var BadSubroutineError = /** @class */ (function (_super) {
|
|
238
|
-
__extends(BadSubroutineError, _super);
|
|
239
|
-
function BadSubroutineError(message) {
|
|
240
|
-
var _newTarget = this.constructor;
|
|
241
|
-
var _this = _super.call(this, message) || this;
|
|
242
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
243
|
-
_this.name = BadSubroutineError.name;
|
|
244
|
-
return _this;
|
|
245
|
-
}
|
|
246
|
-
return BadSubroutineError;
|
|
247
|
-
}(Error));
|
|
248
|
-
exports.BadSubroutineError = BadSubroutineError;
|
|
249
|
-
/** Class representing a bad loop statement declaration. */
|
|
250
|
-
var BadLoopError = /** @class */ (function (_super) {
|
|
251
|
-
__extends(BadLoopError, _super);
|
|
252
|
-
function BadLoopError(message) {
|
|
253
|
-
var _newTarget = this.constructor;
|
|
254
|
-
var _this = _super.call(this, message) || this;
|
|
255
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
256
|
-
_this.name = BadLoopError.name;
|
|
257
|
-
return _this;
|
|
258
|
-
}
|
|
259
|
-
return BadLoopError;
|
|
260
|
-
}(Error));
|
|
261
|
-
exports.BadLoopError = BadLoopError;
|
|
262
|
-
/** Class representing a bad quantum instruction. */
|
|
263
|
-
var BadQuantumInstructionError = /** @class */ (function (_super) {
|
|
264
|
-
__extends(BadQuantumInstructionError, _super);
|
|
265
|
-
function BadQuantumInstructionError(message) {
|
|
266
|
-
var _newTarget = this.constructor;
|
|
267
|
-
var _this = _super.call(this, message) || this;
|
|
268
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
269
|
-
_this.name = BadQuantumInstructionError.name;
|
|
270
|
-
return _this;
|
|
271
|
-
}
|
|
272
|
-
return BadQuantumInstructionError;
|
|
273
|
-
}(Error));
|
|
274
|
-
exports.BadQuantumInstructionError = BadQuantumInstructionError;
|
package/dist/lexer.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Main lexer interface for tokenizing QASM code
|
|
4
|
-
*
|
|
5
|
-
* The lexer is responsible for breaking down QASM source code into tokens
|
|
6
|
-
* that can be consumed by the parser. It supports both OpenQASM 2.0 and 3.0
|
|
7
|
-
* syntax, with version-specific lexers handling the differences in token types
|
|
8
|
-
* and syntax rules.
|
|
9
|
-
*
|
|
10
|
-
* The specific Lexer implementations can be found at:
|
|
11
|
-
* - {@link Qasm3Lexer}
|
|
12
|
-
* - {@link Qasm2Lexer}
|
|
13
|
-
*
|
|
14
|
-
* @module Lexing
|
|
15
|
-
*
|
|
16
|
-
* @example Token Flow
|
|
17
|
-
* ```
|
|
18
|
-
* Source Code → Lexer → Tokens → Parser → AST
|
|
19
|
-
* "h q[0];" → [Id, Id, LSParen, NNInteger, RSParen, Semicolon]
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* * @example Basic lexing workflow
|
|
23
|
-
* ```typescript
|
|
24
|
-
* import { lex } from './lexer';
|
|
25
|
-
*
|
|
26
|
-
* const qasmCode = 'OPENQASM 3.0; qubit q; h q;';
|
|
27
|
-
* const tokens = lex(qasmCode);
|
|
28
|
-
* console.log(tokens);
|
|
29
|
-
* // [
|
|
30
|
-
* // [Token.OpenQASM, undefined],
|
|
31
|
-
* // [Token.Id, 'qubit'],
|
|
32
|
-
* // [Token.Id, 'q'],
|
|
33
|
-
* // [Token.Semicolon, undefined],
|
|
34
|
-
* // [Token.Id, 'h'],
|
|
35
|
-
* // [Token.Id, 'q'],
|
|
36
|
-
* // [Token.Semicolon, undefined]
|
|
37
|
-
* // ]
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.lex = lex;
|
|
42
|
-
var lexer_1 = require("./qasm2/lexer");
|
|
43
|
-
var lexer_2 = require("./qasm3/lexer");
|
|
44
|
-
var version_1 = require("./version");
|
|
45
|
-
var errors_1 = require("./errors");
|
|
46
|
-
/**
|
|
47
|
-
* Tokenizes OpenQASM source code into an array of tokens.
|
|
48
|
-
*
|
|
49
|
-
* This is the main entry point for lexical analysis. It automatically selects
|
|
50
|
-
* the appropriate lexer implementation based on the OpenQASM version and returns
|
|
51
|
-
* an array of tokens that can be consumed by the parser.
|
|
52
|
-
*
|
|
53
|
-
* Each token is represented as a tuple containing:
|
|
54
|
-
* - **Token type**: An enum value indicating the kind of token
|
|
55
|
-
* - **Token value**: The associated value (for literals, identifiers, operators)
|
|
56
|
-
*
|
|
57
|
-
* @group Lexing
|
|
58
|
-
* @param qasm - The OpenQASM source code to tokenize
|
|
59
|
-
* @param cursor - Starting position in the input string (defaults to 0)
|
|
60
|
-
* @param version - OpenQASM version to use for lexing (defaults to 3.0)
|
|
61
|
-
* @returns Array of token tuples [TokenType, value?]
|
|
62
|
-
* @throws {UnsupportedOpenQASMVersionError} When an unsupported version is specified
|
|
63
|
-
*
|
|
64
|
-
* @example Tokenize OpenQASM 3.0 code
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const tokens = lex('qubit[2] q; h q[0];', 0, 3);
|
|
67
|
-
* // Returns tokens using OpenQASM 3.0 syntax rules
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @example Tokenize OpenQASM 2.0 code
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const tokens = lex('qreg q[2]; h q[0];', 0, 2);
|
|
73
|
-
* // Returns tokens using OpenQASM 2.0 syntax rules
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @example Resume lexing from specific position
|
|
77
|
-
* ```typescript
|
|
78
|
-
* const code = 'OPENQASM 3.0; qubit q;';
|
|
79
|
-
* const tokens = lex(code, 12); // Start after "OPENQASM 3.0"
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
function lex(qasm, cursor, version) {
|
|
83
|
-
var lexer;
|
|
84
|
-
if (version instanceof version_1.OpenQASMVersion) {
|
|
85
|
-
switch (version.major) {
|
|
86
|
-
case version_1.OpenQASMMajorVersion.Version2:
|
|
87
|
-
lexer = new lexer_1.default(qasm, cursor);
|
|
88
|
-
break;
|
|
89
|
-
case version_1.OpenQASMMajorVersion.Version3:
|
|
90
|
-
lexer = new lexer_2.default(qasm, cursor);
|
|
91
|
-
break;
|
|
92
|
-
default:
|
|
93
|
-
throw new errors_1.UnsupportedOpenQASMVersionError("Unsupported OpenQASM version detected: ".concat(version.major));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (typeof version === "number") {
|
|
97
|
-
switch (version) {
|
|
98
|
-
case 2:
|
|
99
|
-
lexer = new lexer_1.default(qasm, cursor);
|
|
100
|
-
break;
|
|
101
|
-
case 3:
|
|
102
|
-
lexer = new lexer_2.default(qasm, cursor);
|
|
103
|
-
break;
|
|
104
|
-
default:
|
|
105
|
-
throw new errors_1.UnsupportedOpenQASMVersionError("Unsupported OpenQASM version detected: ".concat(version));
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
else if (version === version_1.OpenQASMMajorVersion.Version2) {
|
|
109
|
-
lexer = new lexer_1.default(qasm, cursor);
|
|
110
|
-
}
|
|
111
|
-
else if (version === version_1.OpenQASMMajorVersion.Version3) {
|
|
112
|
-
lexer = new lexer_2.default(qasm, cursor);
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
lexer = new lexer_2.default(qasm, cursor);
|
|
116
|
-
}
|
|
117
|
-
var tokens = lexer.lex();
|
|
118
|
-
return tokens;
|
|
119
|
-
}
|