qasm-ts 1.1.3 → 2.0.0

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.
Files changed (188) hide show
  1. package/.eslintrc.json +13 -0
  2. package/dist/errors.js +119 -2
  3. package/dist/lexer.js +39 -294
  4. package/dist/main.js +42 -12
  5. package/dist/parser.js +46 -482
  6. package/dist/{ast.js → qasm2/ast.js} +38 -2
  7. package/dist/qasm2/lexer.js +436 -0
  8. package/dist/qasm2/parser.js +609 -0
  9. package/dist/{token.js → qasm2/token.js} +62 -21
  10. package/dist/qasm3/ast.js +1081 -0
  11. package/dist/qasm3/lexer.js +615 -0
  12. package/dist/qasm3/parser.js +2030 -0
  13. package/dist/qasm3/token.js +342 -0
  14. package/dist/version.js +41 -0
  15. package/docs/.nojekyll +1 -0
  16. package/docs/assets/highlight.css +99 -0
  17. package/docs/assets/icons.js +18 -0
  18. package/docs/assets/icons.svg +1 -0
  19. package/docs/assets/main.js +60 -0
  20. package/docs/assets/navigation.js +1 -0
  21. package/docs/assets/search.js +1 -0
  22. package/docs/assets/style.css +1493 -0
  23. package/docs/classes/errors.BadArgumentError.html +12 -0
  24. package/docs/classes/errors.BadBarrierError.html +12 -0
  25. package/docs/classes/errors.BadClassicalTypeError.html +12 -0
  26. package/docs/classes/errors.BadConditionalError.html +12 -0
  27. package/docs/classes/errors.BadCregError.html +12 -0
  28. package/docs/classes/errors.BadEqualsError.html +12 -0
  29. package/docs/classes/errors.BadExpressionError.html +12 -0
  30. package/docs/classes/errors.BadGateError.html +12 -0
  31. package/docs/classes/errors.BadIncludeError.html +12 -0
  32. package/docs/classes/errors.BadLoopError.html +12 -0
  33. package/docs/classes/errors.BadMeasurementError.html +12 -0
  34. package/docs/classes/errors.BadParameterError.html +12 -0
  35. package/docs/classes/errors.BadQregError.html +12 -0
  36. package/docs/classes/errors.BadQuantumInstructionError.html +12 -0
  37. package/docs/classes/errors.BadStringLiteralError.html +12 -0
  38. package/docs/classes/errors.BadSubroutineError.html +12 -0
  39. package/docs/classes/errors.MissingBraceError.html +12 -0
  40. package/docs/classes/errors.MissingSemicolonError.html +12 -0
  41. package/docs/classes/errors.UnsupportedOpenQASMVersionError.html +12 -0
  42. package/docs/classes/qasm2_ast.ApplyGate.html +6 -0
  43. package/docs/classes/qasm2_ast.AstNode.html +3 -0
  44. package/docs/classes/qasm2_ast.Barrier.html +5 -0
  45. package/docs/classes/qasm2_ast.CReg.html +5 -0
  46. package/docs/classes/qasm2_ast.Cos.html +3 -0
  47. package/docs/classes/qasm2_ast.Divide.html +3 -0
  48. package/docs/classes/qasm2_ast.Exp.html +3 -0
  49. package/docs/classes/qasm2_ast.Gate.html +7 -0
  50. package/docs/classes/qasm2_ast.Id.html +4 -0
  51. package/docs/classes/qasm2_ast.If.html +6 -0
  52. package/docs/classes/qasm2_ast.Include.html +4 -0
  53. package/docs/classes/qasm2_ast.Ln.html +3 -0
  54. package/docs/classes/qasm2_ast.Measure.html +7 -0
  55. package/docs/classes/qasm2_ast.Minus.html +3 -0
  56. package/docs/classes/qasm2_ast.NNInteger.html +4 -0
  57. package/docs/classes/qasm2_ast.Opaque.html +6 -0
  58. package/docs/classes/qasm2_ast.Pi.html +3 -0
  59. package/docs/classes/qasm2_ast.Plus.html +3 -0
  60. package/docs/classes/qasm2_ast.Power.html +3 -0
  61. package/docs/classes/qasm2_ast.QReg.html +5 -0
  62. package/docs/classes/qasm2_ast.Real.html +4 -0
  63. package/docs/classes/qasm2_ast.Sin.html +3 -0
  64. package/docs/classes/qasm2_ast.Sqrt.html +3 -0
  65. package/docs/classes/qasm2_ast.Tan.html +3 -0
  66. package/docs/classes/qasm2_ast.Times.html +3 -0
  67. package/docs/classes/qasm2_ast.Variable.html +4 -0
  68. package/docs/classes/qasm2_ast.Version.html +4 -0
  69. package/docs/classes/qasm2_lexer.default.html +50 -0
  70. package/docs/classes/qasm2_parser.default.html +87 -0
  71. package/docs/classes/qasm3_ast.AliasStatement.html +5 -0
  72. package/docs/classes/qasm3_ast.AngleType.html +4 -0
  73. package/docs/classes/qasm3_ast.Arithmetic.html +6 -0
  74. package/docs/classes/qasm3_ast.ArrayAccess.html +5 -0
  75. package/docs/classes/qasm3_ast.ArrayDeclaration.html +7 -0
  76. package/docs/classes/qasm3_ast.ArrayInitializer.html +4 -0
  77. package/docs/classes/qasm3_ast.ArrayReference.html +5 -0
  78. package/docs/classes/qasm3_ast.AssignmentStatement.html +5 -0
  79. package/docs/classes/qasm3_ast.AstNode.html +3 -0
  80. package/docs/classes/qasm3_ast.Binary.html +6 -0
  81. package/docs/classes/qasm3_ast.BitType.html +4 -0
  82. package/docs/classes/qasm3_ast.BitstringLiteral.html +4 -0
  83. package/docs/classes/qasm3_ast.BoolType.html +3 -0
  84. package/docs/classes/qasm3_ast.BooleanLiteral.html +4 -0
  85. package/docs/classes/qasm3_ast.BoxDefinition.html +7 -0
  86. package/docs/classes/qasm3_ast.BranchingStatement.html +8 -0
  87. package/docs/classes/qasm3_ast.BreakStatement.html +3 -0
  88. package/docs/classes/qasm3_ast.CalibrationGrammarDeclaration.html +6 -0
  89. package/docs/classes/qasm3_ast.CaseStatement.html +5 -0
  90. package/docs/classes/qasm3_ast.Cast.html +5 -0
  91. package/docs/classes/qasm3_ast.ClassicalDeclaration.html +7 -0
  92. package/docs/classes/qasm3_ast.ClassicalType.html +3 -0
  93. package/docs/classes/qasm3_ast.ComplexType.html +6 -0
  94. package/docs/classes/qasm3_ast.ContinueStatement.html +3 -0
  95. package/docs/classes/qasm3_ast.DefaultStatement.html +4 -0
  96. package/docs/classes/qasm3_ast.DurationLiteral.html +5 -0
  97. package/docs/classes/qasm3_ast.DurationOf.html +4 -0
  98. package/docs/classes/qasm3_ast.DurationType.html +3 -0
  99. package/docs/classes/qasm3_ast.Euler.html +3 -0
  100. package/docs/classes/qasm3_ast.Expression.html +3 -0
  101. package/docs/classes/qasm3_ast.ExternSignature.html +8 -0
  102. package/docs/classes/qasm3_ast.FloatLiteral.html +4 -0
  103. package/docs/classes/qasm3_ast.FloatType.html +6 -0
  104. package/docs/classes/qasm3_ast.ForLoopStatement.html +12 -0
  105. package/docs/classes/qasm3_ast.HardwareQubit.html +5 -0
  106. package/docs/classes/qasm3_ast.IODeclaration.html +5 -0
  107. package/docs/classes/qasm3_ast.Identifier.html +4 -0
  108. package/docs/classes/qasm3_ast.ImaginaryLiteral.html +4 -0
  109. package/docs/classes/qasm3_ast.Include.html +6 -0
  110. package/docs/classes/qasm3_ast.IndexSet.html +5 -0
  111. package/docs/classes/qasm3_ast.IntType.html +4 -0
  112. package/docs/classes/qasm3_ast.IntegerLiteral.html +4 -0
  113. package/docs/classes/qasm3_ast.MathFunction.html +5 -0
  114. package/docs/classes/qasm3_ast.NumericLiteral.html +4 -0
  115. package/docs/classes/qasm3_ast.Parameters.html +4 -0
  116. package/docs/classes/qasm3_ast.Pi.html +3 -0
  117. package/docs/classes/qasm3_ast.ProgramBlock.html +7 -0
  118. package/docs/classes/qasm3_ast.QuantumBarrier.html +6 -0
  119. package/docs/classes/qasm3_ast.QuantumBlock.html +6 -0
  120. package/docs/classes/qasm3_ast.QuantumDeclaration.html +8 -0
  121. package/docs/classes/qasm3_ast.QuantumDelay.html +5 -0
  122. package/docs/classes/qasm3_ast.QuantumGateCall.html +9 -0
  123. package/docs/classes/qasm3_ast.QuantumGateDefinition.html +9 -0
  124. package/docs/classes/qasm3_ast.QuantumGateModifier.html +5 -0
  125. package/docs/classes/qasm3_ast.QuantumMeasurement.html +6 -0
  126. package/docs/classes/qasm3_ast.QuantumMeasurementAssignment.html +8 -0
  127. package/docs/classes/qasm3_ast.QuantumReset.html +4 -0
  128. package/docs/classes/qasm3_ast.Range.html +6 -0
  129. package/docs/classes/qasm3_ast.ReturnStatement.html +4 -0
  130. package/docs/classes/qasm3_ast.SizeOf.html +5 -0
  131. package/docs/classes/qasm3_ast.Statement.html +12 -0
  132. package/docs/classes/qasm3_ast.StretchType.html +3 -0
  133. package/docs/classes/qasm3_ast.SubroutineBlock.html +6 -0
  134. package/docs/classes/qasm3_ast.SubroutineCall.html +5 -0
  135. package/docs/classes/qasm3_ast.SubroutineDefinition.html +10 -0
  136. package/docs/classes/qasm3_ast.SubscriptedIdentifier.html +5 -0
  137. package/docs/classes/qasm3_ast.SwitchStatement.html +6 -0
  138. package/docs/classes/qasm3_ast.Tau.html +3 -0
  139. package/docs/classes/qasm3_ast.TrigFunction.html +5 -0
  140. package/docs/classes/qasm3_ast.UIntType.html +4 -0
  141. package/docs/classes/qasm3_ast.Unary.html +5 -0
  142. package/docs/classes/qasm3_ast.Version.html +6 -0
  143. package/docs/classes/qasm3_ast.WhileLoopStatement.html +6 -0
  144. package/docs/classes/qasm3_lexer.default.html +60 -0
  145. package/docs/classes/qasm3_parser.default.html +227 -0
  146. package/docs/classes/version.OpenQASMVersion.html +16 -0
  147. package/docs/enums/qasm2_token.Token.html +39 -0
  148. package/docs/enums/qasm3_ast.ArithmeticOp.html +9 -0
  149. package/docs/enums/qasm3_ast.ArrayReferenceModifier.html +4 -0
  150. package/docs/enums/qasm3_ast.BinaryOp.html +15 -0
  151. package/docs/enums/qasm3_ast.DurationUnit.html +7 -0
  152. package/docs/enums/qasm3_ast.IOModifier.html +4 -0
  153. package/docs/enums/qasm3_ast.MathFunctionTypes.html +12 -0
  154. package/docs/enums/qasm3_ast.QuantumGateModifierName.html +6 -0
  155. package/docs/enums/qasm3_ast.TrigFunctionTypes.html +8 -0
  156. package/docs/enums/qasm3_ast.UnaryOp.html +5 -0
  157. package/docs/enums/qasm3_token.Token.html +101 -0
  158. package/docs/enums/version.OpenQASMMajorVersion.html +4 -0
  159. package/docs/functions/lexer.lex.html +1 -0
  160. package/docs/functions/main.parseFile.html +4 -0
  161. package/docs/functions/main.parseString.html +4 -0
  162. package/docs/functions/parser.parse.html +1 -0
  163. package/docs/functions/qasm2_token.inverseLookup.html +3 -0
  164. package/docs/functions/qasm2_token.lookup.html +4 -0
  165. package/docs/functions/qasm2_token.notParam.html +3 -0
  166. package/docs/functions/qasm3_token.inverseLookup.html +3 -0
  167. package/docs/functions/qasm3_token.lookup.html +4 -0
  168. package/docs/functions/qasm3_token.notParam.html +3 -0
  169. package/docs/hierarchy.html +1 -0
  170. package/docs/index.html +55 -0
  171. package/docs/modules/errors.html +21 -0
  172. package/docs/modules/lexer.html +2 -0
  173. package/docs/modules/main.html +3 -0
  174. package/docs/modules/parser.html +2 -0
  175. package/docs/modules/qasm2_ast.html +28 -0
  176. package/docs/modules/qasm2_lexer.html +2 -0
  177. package/docs/modules/qasm2_parser.html +2 -0
  178. package/docs/modules/qasm2_token.html +5 -0
  179. package/docs/modules/qasm3_ast.html +83 -0
  180. package/docs/modules/qasm3_lexer.html +2 -0
  181. package/docs/modules/qasm3_parser.html +2 -0
  182. package/docs/modules/qasm3_token.html +5 -0
  183. package/docs/modules/version.html +3 -0
  184. package/docs/modules.html +14 -0
  185. package/docs/types/errors.ReturnErrorConstructor.html +2 -0
  186. package/package.json +5 -4
  187. package/readme.md +67 -51
  188. package/dist/example.js +0 -22
