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
@@ -0,0 +1,24 @@
1
+ name: Draft PDF
2
+ on: [push]
3
+
4
+ jobs:
5
+ paper:
6
+ runs-on: ubuntu-latest
7
+ name: Paper Draft
8
+ steps:
9
+ - name: Checkout
10
+ uses: actions/checkout@v4
11
+ - name: Build draft PDF
12
+ uses: openjournals/openjournals-draft-action@master
13
+ with:
14
+ journal: joss
15
+ # This should be the path to the paper within your repo.
16
+ paper-path: paper/paper.md
17
+ - name: Upload
18
+ uses: actions/upload-artifact@v4
19
+ with:
20
+ name: paper
21
+ # This is the output path where Pandoc will write the compiled
22
+ # PDF. Note, this should be the same directory as the input
23
+ # paper.md
24
+ path: paper/paper.pdf
@@ -0,0 +1,3 @@
1
+ To get started contributing to QASM-TS, please see the open issues for a place to start.
2
+ Alternatively, you are welcome to create any issues which you feel may capture changes, improvements or additions to the package that would be useful. These may be bug reports or enhancement requests. These will be reviewed in a timely manner by a maintainer. If you are able to implement any desired functionality or bug fixes yourself, we also welcome and promise to review any pull requests. Please simply fork the repository and create a branch in your fork with the changes in question. When you create your pull request, make sure to target our repo.
3
+ Thanks!
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/errors.js CHANGED
@@ -1,4 +1,13 @@
1
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
+ */
2
11
  var __extends = (this && this.__extends) || (function () {
3
12
  var extendStatics = function (d, b) {
4
13
  extendStatics = Object.setPrototypeOf ||
package/dist/lexer.js CHANGED
@@ -1,10 +1,84 @@
1
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
+ */
2
40
  Object.defineProperty(exports, "__esModule", { value: true });
3
41
  exports.lex = lex;
4
42
  var lexer_1 = require("./qasm2/lexer");
5
43
  var lexer_2 = require("./qasm3/lexer");
6
44
  var version_1 = require("./version");
7
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
+ */
8
82
  function lex(qasm, cursor, version) {
9
83
  var lexer;
10
84
  if (version instanceof version_1.OpenQASMVersion) {
package/dist/main.js CHANGED
@@ -3,13 +3,63 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.parseString = parseString;
5
5
  exports.parseFile = parseFile;
6
+ /**
7
+ * Main parsing functions for qasm-ts - the primary entry points for parsing OpenQASM code
8
+ * @module Main Functions
9
+ */
6
10
  var fs = require("fs");
7
11
  var lexer_1 = require("./lexer");
8
12
  var parser_1 = require("./parser");
9
13
  /**
10
- * Returns the abstract syntax tree for a given string of QASM code.
11
- * @param qasm - The code string.
12
- * @return The corresponding AST.
14
+ * Parses OpenQASM code from a string and returns the abstract syntax tree.
15
+ *
16
+ * This is the primary entry point for parsing OpenQASM code. It handles both
17
+ * OpenQASM 2.0 and 3.0 syntax, automatically selecting the appropriate lexer
18
+ * and parser based on the version parameter.
19
+ *
20
+ * @group Main Functions
21
+ * @param qasm - The OpenQASM code string to parse
22
+ * @param version - The OpenQASM version to use (defaults to 3.0)
23
+ * @param verbose - Whether to include class names in the output (defaults to false)
24
+ * @param stringify - Whether to return stringified JSON (defaults to false)
25
+ * @returns The corresponding AST as an array of nodes, or stringified JSON if stringify is true
26
+ *
27
+ * @example Basic OpenQASM 3.0 parsing
28
+ * ```typescript
29
+ * import { parseString } from 'qasm-ts';
30
+ *
31
+ * const qasmCode = `
32
+ * OPENQASM 3.0;
33
+ * include "stdgates.inc";
34
+ * qubit[2] q;
35
+ * h q[0];
36
+ * cx q[0], q[1];
37
+ * `;
38
+ *
39
+ * const ast = parseString(qasmCode);
40
+ * console.log(ast);
41
+ * ```
42
+ *
43
+ * @example OpenQASM 2.0 parsing
44
+ * ```typescript
45
+ * const qasm2Code = `
46
+ * OPENQASM 2.0;
47
+ * include "qelib1.inc";
48
+ * qreg q[2];
49
+ * creg c[2];
50
+ * h q[0];
51
+ * cx q[0],q[1];
52
+ * measure q -> c;
53
+ * `;
54
+ *
55
+ * const ast = parseString(qasm2Code, 2);
56
+ * ```
57
+ *
58
+ * @example Verbose output with class names
59
+ * ```typescript
60
+ * const ast = parseString(qasmCode, 3, true);
61
+ * // Output will include __className__ properties for each node
62
+ * ```
13
63
  */
14
64
  function parseString(qasm, version, verbose, stringify) {
15
65
  var ast;
@@ -29,14 +79,39 @@ function parseString(qasm, version, verbose, stringify) {
29
79
  return ast;
30
80
  }
31
81
  /**
32
- * Returns the abstract syntax tree for a given QASM file.
33
- * @param file - The file location.
34
- * @return The corresponding AST.
82
+ * Parses OpenQASM code from a file and returns the abstract syntax tree.
83
+ *
84
+ * @group Main Functions
85
+ * @param file - The path to the .qasm file to parse
86
+ * @param version - The OpenQASM version to use (defaults to 3.0)
87
+ * @param verbose - Whether to include class names in the output (defaults to false)
88
+ * @param stringify - Whether to return stringified JSON (defaults to false)
89
+ * @returns The corresponding AST as an array of nodes, or stringified JSON if stringify is true
90
+ *
91
+ * @example Parse a QASM file
92
+ * ```typescript
93
+ * import { parseFile } from 'qasm-ts';
94
+ *
95
+ * // Parse OpenQASM 3.0 file
96
+ * const ast = parseFile('./my-circuit.qasm');
97
+ *
98
+ * // Parse OpenQASM 2.0 file
99
+ * const ast2 = parseFile('./legacy-circuit.qasm', 2);
100
+ * ```
101
+ *
102
+ * @example Parse with verbose output
103
+ * ```typescript
104
+ * const ast = parseFile('./circuit.qasm', 3, true);
105
+ * // Includes detailed class information for each AST node
106
+ * ```
35
107
  */
36
108
  function parseFile(file, version, verbose, stringify) {
37
109
  return parseString(fs.readFileSync(file, "utf8"), version, verbose, stringify);
38
110
  }
39
- /** Adds class names to the ast. */
111
+ /**
112
+ * Adds class names to AST nodes for detailed inspection.
113
+ * @internal
114
+ */
40
115
  function getDetailedOutput(object) {
41
116
  if (Array.isArray(object)) {
42
117
  return object.map(getDetailedOutput);
package/dist/parser.js CHANGED
@@ -1,10 +1,81 @@
1
1
  "use strict";
2
+ /**
3
+ * Main parser interface for generating AST from tokens
4
+ *
5
+ * The parser is responsible for transforming a stream of tokens into an Abstract
6
+ * Syntax Tree (AST) that represents the structure of the OpenQASM program. It acts
7
+ * as a dispatcher, selecting the appropriate version-specific parser based on the
8
+ * OpenQASM version being used.
9
+ *
10
+ * The parsing process follows these steps:
11
+ * 1. Receive tokenized input from the lexer
12
+ * 2. Determine OpenQASM version (2.0 or 3.0)
13
+ * 3. Select appropriate parser implementation
14
+ * 4. Generate version-specific AST nodes
15
+ *
16
+ * The specific Parser implementations can be found at:
17
+ * - {@link Qasm3Parser}
18
+ * - {@link Qasm2Parser}
19
+ *
20
+ * @module Parsing
21
+ *
22
+ * @example Basic parsing workflow
23
+ * ```typescript
24
+ * import { lex } from './lexer';
25
+ * import { parse } from './parser';
26
+ *
27
+ * const qasmCode = 'OPENQASM 3.0; h q[0];';
28
+ * const tokens = lex(qasmCode, undefined, 3);
29
+ * const ast = parse(tokens, 3);
30
+ * console.log(ast); // Array of AST nodes
31
+ * ```
32
+ *
33
+ * @example Version-specific parsing
34
+ * ```typescript
35
+ * // Parse as OpenQASM 2.0
36
+ * const ast2 = parse(tokens, 2);
37
+ *
38
+ * // Parse as OpenQASM 3.0
39
+ * const ast3 = parse(tokens, 3);
40
+ *
41
+ * // Use OpenQASMVersion object
42
+ * const version = new OpenQASMVersion(3, 0);
43
+ * const ast = parse(tokens, version);
44
+ * ```
45
+ */
2
46
  Object.defineProperty(exports, "__esModule", { value: true });
3
47
  exports.parse = parse;
4
48
  var parser_1 = require("./qasm2/parser");
5
49
  var parser_2 = require("./qasm3/parser");
6
50
  var version_1 = require("./version");
7
51
  var errors_1 = require("./errors");
52
+ /**
53
+ * Parses an array of tokens into an Abstract Syntax Tree (AST).
54
+ *
55
+ * This is the main entry point for parsing tokenized OpenQASM code. It automatically
56
+ * selects the appropriate parser implementation based on the specified version and
57
+ * returns an AST that can be used for further analysis, compilation, or execution.
58
+ *
59
+ * @group Parsing
60
+ * @param tokens - Array of tokens generated by the lexer
61
+ * @param version - OpenQASM version to use for parsing (defaults to 3.0)
62
+ * @returns Abstract Syntax Tree representing the parsed program
63
+ * @throws {UnsupportedOpenQASMVersionError} When an unsupported version is specified
64
+ *
65
+ * @example Parse OpenQASM 3.0 tokens
66
+ * ```typescript
67
+ * const tokens = lex('OPENQASM 3.0; qubit q; h q;');
68
+ * const ast = parse(tokens, 3);
69
+ * // Returns array of OpenQASM 3.0 AST nodes
70
+ * ```
71
+ *
72
+ * @example Parse OpenQASM 2.0 tokens
73
+ * ```typescript
74
+ * const tokens = lex('OPENQASM 2.0; qreg q[1]; h q[0];');
75
+ * const ast = parse(tokens, 2);
76
+ * // Returns array of OpenQASM 2.0 AST nodes
77
+ * ```
78
+ */
8
79
  function parse(tokens, version) {
9
80
  var parser;
10
81
  var castTokens;
package/dist/qasm2/ast.js CHANGED
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM 2.0 Abstract Syntax Tree Node Definitions
4
+ *
5
+ * This module defines the AST node classes for OpenQASM 2.0, which provides
6
+ * a simpler and more limited set of constructs compared to OpenQASM 3.0.
7
+ *
8
+ * OpenQASM 2.0 focuses on:
9
+ * - Basic quantum register (`qreg`) and classical register (`creg`) declarations
10
+ * - Gate definitions and applications
11
+ * - Measurement operations
12
+ * - Simple conditional statements
13
+ * - Basic arithmetic expressions
14
+ *
15
+ * Key limitations compared to 3.0:
16
+ * - No advanced classical types (only registers)
17
+ * - No control flow structures (loops, complex conditionals)
18
+ * - No function definitions or subroutines
19
+ * - Limited expression capabilities
20
+ *
21
+ * @module
22
+ *
23
+ * @example Basic OpenQASM 2.0 constructs
24
+ * ```typescript
25
+ * // Quantum register: qreg q[2];
26
+ * new QReg('q', 2)
27
+ *
28
+ * // Gate application: h q[0];
29
+ * new ApplyGate('h', [['q', 0]], [])
30
+ *
31
+ * // Measurement: measure q[0] -> c[0];
32
+ * new Measure('q', 'c', 0, 0)
33
+ * ```
34
+ */
2
35
  var __extends = (this && this.__extends) || (function () {
3
36
  var extendStatics = function (d, b) {
4
37
  extendStatics = Object.setPrototypeOf ||
@@ -1,4 +1,34 @@
1
1
  "use strict";
2
+ /**
3
+ * OpenQASM 2.0 Lexical Analyzer
4
+ *
5
+ * This module implements the lexer for OpenQASM 2.0, which provides a simpler
6
+ * token set compared to OpenQASM 3.0. The lexer focuses on basic quantum circuit
7
+ * constructs without the advanced classical programming features of version 3.0.
8
+ *
9
+ * Key characteristics of OpenQASM 2.0 lexing:
10
+ * - **Limited token set**: Basic quantum and classical registers only
11
+ * - **Simple operators**: Basic arithmetic and comparison operators
12
+ * - **No control flow**: No tokens for loops, conditionals, or functions
13
+ * - **Gate-focused**: Emphasis on gate definitions and applications
14
+ * - **Mathematical functions**: Built-in math functions (sin, cos, etc.)
15
+ *
16
+ * Supported constructs:
17
+ * - Quantum registers (`qreg`) and classical registers (`creg`)
18
+ * - Gate definitions and applications
19
+ * - Measurements with arrow notation (`->`)
20
+ * - Basic arithmetic expressions for gate parameters
21
+ * - Include statements for library files
22
+ *
23
+ * @module
24
+ *
25
+ * @example OpenQASM 2.0 lexing
26
+ * ```typescript
27
+ * const lexer = new Lexer('qreg q[2]; h q[0]; measure q -> c;');
28
+ * const tokens = lexer.lex();
29
+ * // Produces tokens for register declaration, gate, and measurement
30
+ * ```
31
+ */
2
32
  Object.defineProperty(exports, "__esModule", { value: true });
3
33
  var token_1 = require("./token");
4
34
  var errors_1 = require("../errors");
@@ -68,7 +98,30 @@ function isAlpha(c) {
68
98
  function isNewline(c) {
69
99
  return /\n|\r(?!\n)|\u2028|\u2029|\r\n/.test(c);
70
100
  }
71
- /** Class representing a lexer. */
101
+ /**
102
+ * OpenQASM 2.0 Lexical Analyzer
103
+ *
104
+ * A simpler lexer implementation focused on the core quantum circuit description
105
+ * features of OpenQASM 2.0. This lexer handles the essential constructs needed
106
+ * for basic quantum programming without the complexity of classical programming
107
+ * language features.
108
+ *
109
+ * @example Basic OpenQASM 2.0 tokenization
110
+ * ```typescript
111
+ * const source = `
112
+ * OPENQASM 2.0;
113
+ * include "qelib1.inc";
114
+ * qreg q[2];
115
+ * creg c[2];
116
+ * h q[0];
117
+ * cx q[0],q[1];
118
+ * measure q -> c;
119
+ * `;
120
+ *
121
+ * const lexer = new Lexer(source);
122
+ * const tokens = lexer.lex();
123
+ * ```
124
+ */
72
125
  var Lexer = /** @class */ (function () {
73
126
  /**
74
127
  * Creates a lexer.