qasm-ts 2.0.0 → 2.1.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 (365) hide show
  1. package/.github/workflows/draft-pdf.yml +24 -0
  2. package/CONTRIBUTING.md +3 -0
  3. package/LICENSE +201 -0
  4. package/dist/errors.js +9 -0
  5. package/dist/lexer.js +74 -0
  6. package/dist/main.js +82 -7
  7. package/dist/parser.js +71 -0
  8. package/dist/qasm2/ast.js +33 -0
  9. package/dist/qasm2/lexer.js +54 -1
  10. package/dist/qasm2/parser.js +51 -1
  11. package/dist/qasm2/token.js +30 -0
  12. package/dist/qasm3/lexer.js +59 -1
  13. package/dist/qasm3/parser.js +55 -2
  14. package/dist/qasm3/token.js +93 -10
  15. package/dist/version.js +17 -1
  16. package/docs/assets/hierarchy.js +1 -0
  17. package/docs/custom.css +3 -0
  18. package/docs/docs-readme.md +208 -0
  19. package/docs/index.html +17 -55
  20. package/docs/typedoc/assets/custom.css +3 -0
  21. package/docs/typedoc/assets/hierarchy.js +1 -0
  22. package/docs/{assets → typedoc/assets}/highlight.css +20 -20
  23. package/docs/{assets → typedoc/assets}/icons.js +1 -1
  24. package/docs/{assets → typedoc/assets}/icons.svg +1 -1
  25. package/docs/typedoc/assets/main.js +60 -0
  26. package/docs/typedoc/assets/navigation.js +1 -0
  27. package/docs/typedoc/assets/search.js +1 -0
  28. package/docs/typedoc/assets/style.css +1633 -0
  29. package/docs/typedoc/classes/Error_Handling.BadArgumentError.html +12 -0
  30. package/docs/typedoc/classes/Error_Handling.BadBarrierError.html +12 -0
  31. package/docs/typedoc/classes/Error_Handling.BadClassicalTypeError.html +12 -0
  32. package/docs/typedoc/classes/Error_Handling.BadConditionalError.html +12 -0
  33. package/docs/typedoc/classes/Error_Handling.BadCregError.html +12 -0
  34. package/docs/typedoc/classes/Error_Handling.BadEqualsError.html +12 -0
  35. package/docs/typedoc/classes/Error_Handling.BadExpressionError.html +12 -0
  36. package/docs/typedoc/classes/Error_Handling.BadGateError.html +12 -0
  37. package/docs/typedoc/classes/Error_Handling.BadIncludeError.html +12 -0
  38. package/docs/typedoc/classes/Error_Handling.BadLoopError.html +12 -0
  39. package/docs/typedoc/classes/Error_Handling.BadMeasurementError.html +12 -0
  40. package/docs/typedoc/classes/Error_Handling.BadParameterError.html +12 -0
  41. package/docs/typedoc/classes/Error_Handling.BadQregError.html +12 -0
  42. package/docs/typedoc/classes/Error_Handling.BadQuantumInstructionError.html +12 -0
  43. package/docs/typedoc/classes/Error_Handling.BadStringLiteralError.html +12 -0
  44. package/docs/typedoc/classes/Error_Handling.BadSubroutineError.html +12 -0
  45. package/docs/typedoc/classes/Error_Handling.MissingBraceError.html +12 -0
  46. package/docs/typedoc/classes/Error_Handling.MissingSemicolonError.html +12 -0
  47. package/docs/typedoc/classes/Error_Handling.UnsupportedOpenQASMVersionError.html +12 -0
  48. package/docs/typedoc/classes/Version_Management.OpenQASMVersion.html +16 -0
  49. package/docs/typedoc/classes/qasm2_ast.ApplyGate.html +6 -0
  50. package/docs/typedoc/classes/qasm2_ast.AstNode.html +3 -0
  51. package/docs/typedoc/classes/qasm2_ast.Barrier.html +5 -0
  52. package/docs/typedoc/classes/qasm2_ast.CReg.html +5 -0
  53. package/docs/typedoc/classes/qasm2_ast.Cos.html +3 -0
  54. package/docs/typedoc/classes/qasm2_ast.Divide.html +3 -0
  55. package/docs/typedoc/classes/qasm2_ast.Exp.html +3 -0
  56. package/docs/typedoc/classes/qasm2_ast.Gate.html +7 -0
  57. package/docs/typedoc/classes/qasm2_ast.Id.html +4 -0
  58. package/docs/typedoc/classes/qasm2_ast.If.html +6 -0
  59. package/docs/typedoc/classes/qasm2_ast.Include.html +4 -0
  60. package/docs/typedoc/classes/qasm2_ast.Ln.html +3 -0
  61. package/docs/typedoc/classes/qasm2_ast.Measure.html +7 -0
  62. package/docs/typedoc/classes/qasm2_ast.Minus.html +3 -0
  63. package/docs/typedoc/classes/qasm2_ast.NNInteger.html +4 -0
  64. package/docs/typedoc/classes/qasm2_ast.Opaque.html +6 -0
  65. package/docs/typedoc/classes/qasm2_ast.Pi.html +3 -0
  66. package/docs/typedoc/classes/qasm2_ast.Plus.html +3 -0
  67. package/docs/typedoc/classes/qasm2_ast.Power.html +3 -0
  68. package/docs/typedoc/classes/qasm2_ast.QReg.html +5 -0
  69. package/docs/typedoc/classes/qasm2_ast.Real.html +4 -0
  70. package/docs/typedoc/classes/qasm2_ast.Sin.html +3 -0
  71. package/docs/typedoc/classes/qasm2_ast.Sqrt.html +3 -0
  72. package/docs/typedoc/classes/qasm2_ast.Tan.html +3 -0
  73. package/docs/typedoc/classes/qasm2_ast.Times.html +3 -0
  74. package/docs/typedoc/classes/qasm2_ast.Variable.html +4 -0
  75. package/docs/typedoc/classes/qasm2_ast.Version.html +4 -0
  76. package/docs/typedoc/classes/qasm2_lexer.default.html +57 -0
  77. package/docs/typedoc/classes/qasm2_parser.default.html +93 -0
  78. package/docs/typedoc/classes/qasm3_ast.AliasStatement.html +5 -0
  79. package/docs/typedoc/classes/qasm3_ast.AngleType.html +4 -0
  80. package/docs/typedoc/classes/qasm3_ast.Arithmetic.html +6 -0
  81. package/docs/typedoc/classes/qasm3_ast.ArrayAccess.html +5 -0
  82. package/docs/typedoc/classes/qasm3_ast.ArrayDeclaration.html +7 -0
  83. package/docs/typedoc/classes/qasm3_ast.ArrayInitializer.html +4 -0
  84. package/docs/typedoc/classes/qasm3_ast.ArrayReference.html +5 -0
  85. package/docs/typedoc/classes/qasm3_ast.AssignmentStatement.html +5 -0
  86. package/docs/typedoc/classes/qasm3_ast.AstNode.html +3 -0
  87. package/docs/typedoc/classes/qasm3_ast.Binary.html +6 -0
  88. package/docs/typedoc/classes/qasm3_ast.BitType.html +4 -0
  89. package/docs/typedoc/classes/qasm3_ast.BitstringLiteral.html +4 -0
  90. package/docs/typedoc/classes/qasm3_ast.BoolType.html +3 -0
  91. package/docs/typedoc/classes/qasm3_ast.BooleanLiteral.html +4 -0
  92. package/docs/typedoc/classes/qasm3_ast.BoxDefinition.html +7 -0
  93. package/docs/typedoc/classes/qasm3_ast.BranchingStatement.html +8 -0
  94. package/docs/typedoc/classes/qasm3_ast.BreakStatement.html +3 -0
  95. package/docs/typedoc/classes/qasm3_ast.CalibrationGrammarDeclaration.html +6 -0
  96. package/docs/typedoc/classes/qasm3_ast.CaseStatement.html +5 -0
  97. package/docs/typedoc/classes/qasm3_ast.Cast.html +5 -0
  98. package/docs/typedoc/classes/qasm3_ast.ClassicalDeclaration.html +7 -0
  99. package/docs/typedoc/classes/qasm3_ast.ClassicalType.html +3 -0
  100. package/docs/typedoc/classes/qasm3_ast.ComplexType.html +6 -0
  101. package/docs/typedoc/classes/qasm3_ast.ContinueStatement.html +3 -0
  102. package/docs/typedoc/classes/qasm3_ast.DefaultStatement.html +4 -0
  103. package/docs/typedoc/classes/qasm3_ast.DurationLiteral.html +5 -0
  104. package/docs/typedoc/classes/qasm3_ast.DurationOf.html +4 -0
  105. package/docs/typedoc/classes/qasm3_ast.DurationType.html +3 -0
  106. package/docs/typedoc/classes/qasm3_ast.Euler.html +3 -0
  107. package/docs/typedoc/classes/qasm3_ast.Expression.html +3 -0
  108. package/docs/typedoc/classes/qasm3_ast.ExternSignature.html +8 -0
  109. package/docs/typedoc/classes/qasm3_ast.FloatLiteral.html +4 -0
  110. package/docs/typedoc/classes/qasm3_ast.FloatType.html +6 -0
  111. package/docs/typedoc/classes/qasm3_ast.ForLoopStatement.html +12 -0
  112. package/docs/typedoc/classes/qasm3_ast.HardwareQubit.html +5 -0
  113. package/docs/typedoc/classes/qasm3_ast.IODeclaration.html +5 -0
  114. package/docs/typedoc/classes/qasm3_ast.Identifier.html +4 -0
  115. package/docs/typedoc/classes/qasm3_ast.ImaginaryLiteral.html +4 -0
  116. package/docs/typedoc/classes/qasm3_ast.Include.html +6 -0
  117. package/docs/typedoc/classes/qasm3_ast.IndexSet.html +5 -0
  118. package/docs/typedoc/classes/qasm3_ast.IntType.html +4 -0
  119. package/docs/typedoc/classes/qasm3_ast.IntegerLiteral.html +4 -0
  120. package/docs/typedoc/classes/qasm3_ast.MathFunction.html +5 -0
  121. package/docs/typedoc/classes/qasm3_ast.NumericLiteral.html +4 -0
  122. package/docs/typedoc/classes/qasm3_ast.Parameters.html +4 -0
  123. package/docs/typedoc/classes/qasm3_ast.Pi.html +3 -0
  124. package/docs/typedoc/classes/qasm3_ast.ProgramBlock.html +7 -0
  125. package/docs/typedoc/classes/qasm3_ast.QuantumBarrier.html +6 -0
  126. package/docs/typedoc/classes/qasm3_ast.QuantumBlock.html +6 -0
  127. package/docs/typedoc/classes/qasm3_ast.QuantumDeclaration.html +8 -0
  128. package/docs/typedoc/classes/qasm3_ast.QuantumDelay.html +5 -0
  129. package/docs/typedoc/classes/qasm3_ast.QuantumGateCall.html +9 -0
  130. package/docs/typedoc/classes/qasm3_ast.QuantumGateDefinition.html +9 -0
  131. package/docs/typedoc/classes/qasm3_ast.QuantumGateModifier.html +5 -0
  132. package/docs/typedoc/classes/qasm3_ast.QuantumMeasurement.html +6 -0
  133. package/docs/typedoc/classes/qasm3_ast.QuantumMeasurementAssignment.html +8 -0
  134. package/docs/typedoc/classes/qasm3_ast.QuantumReset.html +4 -0
  135. package/docs/typedoc/classes/qasm3_ast.Range.html +6 -0
  136. package/docs/typedoc/classes/qasm3_ast.ReturnStatement.html +4 -0
  137. package/docs/typedoc/classes/qasm3_ast.SizeOf.html +5 -0
  138. package/docs/typedoc/classes/qasm3_ast.Statement.html +12 -0
  139. package/docs/typedoc/classes/qasm3_ast.StretchType.html +3 -0
  140. package/docs/typedoc/classes/qasm3_ast.SubroutineBlock.html +6 -0
  141. package/docs/typedoc/classes/qasm3_ast.SubroutineCall.html +5 -0
  142. package/docs/typedoc/classes/qasm3_ast.SubroutineDefinition.html +10 -0
  143. package/docs/typedoc/classes/qasm3_ast.SubscriptedIdentifier.html +5 -0
  144. package/docs/typedoc/classes/qasm3_ast.SwitchStatement.html +6 -0
  145. package/docs/typedoc/classes/qasm3_ast.Tau.html +3 -0
  146. package/docs/typedoc/classes/qasm3_ast.TrigFunction.html +5 -0
  147. package/docs/typedoc/classes/qasm3_ast.UIntType.html +4 -0
  148. package/docs/typedoc/classes/qasm3_ast.Unary.html +5 -0
  149. package/docs/typedoc/classes/qasm3_ast.Version.html +6 -0
  150. package/docs/typedoc/classes/qasm3_ast.WhileLoopStatement.html +6 -0
  151. package/docs/typedoc/classes/qasm3_lexer.default.html +71 -0
  152. package/docs/typedoc/classes/qasm3_parser.default.html +237 -0
  153. package/docs/typedoc/enums/Version_Management.OpenQASMMajorVersion.html +4 -0
  154. package/docs/typedoc/enums/qasm2_token.Token.html +42 -0
  155. package/docs/typedoc/enums/qasm3_ast.ArithmeticOp.html +9 -0
  156. package/docs/typedoc/enums/qasm3_ast.ArrayReferenceModifier.html +4 -0
  157. package/docs/typedoc/enums/qasm3_ast.BinaryOp.html +15 -0
  158. package/docs/typedoc/enums/qasm3_ast.DurationUnit.html +7 -0
  159. package/docs/typedoc/enums/qasm3_ast.IOModifier.html +4 -0
  160. package/docs/typedoc/enums/qasm3_ast.MathFunctionTypes.html +12 -0
  161. package/docs/typedoc/enums/qasm3_ast.QuantumGateModifierName.html +6 -0
  162. package/docs/typedoc/enums/qasm3_ast.TrigFunctionTypes.html +8 -0
  163. package/docs/typedoc/enums/qasm3_ast.UnaryOp.html +5 -0
  164. package/docs/typedoc/enums/qasm3_token.Token.html +113 -0
  165. package/docs/typedoc/functions/Lexing.lex.html +24 -0
  166. package/docs/typedoc/functions/Main_Functions.parseFile.html +13 -0
  167. package/docs/typedoc/functions/Main_Functions.parseString.html +19 -0
  168. package/docs/typedoc/functions/Parsing.parse.html +15 -0
  169. package/docs/typedoc/functions/qasm2_token.inverseLookup.html +3 -0
  170. package/docs/typedoc/functions/qasm2_token.lookup.html +4 -0
  171. package/docs/typedoc/functions/qasm2_token.notParam.html +3 -0
  172. package/docs/typedoc/functions/qasm3_token.inverseLookup.html +9 -0
  173. package/docs/typedoc/functions/qasm3_token.lookup.html +10 -0
  174. package/docs/typedoc/functions/qasm3_token.notParam.html +11 -0
  175. package/docs/typedoc/hierarchy.html +1 -0
  176. package/docs/typedoc/index.html +76 -0
  177. package/docs/typedoc/modules/Error_Handling.html +5 -0
  178. package/docs/typedoc/modules/Lexing.html +20 -0
  179. package/docs/typedoc/modules/Main_Functions.html +2 -0
  180. package/docs/typedoc/modules/Parsing.html +24 -0
  181. package/docs/typedoc/modules/Version_Management.html +8 -0
  182. package/docs/typedoc/modules/qasm2_ast.html +22 -0
  183. package/docs/typedoc/modules/qasm2_lexer.html +24 -0
  184. package/docs/typedoc/modules/qasm2_parser.html +21 -0
  185. package/docs/typedoc/modules/qasm2_token.html +15 -0
  186. package/docs/typedoc/modules/qasm3_ast.html +26 -0
  187. package/docs/typedoc/modules/qasm3_lexer.html +25 -0
  188. package/docs/typedoc/modules/qasm3_parser.html +25 -0
  189. package/docs/typedoc/modules/qasm3_token.html +15 -0
  190. package/docs/typedoc/modules.html +1 -0
  191. package/docs/typedoc/types/Error_Handling.ReturnErrorConstructor.html +2 -0
  192. package/docs/typedoc.json +47 -0
  193. package/package.json +6 -2
  194. package/paper/jats/paper.jats +464 -0
  195. package/paper/main.bib +191 -0
  196. package/paper/paper.md +166 -0
  197. package/paper/paper.pdf +0 -0
  198. package/readme.md +63 -9
  199. package/docs/assets/main.js +0 -60
  200. package/docs/assets/navigation.js +0 -1
  201. package/docs/assets/search.js +0 -1
  202. package/docs/assets/style.css +0 -1493
  203. package/docs/classes/errors.BadArgumentError.html +0 -12
  204. package/docs/classes/errors.BadBarrierError.html +0 -12
  205. package/docs/classes/errors.BadClassicalTypeError.html +0 -12
  206. package/docs/classes/errors.BadConditionalError.html +0 -12
  207. package/docs/classes/errors.BadCregError.html +0 -12
  208. package/docs/classes/errors.BadEqualsError.html +0 -12
  209. package/docs/classes/errors.BadExpressionError.html +0 -12
  210. package/docs/classes/errors.BadGateError.html +0 -12
  211. package/docs/classes/errors.BadIncludeError.html +0 -12
  212. package/docs/classes/errors.BadLoopError.html +0 -12
  213. package/docs/classes/errors.BadMeasurementError.html +0 -12
  214. package/docs/classes/errors.BadParameterError.html +0 -12
  215. package/docs/classes/errors.BadQregError.html +0 -12
  216. package/docs/classes/errors.BadQuantumInstructionError.html +0 -12
  217. package/docs/classes/errors.BadStringLiteralError.html +0 -12
  218. package/docs/classes/errors.BadSubroutineError.html +0 -12
  219. package/docs/classes/errors.MissingBraceError.html +0 -12
  220. package/docs/classes/errors.MissingSemicolonError.html +0 -12
  221. package/docs/classes/errors.UnsupportedOpenQASMVersionError.html +0 -12
  222. package/docs/classes/qasm2_ast.ApplyGate.html +0 -6
  223. package/docs/classes/qasm2_ast.AstNode.html +0 -3
  224. package/docs/classes/qasm2_ast.Barrier.html +0 -5
  225. package/docs/classes/qasm2_ast.CReg.html +0 -5
  226. package/docs/classes/qasm2_ast.Cos.html +0 -3
  227. package/docs/classes/qasm2_ast.Divide.html +0 -3
  228. package/docs/classes/qasm2_ast.Exp.html +0 -3
  229. package/docs/classes/qasm2_ast.Gate.html +0 -7
  230. package/docs/classes/qasm2_ast.Id.html +0 -4
  231. package/docs/classes/qasm2_ast.If.html +0 -6
  232. package/docs/classes/qasm2_ast.Include.html +0 -4
  233. package/docs/classes/qasm2_ast.Ln.html +0 -3
  234. package/docs/classes/qasm2_ast.Measure.html +0 -7
  235. package/docs/classes/qasm2_ast.Minus.html +0 -3
  236. package/docs/classes/qasm2_ast.NNInteger.html +0 -4
  237. package/docs/classes/qasm2_ast.Opaque.html +0 -6
  238. package/docs/classes/qasm2_ast.Pi.html +0 -3
  239. package/docs/classes/qasm2_ast.Plus.html +0 -3
  240. package/docs/classes/qasm2_ast.Power.html +0 -3
  241. package/docs/classes/qasm2_ast.QReg.html +0 -5
  242. package/docs/classes/qasm2_ast.Real.html +0 -4
  243. package/docs/classes/qasm2_ast.Sin.html +0 -3
  244. package/docs/classes/qasm2_ast.Sqrt.html +0 -3
  245. package/docs/classes/qasm2_ast.Tan.html +0 -3
  246. package/docs/classes/qasm2_ast.Times.html +0 -3
  247. package/docs/classes/qasm2_ast.Variable.html +0 -4
  248. package/docs/classes/qasm2_ast.Version.html +0 -4
  249. package/docs/classes/qasm2_lexer.default.html +0 -50
  250. package/docs/classes/qasm2_parser.default.html +0 -87
  251. package/docs/classes/qasm3_ast.AliasStatement.html +0 -5
  252. package/docs/classes/qasm3_ast.AngleType.html +0 -4
  253. package/docs/classes/qasm3_ast.Arithmetic.html +0 -6
  254. package/docs/classes/qasm3_ast.ArrayAccess.html +0 -5
  255. package/docs/classes/qasm3_ast.ArrayDeclaration.html +0 -7
  256. package/docs/classes/qasm3_ast.ArrayInitializer.html +0 -4
  257. package/docs/classes/qasm3_ast.ArrayReference.html +0 -5
  258. package/docs/classes/qasm3_ast.AssignmentStatement.html +0 -5
  259. package/docs/classes/qasm3_ast.AstNode.html +0 -3
  260. package/docs/classes/qasm3_ast.Binary.html +0 -6
  261. package/docs/classes/qasm3_ast.BitType.html +0 -4
  262. package/docs/classes/qasm3_ast.BitstringLiteral.html +0 -4
  263. package/docs/classes/qasm3_ast.BoolType.html +0 -3
  264. package/docs/classes/qasm3_ast.BooleanLiteral.html +0 -4
  265. package/docs/classes/qasm3_ast.BoxDefinition.html +0 -7
  266. package/docs/classes/qasm3_ast.BranchingStatement.html +0 -8
  267. package/docs/classes/qasm3_ast.BreakStatement.html +0 -3
  268. package/docs/classes/qasm3_ast.CalibrationGrammarDeclaration.html +0 -6
  269. package/docs/classes/qasm3_ast.CaseStatement.html +0 -5
  270. package/docs/classes/qasm3_ast.Cast.html +0 -5
  271. package/docs/classes/qasm3_ast.ClassicalDeclaration.html +0 -7
  272. package/docs/classes/qasm3_ast.ClassicalType.html +0 -3
  273. package/docs/classes/qasm3_ast.ComplexType.html +0 -6
  274. package/docs/classes/qasm3_ast.ContinueStatement.html +0 -3
  275. package/docs/classes/qasm3_ast.DefaultStatement.html +0 -4
  276. package/docs/classes/qasm3_ast.DurationLiteral.html +0 -5
  277. package/docs/classes/qasm3_ast.DurationOf.html +0 -4
  278. package/docs/classes/qasm3_ast.DurationType.html +0 -3
  279. package/docs/classes/qasm3_ast.Euler.html +0 -3
  280. package/docs/classes/qasm3_ast.Expression.html +0 -3
  281. package/docs/classes/qasm3_ast.ExternSignature.html +0 -8
  282. package/docs/classes/qasm3_ast.FloatLiteral.html +0 -4
  283. package/docs/classes/qasm3_ast.FloatType.html +0 -6
  284. package/docs/classes/qasm3_ast.ForLoopStatement.html +0 -12
  285. package/docs/classes/qasm3_ast.HardwareQubit.html +0 -5
  286. package/docs/classes/qasm3_ast.IODeclaration.html +0 -5
  287. package/docs/classes/qasm3_ast.Identifier.html +0 -4
  288. package/docs/classes/qasm3_ast.ImaginaryLiteral.html +0 -4
  289. package/docs/classes/qasm3_ast.Include.html +0 -6
  290. package/docs/classes/qasm3_ast.IndexSet.html +0 -5
  291. package/docs/classes/qasm3_ast.IntType.html +0 -4
  292. package/docs/classes/qasm3_ast.IntegerLiteral.html +0 -4
  293. package/docs/classes/qasm3_ast.MathFunction.html +0 -5
  294. package/docs/classes/qasm3_ast.NumericLiteral.html +0 -4
  295. package/docs/classes/qasm3_ast.Parameters.html +0 -4
  296. package/docs/classes/qasm3_ast.Pi.html +0 -3
  297. package/docs/classes/qasm3_ast.ProgramBlock.html +0 -7
  298. package/docs/classes/qasm3_ast.QuantumBarrier.html +0 -6
  299. package/docs/classes/qasm3_ast.QuantumBlock.html +0 -6
  300. package/docs/classes/qasm3_ast.QuantumDeclaration.html +0 -8
  301. package/docs/classes/qasm3_ast.QuantumDelay.html +0 -5
  302. package/docs/classes/qasm3_ast.QuantumGateCall.html +0 -9
  303. package/docs/classes/qasm3_ast.QuantumGateDefinition.html +0 -9
  304. package/docs/classes/qasm3_ast.QuantumGateModifier.html +0 -5
  305. package/docs/classes/qasm3_ast.QuantumMeasurement.html +0 -6
  306. package/docs/classes/qasm3_ast.QuantumMeasurementAssignment.html +0 -8
  307. package/docs/classes/qasm3_ast.QuantumReset.html +0 -4
  308. package/docs/classes/qasm3_ast.Range.html +0 -6
  309. package/docs/classes/qasm3_ast.ReturnStatement.html +0 -4
  310. package/docs/classes/qasm3_ast.SizeOf.html +0 -5
  311. package/docs/classes/qasm3_ast.Statement.html +0 -12
  312. package/docs/classes/qasm3_ast.StretchType.html +0 -3
  313. package/docs/classes/qasm3_ast.SubroutineBlock.html +0 -6
  314. package/docs/classes/qasm3_ast.SubroutineCall.html +0 -5
  315. package/docs/classes/qasm3_ast.SubroutineDefinition.html +0 -10
  316. package/docs/classes/qasm3_ast.SubscriptedIdentifier.html +0 -5
  317. package/docs/classes/qasm3_ast.SwitchStatement.html +0 -6
  318. package/docs/classes/qasm3_ast.Tau.html +0 -3
  319. package/docs/classes/qasm3_ast.TrigFunction.html +0 -5
  320. package/docs/classes/qasm3_ast.UIntType.html +0 -4
  321. package/docs/classes/qasm3_ast.Unary.html +0 -5
  322. package/docs/classes/qasm3_ast.Version.html +0 -6
  323. package/docs/classes/qasm3_ast.WhileLoopStatement.html +0 -6
  324. package/docs/classes/qasm3_lexer.default.html +0 -60
  325. package/docs/classes/qasm3_parser.default.html +0 -227
  326. package/docs/classes/version.OpenQASMVersion.html +0 -16
  327. package/docs/enums/qasm2_token.Token.html +0 -39
  328. package/docs/enums/qasm3_ast.ArithmeticOp.html +0 -9
  329. package/docs/enums/qasm3_ast.ArrayReferenceModifier.html +0 -4
  330. package/docs/enums/qasm3_ast.BinaryOp.html +0 -15
  331. package/docs/enums/qasm3_ast.DurationUnit.html +0 -7
  332. package/docs/enums/qasm3_ast.IOModifier.html +0 -4
  333. package/docs/enums/qasm3_ast.MathFunctionTypes.html +0 -12
  334. package/docs/enums/qasm3_ast.QuantumGateModifierName.html +0 -6
  335. package/docs/enums/qasm3_ast.TrigFunctionTypes.html +0 -8
  336. package/docs/enums/qasm3_ast.UnaryOp.html +0 -5
  337. package/docs/enums/qasm3_token.Token.html +0 -101
  338. package/docs/enums/version.OpenQASMMajorVersion.html +0 -4
  339. package/docs/functions/lexer.lex.html +0 -1
  340. package/docs/functions/main.parseFile.html +0 -4
  341. package/docs/functions/main.parseString.html +0 -4
  342. package/docs/functions/parser.parse.html +0 -1
  343. package/docs/functions/qasm2_token.inverseLookup.html +0 -3
  344. package/docs/functions/qasm2_token.lookup.html +0 -4
  345. package/docs/functions/qasm2_token.notParam.html +0 -3
  346. package/docs/functions/qasm3_token.inverseLookup.html +0 -3
  347. package/docs/functions/qasm3_token.lookup.html +0 -4
  348. package/docs/functions/qasm3_token.notParam.html +0 -3
  349. package/docs/hierarchy.html +0 -1
  350. package/docs/modules/errors.html +0 -21
  351. package/docs/modules/lexer.html +0 -2
  352. package/docs/modules/main.html +0 -3
  353. package/docs/modules/parser.html +0 -2
  354. package/docs/modules/qasm2_ast.html +0 -28
  355. package/docs/modules/qasm2_lexer.html +0 -2
  356. package/docs/modules/qasm2_parser.html +0 -2
  357. package/docs/modules/qasm2_token.html +0 -5
  358. package/docs/modules/qasm3_ast.html +0 -83
  359. package/docs/modules/qasm3_lexer.html +0 -2
  360. package/docs/modules/qasm3_parser.html +0 -2
  361. package/docs/modules/qasm3_token.html +0 -5
  362. package/docs/modules/version.html +0 -3
  363. package/docs/modules.html +0 -14
  364. package/docs/types/errors.ReturnErrorConstructor.html +0 -2
  365. /package/docs/{.nojekyll → typedoc/.nojekyll} +0 -0