@@ -0,0 +1,2 @@
1
+ <!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>ReturnErrorConstructor | qasm-ts</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"/><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></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">qasm-ts</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">qasm-ts</a></li><li><a href="../modules/errors.html">errors</a></li><li><a href="errors.ReturnErrorConstructor.html">ReturnErrorConstructor</a></li></ul><h1>Type Alias ReturnErrorConstructor</h1></div><div class="tsd-signature"><span class="tsd-kind-type-alias">Return<wbr/>Error<wbr/>Constructor</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-symbol">(</span><span class="tsd-signature-keyword">new </span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">message</span><span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol"> =&gt; </span><span class="tsd-signature-type">Error</span><span class="tsd-signature-symbol">)</span></div><div class="tsd-comment tsd-typography"><p>Type for returning an error constructor.</p>
2
+ </div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/comp-phys-marc/qasm-ts/blob/718a068d66b43e264c7bbca3983a86ec77251996/src/errors.ts#L173">projects/personal/qasm-ts/src/errors.ts:173</a></li></ul></aside></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>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></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>qasm-ts</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qasm-ts",
3
- "version": "1.1.3",
3
+ "version": "2.0.0",
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": {
@@ -25,12 +25,13 @@
25
25
  "homepage": "https://github.com/comp-phys-marc/qasm-ts#readme",
