qasm-ts 2.1.2 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,160 +0,0 @@
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
- */
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.Token = void 0;
28
- exports.notParam = notParam;
29
- exports.lookup = lookup;
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
- */
37
- var Token;
38
- (function (Token) {
39
- // 0; invalid or unrecognized token
40
- Token[Token["Illegal"] = 0] = "Illegal";
41
- // 1; end of file character
42
- Token[Token["EndOfFile"] = 1] = "EndOfFile";
43
- // 2; real number (floating point)
44
- Token[Token["Real"] = 2] = "Real";
45
- // 3; non-negative integer
46
- Token[Token["NNInteger"] = 3] = "NNInteger";
47
- // 4; identifier (variables names, function names, etc.)
48
- Token[Token["Id"] = 4] = "Id";
49
- // 5; OPENQASM version declaration
50
- Token[Token["OpenQASM"] = 5] = "OpenQASM";
51
- // 6; semicolon to terminate statements
52
- Token[Token["Semicolon"] = 6] = "Semicolon";
53
- // 7; comma
54
- Token[Token["Comma"] = 7] = "Comma";
55
- // 8; left paren (
56
- Token[Token["LParen"] = 8] = "LParen";
57
- // 9; left square bracket [
58
- Token[Token["LSParen"] = 9] = "LSParen";
59
- // 10; left curly brakcet {
60
- Token[Token["LCParen"] = 10] = "LCParen";
61
- // 11; right paren )
62
- Token[Token["RParen"] = 11] = "RParen";
63
- // 12; right square paren ]
64
- Token[Token["RSParen"] = 12] = "RSParen";
65
- // 13; right curly bracket }
66
- Token[Token["RCParen"] = 13] = "RCParen";
67
- // 14; arrow (->) used in measurement operations
68
- Token[Token["Arrow"] = 14] = "Arrow";
69
- // 15; equality operator (==)
70
- Token[Token["Equals"] = 15] = "Equals";
71
- // 16; addition operator (+)
72
- Token[Token["Plus"] = 16] = "Plus";
73
- // 17; subtraction operator (-)
74
- Token[Token["Minus"] = 17] = "Minus";
75
- // 18; multiplication operator (*)
76
- Token[Token["Times"] = 18] = "Times";
77
- // 19; division operator (/)
78
- Token[Token["Divide"] = 19] = "Divide";
79
- // 20; exponentiation operator (^)
80
- Token[Token["Power"] = 20] = "Power";
81
- // 21; sine function
82
- Token[Token["Sin"] = 21] = "Sin";
83
- // 22; cosine function
84
- Token[Token["Cos"] = 22] = "Cos";
85
- // 23; tangent function
86
- Token[Token["Tan"] = 23] = "Tan";
87
- // 24; exponential function
88
- Token[Token["Exp"] = 24] = "Exp";
89
- // 25; natural logarithm function
90
- Token[Token["Ln"] = 25] = "Ln";
91
- // 26; square root function
92
- Token[Token["Sqrt"] = 26] = "Sqrt";
93
- // 27; mathematical constant pi
94
- Token[Token["Pi"] = 27] = "Pi";
95
- // 28; quantum register declaration
96
- Token[Token["QReg"] = 28] = "QReg";
97
- // 29; classical register declaration
98
- Token[Token["CReg"] = 29] = "CReg";
99
- // 30; barrier operation
100
- Token[Token["Barrier"] = 30] = "Barrier";
101
- // 31; gate declaration or application
102
- Token[Token["Gate"] = 31] = "Gate";
103
- // 32; measurement operation
104
- Token[Token["Measure"] = 32] = "Measure";
105
- // 33; qubit reset operation
106
- Token[Token["Reset"] = 33] = "Reset";
107
- // 34; include statement
108
- Token[Token["Include"] = 34] = "Include";
109
- // 35; if statement conditional
110
- Token[Token["If"] = 35] = "If";
111
- // 36; string literal
112
- Token[Token["String"] = 36] = "String";
113
- // 37; opaque keyword
114
- Token[Token["Opaque"] = 37] = "Opaque";
115
- })(Token || (exports.Token = Token = {}));
116
- var lookupMap = {
117
- if: Token.If,
118
- sin: Token.Sin,
119
- cos: Token.Cos,
120
- tan: Token.Tan,
121
- exp: Token.Exp,
122
- ln: Token.Ln,
123
- sqrt: Token.Sqrt,
124
- pi: Token.Pi,
125
- "+": Token.Plus,
126
- "-": Token.Minus,
127
- "/": Token.Divide,
128
- "*": Token.Times,
129
- "^": Token.Power,
130
- };
131
- /**
132
- * Returns the token that represents a given string.
133
- * @param ident - The string.
134
- * @return The corresponding token.
135
- */
136
- function lookup(ident) {
137
- return ident in lookupMap ? lookupMap[ident] : Token.Id;
138
- }
139
- /**
140
- * Returns the string representation of a token.
141
- * @param tokens - The token.
142
- * @return The string representation of the token.
143
- */
144
- function inverseLookup(token) {
145
- return Object.keys(lookupMap).find(function (ident) { return lookupMap[ident] == token; });
146
- }
147
- /**
148
- * Determines whether a token denotes a parameter.
149
- * @param tokens - The token.
150
- * @return Whether the token does NOT denote a parameter.
151
- */
152
- function notParam(token) {
153
- if (token == Token.NNInteger ||
154
- token == Token.Real ||
155
- token == Token.Id ||
156
- inverseLookup(token)) {
157
- return false;
158
- }
159
- return true;
160
- }