@@ -1,10 +1,60 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM 2.0 Parser Implementation
4
+ *
5
+ * This module implements a parser for OpenQASM 2.0 that focuses on the core
6
+ * quantum circuit description language without the advanced features of version 3.0.
7
+ * The parser handles quantum and classical register declarations, gate definitions
8
+ * and applications, measurements, and basic control structures.
9
+ *
10
+ * OpenQASM 2.0 parsing capabilities:
11
+ * - **Register declarations**: qreg and creg with size specifications
12
+ * - **Gate definitions**: Custom gate definitions with parameters and bodies
13
+ * - **Gate applications**: Built-in and custom gate applications
14
+ * - **Measurements**: Quantum measurements with classical result storage
15
+ * - **Basic conditionals**: Simple if statements based on classical register values
16
+ * - **Arithmetic expressions**: Parameter expressions for gate operations
17
+ * - **Opaque gates**: External gate declarations
18
+ *
19
+ * The parser maintains a list of known gates and validates gate applications
20
+ * against declared gates and built-in operations.
21
+ *
22
+ * @module
23
+ *
24
+ * @example Parsing OpenQASM 2.0 code
25
+ * ```typescript
26
+ * const tokens = lexer.lex();
27
+ * const parser = new Parser(tokens);
28
+ * const ast = parser.parse();
29
+ *
30
+ * // AST contains simplified node structure for OpenQASM 2.0
31
+ * ```
32
+ */
2
33
  Object.defineProperty(exports, "__esModule", { value: true });