26
26
  "dependencies": {
27
27
  "path": "^0.12.7",
28
- "ts-node": "^8.3.0",
29
- "typescript": "^3.5.3"
28
+ "ts-node": "^8.3.0"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/jasmine": "^3.4.0",
33
32
  "@types/node": "^12.7.2",
34
- "jasmine": "^3.4.0"
33
+ "eslint": "^8.57.0",
34
+ "jasmine": "^3.4.0",
35
+ "typescript": "^5.5.4"
35
36
  }
36
37
  }
package/readme.md CHANGED
@@ -4,77 +4,92 @@ OpenQASM, the low-level programming language for quantum circuit specification,
4
4
 
5
5
  Language documentation is provided by IBM [here](https://github.com/Qiskit/openqasm/blob/master/spec/qasm2.rst).
6
6
 
7
- ## New in Version 1.1.0
7
+ ## New in Version 2.0.0
8
8
 
9
- - Checking for invalid code structure
10
- - Supporting custom gates
11
- - Rejecting unsupported gates
12
- - Better parameter parsing
13
- - Added conformance tests
14
- - Found and fixed bugs related to conformity
15
- - Jasmine unit tests
16
- - Lexing string literals
17
-
18
- ## New in Latest Subversion
19
-
20
- - Updated readme.
9
+ - Support for the OpenQASM 3.0 spec while retaining OpenQASM 2.0 backwards compatability.
21
10
 
22
11
  ## Usage
23
12
 
24
13
  Import the parse function or parseString function from the package.
25
14
 
26
- ```
27
- import { parse, parseString } from 'qasm-ts';
15
+ ```ts
16
+ import { parseFile, parseString } from 'qasm-ts';
28
17
  ```
29
18
 
30
- `parse` can be called with a file path to a `.qasm` file. It will parse the file and return the abstract syntax tree representation.
19
+ `parseFile` can be called with a file path to a `.qasm` file. It will parse the file and return the abstract syntax tree representation. `parseFile` can also take 3 optional parameters:
20
+ 1. `version`: A `number`, `OpenQASMVersion`, or `OpenQASMMajorVersion` to specify whether to use the Qasm 2 or 3 lexer/parser (defaults to version 3).
21
+ 2. `verbose`: Whether to return verbose objects that includes an extra key for each node's class name (defaults to `false`).
22
+ 3. `stringify`: Whether to stringify and format the return object (defaults to `false`).
31
23
 
32
- ```
33
- let ast = parse(<file-path>);
24
+ ```ts
25
+ let ast = parseFile("<file-path>");
34
26
  ```
35
27
 
36
- `parseString` should be called with a string of QASM code. It will parse the code and return the abstract syntax tree representation.
28
+ `parseString` should be called with a string of QASM code. It will parse the code and return the abstract syntax tree representation. `parseString` also takes the same optional arguments as `parseFile`.
37
29
 
38
- ```
39
- let ast = parseString(<qasm-string>);
30
+ ```ts
31
+ let ast = parseString("<qasm-string>");
40
32
  ```
41
33
 
42
34
  ## Example I/O
43
35
 
44
- ### Input: Deutsch_Algorithm.qasm
36
+ ### Input: `alignment.qasm` ([source](https://github.com/openqasm/openqasm/blob/main/examples/alignment.qasm))
45
37
 
46
38
  ```
47
- // Implementation of Deutsch algorithm with two qubits for f(x)=x
48
- OPENQASM 2.0;
49
- include "qelib1.inc";
50
-
51
- qreg q[5];
52
- creg c[5];
53
-
54
- x q[4];
55
- h q[3];
56
- h q[4];
57
- cx q[3],q[4];
58
- h q[3];
59
- measure q[3] -> c[3];
39
+ include "stdgates.inc";
40
+
41
+ stretch g;
42
+
43
+ qubit[3] q;
44
+ barrier q;
45
+ cx q[0], q[1];
46
+ delay[g] q[2];
47
+ U(pi/4, 0, pi/2) q[2];
48
+ delay[2*g] q[2];
49
+ barrier q;
50
+
60
51
  ```
61
52
 
62
53
  ### Output: Abstract Syntax Tree
63
54
 
64
- ```
65
- [ QReg { id: 'q', size: 5 },
66
- QReg { id: 'c', size: 5 },
67
- [ ApplyGate { name: 'x', qubits: [['q',4]], params: [] } ],
68
- [ ApplyGate { name: 'h', qubits: [['q',3]], params: [] } ],
69
- [ ApplyGate { name: 'h', qubits: [['q',4]], params: [] } ],
70
- [ ApplyGate { name: 'cx', qubits: [['q',3],['q',4]], params: [] } ],
71
- [ ApplyGate { name: 'h', qubits: [['q',3]], params: [] } ],
72
- Measure {
73
- src_index: 3,
74
- src_register: 'q',
75
- dest_index: 3,
76
- dest_register: 'c'
77
- } ]
55
+ Run with: `const ast = parseFile("./alignment.qasm", 3);`.
56
+
57
+ ```
58
+ [
59
+ Include { filename: '"stdgates.inc"' },
60
+ ClassicalDeclaration {
61
+ classicalType: StretchType {},
62
+ identifier: Identifier { name: 'g' },
63
+ initializer: null,
64
+ isConst: false
65
+ },
66
+ QuantumDeclaration {
67
+ identifier: Identifier { name: 'q' },
68
+ size: IntegerLiteral { value: 3 }
69
+ },
70
+ QuantumBarrier { qubits: [ [Identifier] ] },
71
+ QuantumGateCall {
72
+ quantumGateName: Identifier { name: 'cx' },
73
+ qubits: [ [SubscriptedIdentifier], [SubscriptedIdentifier] ],
74
+ parameters: null,
75
+ modifiers: []
76
+ },
77
+ QuantumDelay {
78
+ duration: Identifier { name: 'g' },
79
+ qubits: [ [SubscriptedIdentifier] ]
80
+ },
81
+ QuantumGateCall {
82
+ quantumGateName: Identifier { name: 'U' },
83
+ qubits: [ [SubscriptedIdentifier] ],
84
+ parameters: Parameters { args: [Array] },
85
+ modifiers: []
86
+ },
87
+ QuantumDelay {
88
+ duration: Arithmetic { op: '*', left: [IntegerLiteral], right: [Identifier] },
89
+ qubits: [ [SubscriptedIdentifier] ]
90
+ },
91
+ QuantumBarrier { qubits: [ [Identifier] ] }
92
+ ]
78
93
  ```
79
94
 
80
95
  ## Source code
@@ -103,7 +118,8 @@ npm test
103
118
 
104
119
  The original OpenQASM authors:
105
120
 
106
- - Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta "Open Quantum Assembly Language" [arXiv:1707.03429](http://web.archive.org/web/20210121114036/https://arxiv.org/abs/1707.03429).
121
+ - Andrew W. Cross, Lev S. Bishop, John A. Smolin, Jay M. Gambetta "Open Quantum Assembly Language" [arXiv:1707.03429](https://web.archive.org/web/20210121114036/https://arxiv.org/abs/1707.03429).
122
+ - Andrew W. Cross, Ali Javadi-Abhari, Thomas Alexander, Niel de Beaudrap, Lev S. Bishop, Steven Heidel, Colm A. Ryan, Prasahnt Sivarajah, John Smolin, Jay M. Gambetta, Blake R. Johnson "OpenQASM 3: A broader and deeper quantum assembly language" [arXiv:2104.14722](https://arxiv.org/abs/2104.14722)
107
123
 
108
124
  Another strongly typed implementation from which this project took some inspiration:
109
125
 
@@ -119,4 +135,4 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
119
135
  http://www.apache.org/licenses/LICENSE-2.0
120
136
  ```
121
137
 
122
- 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.
138
+ 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.
package/dist/example.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- exports.__esModule = true;
3
- var lexer_1 = require("./lexer");
4
- var parser_1 = require("./parser");
5
- var fs = require("fs");
6
- var qmasm = fs.readFileSync('spec/qmasm/comparator.qmasm', 'utf8');
7
- console.log(qmasm);
8
- var lexer = new lexer_1["default"](qmasm, 0);
9
- var tokens = lexer.lex();
10
- console.log(tokens);
11
- var parser = new parser_1["default"](tokens, false, 'spec/qmasm/');
12
- var ast = parser.parse();
13
- for (var i = 0; i < ast.length; i++) {
14
- console.log(ast[i]);
15
- if (ast[i]['val'] && ast[i]['val']['elements']) {
16
- for (var j = 0; j < ast[i]['val']['elements'].length; j++) {
17
- console.log(ast[i]['val']['elements'][j]);
18
- }
19
- }
20
- console.log(JSON.stringify(ast[i]));
21
- console.log('\n');
22
- }