3
34
  var token_1 = require("./token");
4
35
  var version_1 = require("../version");
5
36
  var errors_1 = require("../errors");
6
37
  var ast_1 = require("./ast");
7
- /** Class representing a token parser. */
38
+ /**
39
+ * OpenQASM 2.0 Parser
40
+ *
41
+ * A straightforward recursive descent parser for OpenQASM 2.0 that produces
42
+ * a simplified AST structure appropriate for the more limited feature set
43
+ * of the 2.0 language specification.
44
+ *
45
+ * @example Basic parsing workflow
46
+ * ```typescript
47
+ * const parser = new Parser(tokens);
48
+ * const ast = parser.parse();
49
+ *
50
+ * // Process the resulting AST nodes
51
+ * ast.forEach(node => {
52
+ * if (node instanceof QReg) {
53
+ * console.log(`Quantum register: ${node.id}[${node.size}]`);
54
+ * }
55
+ * });
56
+ * ```
57
+ */
8
58
  var Parser = /** @class */ (function () {
9
59
  /**
10
60
  * Creates a parser.
@@ -1,9 +1,39 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM 2.0 Token Definitions and Utilities
4
+ *
5
+ * This module defines the token types used in OpenQASM 2.0 syntax. OpenQASM 2.0
6
+ * has a simpler token set compared to 3.0, focusing on basic quantum operations
7
+ * and classical registers without advanced control flow or data types.
8
+ *
9
+ * Key differences from OpenQASM 3.0:
10
+ * - Limited to `qreg` and `creg` declarations (no advanced types)
11
+ * - No control flow tokens (if/else/for/while)
12
+ * - No subroutine or function definitions
13
+ * - Simpler expression and operator support
14
+ *
15
+ * @module
16
+ *
17
+ * @example OpenQASM 2.0 token usage
18
+ * ```typescript
19
+ * import { lookup, Token } from './qasm2/token';
20
+ *
21
+ * console.log(lookup('qreg')); // Token.QReg
22
+ * console.log(lookup('barrier')); // Token.Barrier
23
+ * console.log(lookup('measure')); // Token.Measure
24
+ * ```
25
+ */
2
26
  Object.defineProperty(exports, "__esModule", { value: true });
3
27
  exports.Token = void 0;
4
28
  exports.notParam = notParam;
5
29
  exports.lookup = lookup;
6
30
  exports.inverseLookup = inverseLookup;
31
+ /**
32
+ * Enumeration of OpenQASM 2.0 token types.
33
+ *
34
+ * This simplified token set reflects OpenQASM 2.0's focus on basic quantum
35
+ * circuit description without the advanced features of version 3.0.
36
+ */
7
37
  var Token;
8
38
  (function (Token) {
9
39
  // 0; invalid or unrecognized token
@@ -1,6 +1,40 @@
1
1
  "use strict";
2
2
  /* eslint-disable no-useless-escape */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * OpenQASM 3.0 Lexical Analyzer
6
+ *
7
+ * This module implements the lexer for OpenQASM 3.0, which transforms source code
8
+ * into a stream of tokens. The lexer handles the significantly expanded syntax of
9
+ * OpenQASM 3.0, including classical programming constructs, control flow, and
10
+ * advanced quantum features.
11
+ *
12
+ * Key features of the OpenQASM 3.0 lexer:
13
+ * - **Extended token set**: Classical types, control flow, functions
14
+ * - **Complex operators**: Compound assignment, bitwise operations
15
+ * - **Advanced literals**: Scientific notation, binary/hex/octal, durations
16
+ * - **Gate modifiers**: ctrl, negctrl, inv, pow with @ syntax
17
+ * - **Unicode support**: Mathematical constants (π, ℇ, τ)
18
+ * - **Robust error handling**: Detailed syntax error reporting
19
+ *
20
+ * The lexer performs several validation passes:
21
+ * - Semicolon verification for statement termination
22
+ * - Comment handling (single-line // and multi-line /* *\/)
23
+ * - String literal parsing with multiple quote styles
24
+ * - Number format validation and conversion
25
+ *
26
+ * @module
27
+ *
28
+ * @example Basic lexing process
29
+ * ```typescript
30
+ * const lexer = new Lexer('qubit[2] q; h q[0];');
31
+ * const tokens = lexer.lex();
32
+ * // Returns: [
33
+ * // [Token.Id, 'qubit'], [Token.LSParen], [Token.NNInteger, 2],
34
+ * // [Token.RSParen], [Token.Id, 'q'], [Token.Semicolon], ...
35
+ * // ]
36
+ * ```
37
+ */
4
38
  var token_1 = require("./token");
5
39
  var errors_1 = require("../errors");
6
40
  /**
@@ -69,7 +103,31 @@ function isAlpha(c) {
69
103
  function isNewline(c) {
70
104
  return /\n|\r(?!\n)|\u2028|\u2029|\r\n/.test(c);
71
105
  }
72
- /** Class representing a lexer. */
106
+ /**
107
+ * OpenQASM 3.0 Lexical Analyzer
108
+ *
109
+ * The main lexer class that processes OpenQASM 3.0 source code character by
110
+ * character and produces a stream of tokens for the parser to consume.
111
+ *
112
+ * The lexer maintains state including:
113
+ * - Current cursor position in the input
114
+ * - Input validation status
115
+ * - Error reporting context
116
+ *
117
+ * @example Creating and using a lexer
118
+ * ```typescript
119
+ * const source = `
120
+ * OPENQASM 3.0;
121
+ * include "stdgates.inc";
122
+ * qubit[2] q;
123
+ * h q[0];
124
+ * cx q[0], q[1];
125
+ * `;
126
+ *
127
+ * const lexer = new Lexer(source);
128
+ * const tokens = lexer.lex();
129
+ * ```
130
+ */
73
131
  var Lexer = /** @class */ (function () {
74
132
  /**
75
133
  * Creates a lexer.
@@ -1,6 +1,37 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * OpenQASM 3.0 Parser Implementation
6
+ *
7
+ * This module implements a recursive descent parser for OpenQASM 3.0 that transforms
8
+ * a stream of tokens into an Abstract Syntax Tree (AST). The parser handles the full
9
+ * OpenQASM 3.0 language specification including classical programming constructs,
10
+ * control flow, quantum operations, and advanced features.
11
+ *
12
+ * Key parsing capabilities:
13
+ * - **Classical types**: int, uint, float, bool, bit, complex, angle
14
+ * - **Control flow**: if/else, for/while loops, switch/case statements
15
+ * - **Functions**: def, return, extern declarations, subroutine calls
16
+ * - **Quantum operations**: gate definitions/calls, measurements, barriers, delays
17
+ * - **Advanced features**: arrays, timing constructs, calibration grammar
18
+ * - **Expressions**: Arithmetic, logical, function calls with proper precedence
19
+ *
20
+ * The parser maintains context about:
21
+ * - Defined gates (built-in, standard library, custom)
22
+ * - Declared subroutines and external functions
23
+ * - Array declarations and aliases
24
+ * - Type information for validation
25
+ *
26
+ * @module
27
+ *
28
+ * @example Basic parsing workflow
29
+ * ```typescript
30
+ * const tokens = lexer.lex();
31
+ * const parser = new Parser(tokens);
32
+ * const ast = parser.parse();
33
+ * ```
34
+ */
4
35
  var token_1 = require("./token");
5
36
  var version_1 = require("../version");
6
37
  var errors_1 = require("../errors");
@@ -18,7 +49,29 @@ function throwParserError(error, token, index, message) {
18
49
  : "index: ".concat(index, " at token [").concat(token, "]");
19
50
  throw new error(errorMessage);
20
51
  }
21
- /** Class representing a token parser. */
52
+ /**
53
+ * OpenQASM 3.0 Recursive Descent Parser
54
+ *
55
+ * Implements a comprehensive parser for the OpenQASM 3.0 language specification.
56
+ * The parser uses recursive descent parsing with appropriate error recovery and
57
+ * maintains symbol tables for gates, subroutines, and variables.
58
+ *
59
+ * Parser state includes:
60
+ * - Token stream and current position
61
+ * - Symbol tables for gates, subroutines, arrays, aliases
62
+ * - Machine-specific defaults (float width, int size)
63
+ *
64
+ * @example Creating and using the parser
65
+ * ```typescript
66
+ * const parser = new Parser(tokens);
67
+ *
68
+ * // Parse the entire program
69
+ * const ast = parser.parse();
70
+ *
71
+ * // AST contains array of top-level statements and declarations
72
+ * console.log(ast); // [VersionNode, IncludeNode, DeclarationNode, ...]
73
+ * ```
74
+ */
22
75
  var Parser = /** @class */ (function () {
23
76
  /**
24
77
  * Creates a parser.
@@ -1872,7 +1925,7 @@ var Parser = /** @class */ (function () {
1872
1925
  /**
1873
1926
  * Creates a classical type.
1874
1927
  * @param token - The token that represents the type.
1875
- * @width - The type's width or size, if applicable.
1928
+ * @param width - The type's width or size, if applicable.
1876
1929
  * @return The created ClassicalType.
1877
1930
  */
1878
1931
  Parser.prototype.createClassicalType = function (token, width) {
@@ -1,9 +1,46 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM 3.0 Token Definitions and Utilities
4
+ *
5
+ * This module defines all the token types used in OpenQASM 3.0 syntax, which
6
+ * significantly extends OpenQASM 2.0 with modern programming language features.
7
+ *
8
+ * Major additions in OpenQASM 3.0:
9
+ * - **Classical types**: int, uint, float, bool, bit, complex
10
+ * - **Control flow**: if/else, for/while loops, switch/case
11
+ * - **Functions**: def, return, extern declarations
12
+ * - **Advanced features**: arrays, timing (delay, durationof), calibration
13
+ * - **Quantum extensions**: qubit declarations, gate modifiers, hardware qubits
14
+ *
15
+ * @module
16
+ *
17
+ * @example OpenQASM 3.0 advanced tokens
18
+ * ```typescript
19
+ * import { lookup, Token } from './qasm3/token';
20
+ *
21
+ * console.log(lookup('qubit')); // Token.Qubit
22
+ * console.log(lookup('if')); // Token.If
23
+ * console.log(lookup('def')); // Token.Def
24
+ * console.log(lookup('complex')); // Token.Complex
25
+ * ```
26
+ */
2
27
  Object.defineProperty(exports, "__esModule", { value: true });
3
28
  exports.Token = void 0;
4
29
  exports.notParam = notParam;
5
30
  exports.lookup = lookup;
6
31
  exports.inverseLookup = inverseLookup;
32
+ /**
33
+ * Enumeration of all OpenQASM 3.0 token types.
34
+ *
35
+ * Each token represents a specific syntactic element in OpenQASM 3.0 code.
36
+ * The enum values correspond to different categories:
37
+ * - Literals: NNInteger, Real, String, BoolLiteral
38
+ * - Identifiers: Id
39
+ * - Keywords: Qubit, Gate, Measure, If, For, While, etc.
40
+ * - Operators: ArithmeticOp, BinaryOp, UnaryOp
41
+ * - Punctuation: Semicolon, Comma, LParen, RParen, etc.
42
+ * - Special: OpenQASM, Include, EndOfFile, Illegal
43
+ */
7
44
  var Token;
8
45
  (function (Token) {
9
46
  // 0; invalid or unrecognized token
@@ -209,6 +246,14 @@ var Token;
209
246
  // 100; compound binary operators
210
247
  Token[Token["CompoundBinaryOp"] = 100] = "CompoundBinaryOp";
211
248
  })(Token || (exports.Token = Token = {}));
249
+ /**
250
+ * Mapping of string keywords to their corresponding token types.
251
+ *
252
+ * This lookup table enables the lexer to quickly determine if a string
253
+ * represents a reserved keyword or should be treated as an identifier.
254
+ *
255
+ * @internal
256
+ */
212
257
  var lookupMap = {
213
258
  pi: Token.Pi,
214
259
  π: Token.Pi,
@@ -300,7 +345,7 @@ var lookupMap = {
300
345
  angle: Token.Angle,
301
346
  "@": Token.At,
302
347
  complex: Token.Complex,
303
- "$": Token.Dollar,
348
+ $: Token.Dollar,
304
349
  array: Token.Array,
305
350
  durationof: Token.DurationOf,
306
351
  stretch: Token.Stretch,
@@ -311,25 +356,63 @@ var lookupMap = {
311
356
  extern: Token.Extern,
312
357
  };
313
358
  /**
314
- * Returns the token that represents a given string.
315
- * @param ident - The string.
316
- * @return The corresponding token.
359
+ * Returns the token type that corresponds to a given string.
360
+ *
361
+ * This function is used by the lexer to classify identifiers and keywords.
362
+ * If the string is a reserved keyword, it returns the appropriate token type.
363
+ * Otherwise, it returns Token.Id to indicate a user-defined identifier.
364
+ *
365
+ * @param ident - The string to look up
366
+ * @returns The corresponding token type
367
+ *
368
+ * @example Keyword lookup
369
+ * ```typescript
370
+ * lookup('qubit'); // Returns Token.Qubit
371
+ * lookup('measure'); // Returns Token.Measure
372
+ * lookup('myVar'); // Returns Token.Id
373
+ * lookup('π'); // Returns Token.Pi
374
+ * ```
317
375
  */
318
376
  function lookup(ident) {
319
377
  return ident in lookupMap ? lookupMap[ident] : Token.Id;
320
378
  }
321
379
  /**
322
- * Returns the string representation of a token.
323
- * @param tokens - The token.
324
- * @return The string representation of the token.
380
+ * Returns the string representation of a token type.
381
+ *
382
+ * This is useful for debugging and error reporting, allowing you to
383
+ * convert token enum values back to their string representations.
384
+ *
385
+ * @param token - The token type to convert
386
+ * @returns The string representation of the token, or undefined if not found
387
+ *
388
+ * @example Token to string conversion
389
+ * ```typescript
390
+ * inverseLookup(Token.Qubit); // Returns 'qubit'
391
+ * inverseLookup(Token.If); // Returns 'if'
392
+ * inverseLookup(Token.Pi); // Returns 'pi'
393
+ * ```
325
394
  */
326
395
  function inverseLookup(token) {
327
396
  return Object.keys(lookupMap).find(function (ident) { return lookupMap[ident] == token; });
328
397
  }
329
398
  /**
330
- * Determines whether a token denotes a parameter.
331
- * @param tokens - The token.
332
- * @return Whether the token does NOT denote a parameter.
399
+ * Determines whether a token can be used as a parameter in expressions.
400
+ *
401
+ * This function helps the parser validate parameter lists by checking if
402
+ * a token type is allowed in parameter contexts. Parameters can include
403
+ * identifiers, numbers, and other value-bearing tokens, but not structural
404
+ * tokens like semicolons or braces.
405
+ *
406
+ * @param token - The token type to check
407
+ * @returns true if the token CANNOT be used as a parameter, false otherwise
408
+ *
409
+ * @example Parameter validation
410
+ * ```typescript
411
+ * notParam(Token.Id); // false - identifiers can be parameters
412
+ * notParam(Token.NNInteger); // false - numbers can be parameters
413
+ * notParam(Token.Semicolon); // true - semicolons cannot be parameters
414
+ * notParam(Token.LParen); // true - parentheses cannot be parameters
415
+ * ```
333
416
  */
334
417
  function notParam(token) {
335
418
  if (token == Token.NNInteger ||
package/dist/version.js CHANGED
@@ -1,4 +1,20 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM version detection and management utilities
4
+ *
5
+ * Handles version detection from QASM source code and provides utilities
6
+ * for working with different OpenQASM versions. Supports automatic version
7
+ * detection from OPENQASM statements and manual version specification.
8
+ *
9
+ * @module Version Management
10
+ *
11
+ * @example Version detection
12
+ * ```typescript
13
+ * const version = new OpenQASMVersion(3, 0);
14
+ * console.log(version.toString()); // "3.0"
15
+ * console.log(version.isVersion3()); // true
16
+ * ```
17
+ */
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
19
  exports.OpenQASMVersion = exports.OpenQASMMajorVersion = void 0;
4
20
  /** Enum representing the major OpenQASM versions. */
@@ -12,7 +28,7 @@ var OpenQASMVersion = /** @class */ (function () {
12
28
  /**
13
29
  * Creates an OpenQASMVersion instance.
14
30
  * @param major - The OpenQASM major version. (optional)
15
- * @param minor - The OpenQASM minor version (optional).
31
+ * @param minor - The OpenQASM minor version (optional)
16
32
  */
17
33
  function OpenQASMVersion(major, minor) {
18
34
  this.major = major ? major : OpenQASMMajorVersion.Version3;
@@ -0,0 +1 @@
1
+ window.hierarchyData = "eJyrVirKzy8pVrKKjtVRKkpNy0lNLsnMzwMKVNfWAgCbHgqm"
@@ -0,0 +1,3 @@
1
+ .tsd-navigation.settings {
2
+ display: none !important;
3
+ }
@@ -0,0 +1,208 @@
1
+ # QASM TypeScript Documentation
2
+
3
+ OpenQASM, the low-level programming language for quantum circuit specification, implemented in TypeScript.
4
+
5
+ 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.
6
+
7
+ 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.
8
+
9
+ Language documentation is provided by IBM [here](https://openqasm.com).
10
+
11
+ ## Quick Start
12
+
13
+ ### Installation
14
+
15
+ ```bash
16
+ npm install qasm-ts
17
+ ```
18
+
19
+ ### Basic Usage
20
+
21
+ Parse from an OpenQASM string snippet:
22
+
23
+ ```typescript
24
+ import { parseString } from "qasm-ts";
25
+
26
+ const qasmCode = `
27
+ OPENQASM 3.0;
28
+ include "stdgates.inc";
29
+ qubit[2] q;
30
+ h q[0];
31
+ cx q[0], q[1];
32
+ `;
33
+
34
+ const ast = parseString(qasmCode);
35
+ ```
36
+
37
+ Parse from an OpenQASM file:
38
+
39
+ ```typescript
40
+ import { parseFile } from "qasm-ts";
41
+
42
+ const ast = parseFile("./my-circuit.qasm");
43
+
44
+ // Specify OpenQASM version explicitly
45
+ const ast2 = parseFile("./legacy-circuit.qasm", 2); // OpenQASM 2.0
46
+ const ast3 = parseFile("./modern-circuit.qasm", 3); // OpenQASM 3.0
47
+ ```
48
+
49
+ ### Working with the AST
50
+
51
+ ```typescript
52
+ // Get verbose output with class names
53
+ const verboseAst = parseString(qasmCode, 3, true);
54
+
55
+ // Get stringified JSON output
56
+ const jsonAst = parseString(qasmCode, 3, false, true);
57
+
58
+ // Both verbose and stringified
59
+ const verboseJsonAst = parseString(qasmCode, 3, true, true);
60
+ ```
61
+
62
+ ## Example I/O
63
+
64
+ ### Input: `alignment.qasm` ([source](https://github.com/openqasm/openqasm/blob/main/examples/alignment.qasm))
65
+
66
+ ```
67
+ include "stdgates.inc";
68
+
69
+ stretch g;
70
+
71
+ qubit[3] q;
72
+ barrier q;
73
+ cx q[0], q[1];
74
+ delay[g] q[2];
75
+ U(pi/4, 0, pi/2) q[2];
76
+ delay[2*g] q[2];
77
+ barrier q;
78
+
79
+ ```
80
+
81
+ ### Output: Abstract Syntax Tree
82
+
83
+ ```
84
+ [
85
+ Include { filename: '"stdgates.inc"' },
86
+ ClassicalDeclaration {
87
+ classicalType: StretchType {},
88
+ identifier: Identifier { name: 'g' },
89
+ initializer: null,
90
+ isConst: false
91
+ },
92
+ QuantumDeclaration {
93
+ identifier: Identifier { name: 'q' },
94
+ size: IntegerLiteral { value: 3 }
95
+ },
96
+ QuantumBarrier { qubits: [ [Identifier] ] },
97
+ QuantumGateCall {
98
+ quantumGateName: Identifier { name: 'cx' },
99
+ qubits: [ [SubscriptedIdentifier], [SubscriptedIdentifier] ],
100
+ parameters: null,
101
+ modifiers: []
102
+ },
103
+ QuantumDelay {
104
+ duration: Identifier { name: 'g' },
105
+ qubits: [ [SubscriptedIdentifier] ]
106
+ },
107
+ QuantumGateCall {
108
+ quantumGateName: Identifier { name: 'U' },
109
+ qubits: [ [SubscriptedIdentifier] ],
110
+ parameters: Parameters { args: [Array] },
111
+ modifiers: []
112
+ },
113
+ QuantumDelay {
114
+ duration: Arithmetic { op: '*', left: [IntegerLiteral], right: [Identifier] },
115
+ qubits: [ [SubscriptedIdentifier] ]
116
+ },
117
+ QuantumBarrier { qubits: [ [Identifier] ] }
118
+ ]
119
+ ```
120
+
121
+ ## API Documentation Navigation
122
+
123
+ ### Core Functions
124
+
125
+ Start here for the main parsing functions:
126
+
127
+ - **[parseString](functions/Main_Functions.parseString.html)** - Parse OpenQASM code from a string
128
+ - **[parseFile](functions/Main_Functions.parseFile.html)** - Parse OpenQASM code from a file
129
+
130
+ ### Tokenization
131
+
132
+ Understand the tokenization process and available token types:
133
+
134
+ - **[OpenQASM 3.0 Tokens](modules/qasm3_token.html)** - Modern OpenQASM token set
135
+ - **[OpenQASM 2.0 Tokens](modules/qasm2_token.html)** - Legacy OpenQASM token set
136
+
137
+ ### Lexing
138
+
139
+ Understand the Lexer:
140
+
141
+ - **[OpenQASM 3.0 Lexer](modules/qasm3_lexer.html)** - Modern OpenQASM lexer
142
+ - **[OpenQASM 2.0 Lexer](modules/qasm2_lexer.html)** - Legacy OpenQASM lexer
143
+
144
+ ### AST Structure
145
+
146
+ Understand the abstract syntax tree nodes:
147
+
148
+ - **[OpenQASM 3.0 AST Nodes](modules/qasm3_ast.html)** - Modern OpenQASM syntax tree
149
+ - **[OpenQASM 2.0 AST Nodes](modules/qasm2_ast.html)** - Legacy OpenQASM syntax tree
150
+
151
+ ### Parsing
152
+
153
+ Understand the Parser:
154
+
155
+ - **[OpenQASM 3.0 Parser](modules/qasm3_parser.html)** - Modern OpenQASM parser
156
+ - **[OpenQASM 2.0 Parser](modules/qasm2_parser.html)** - Legacy OpenQASM parser
157
+
158
+ ### Utilities and Internals
159
+
160
+ - **[Error Handling](modules/Error_Handling.html)** - All error types and their usage
161
+ - **[Version Management](modules/Version_Management.html)** - Version detection and handling
162
+
163
+ Navigate using the sidebar or search functionality to find specific functions and classes.
164
+
165
+ ## New In Version 2.0.0
166
+
167
+ - Support for the OpenQASM 3.0 spec while retaining OpenQASM 2.0 backwards compatibility.
168
+
169
+ ## Source Code
170
+
171
+ Feel free to clone, fork, comment or contribute on [GitHub](https://github.com/comp-phys-marc/qasm-ts)!
172
+
173
+ ## References
174
+
175
+ The original OpenQASM authors:
176
+
177
+ - 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)
178
+ - 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)
179
+
180
+ Another strongly typed implementation from which this project took some inspiration:
181
+
182
+ - [Adam Kelly's Rust QASM Parser](https://github.com/libtangle/qasm-rust)
183
+
184
+ ## License
185
+
186
+ Copyright 2019 Marcus Edwards
187
+
188
+ 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:
189
+
190
+ ```http://www.apache.org/licenses/LICENSE-2.0```
191
+
192
+ 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.
193
+
194
+ ## How to Cite
195
+
196
+ If you are using QASM-TS for research we appreciate any citations. Please read and cite our pre-print at https://arxiv.org/abs/2412.12578.
197
+
198
+ ```
199
+ @misc{kim2024enablingverificationformalizationhybrid,
200
+ title={Enabling the Verification and Formalization of Hybrid Quantum-Classical Computing with OpenQASM 3.0 compatible QASM-TS 2.0},
201
+ author={Sean Kim and Marcus Edwards},
202
+ year={2024},
203
+ eprint={2412.12578},
204
+ archivePrefix={arXiv},
205
+ primaryClass={cs.PL},
206
+ url={https://arxiv.org/abs/2412.12578},
207
+ }
208
+ ```