qasm-ts 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +13 -0
- package/dist/errors.js +119 -2
- package/dist/lexer.js +39 -294
- package/dist/main.js +42 -12
- package/dist/parser.js +46 -482
- package/dist/{ast.js → qasm2/ast.js} +38 -2
- package/dist/qasm2/lexer.js +436 -0
- package/dist/qasm2/parser.js +609 -0
- package/dist/{token.js → qasm2/token.js} +62 -21
- package/dist/qasm3/ast.js +1081 -0
- package/dist/qasm3/lexer.js +615 -0
- package/dist/qasm3/parser.js +2030 -0
- package/dist/qasm3/token.js +342 -0
- package/dist/version.js +41 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +99 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1493 -0
- package/docs/classes/errors.BadArgumentError.html +12 -0
- package/docs/classes/errors.BadBarrierError.html +12 -0
- package/docs/classes/errors.BadClassicalTypeError.html +12 -0
- package/docs/classes/errors.BadConditionalError.html +12 -0
- package/docs/classes/errors.BadCregError.html +12 -0
- package/docs/classes/errors.BadEqualsError.html +12 -0
- package/docs/classes/errors.BadExpressionError.html +12 -0
- package/docs/classes/errors.BadGateError.html +12 -0
- package/docs/classes/errors.BadIncludeError.html +12 -0
- package/docs/classes/errors.BadLoopError.html +12 -0
- package/docs/classes/errors.BadMeasurementError.html +12 -0
- package/docs/classes/errors.BadParameterError.html +12 -0
- package/docs/classes/errors.BadQregError.html +12 -0
- package/docs/classes/errors.BadQuantumInstructionError.html +12 -0
- package/docs/classes/errors.BadStringLiteralError.html +12 -0
- package/docs/classes/errors.BadSubroutineError.html +12 -0
- package/docs/classes/errors.MissingBraceError.html +12 -0
- package/docs/classes/errors.MissingSemicolonError.html +12 -0
- package/docs/classes/errors.UnsupportedOpenQASMVersionError.html +12 -0
- package/docs/classes/qasm2_ast.ApplyGate.html +6 -0
- package/docs/classes/qasm2_ast.AstNode.html +3 -0
- package/docs/classes/qasm2_ast.Barrier.html +5 -0
- package/docs/classes/qasm2_ast.CReg.html +5 -0
- package/docs/classes/qasm2_ast.Cos.html +3 -0
- package/docs/classes/qasm2_ast.Divide.html +3 -0
- package/docs/classes/qasm2_ast.Exp.html +3 -0
- package/docs/classes/qasm2_ast.Gate.html +7 -0
- package/docs/classes/qasm2_ast.Id.html +4 -0
- package/docs/classes/qasm2_ast.If.html +6 -0
- package/docs/classes/qasm2_ast.Include.html +4 -0
- package/docs/classes/qasm2_ast.Ln.html +3 -0
- package/docs/classes/qasm2_ast.Measure.html +7 -0
- package/docs/classes/qasm2_ast.Minus.html +3 -0
- package/docs/classes/qasm2_ast.NNInteger.html +4 -0
- package/docs/classes/qasm2_ast.Opaque.html +6 -0
- package/docs/classes/qasm2_ast.Pi.html +3 -0
- package/docs/classes/qasm2_ast.Plus.html +3 -0
- package/docs/classes/qasm2_ast.Power.html +3 -0
- package/docs/classes/qasm2_ast.QReg.html +5 -0
- package/docs/classes/qasm2_ast.Real.html +4 -0
- package/docs/classes/qasm2_ast.Sin.html +3 -0
- package/docs/classes/qasm2_ast.Sqrt.html +3 -0
- package/docs/classes/qasm2_ast.Tan.html +3 -0
- package/docs/classes/qasm2_ast.Times.html +3 -0
- package/docs/classes/qasm2_ast.Variable.html +4 -0
- package/docs/classes/qasm2_ast.Version.html +4 -0
- package/docs/classes/qasm2_lexer.default.html +50 -0
- package/docs/classes/qasm2_parser.default.html +87 -0
- package/docs/classes/qasm3_ast.AliasStatement.html +5 -0
- package/docs/classes/qasm3_ast.AngleType.html +4 -0
- package/docs/classes/qasm3_ast.Arithmetic.html +6 -0
- package/docs/classes/qasm3_ast.ArrayAccess.html +5 -0
- package/docs/classes/qasm3_ast.ArrayDeclaration.html +7 -0
- package/docs/classes/qasm3_ast.ArrayInitializer.html +4 -0
- package/docs/classes/qasm3_ast.ArrayReference.html +5 -0
- package/docs/classes/qasm3_ast.AssignmentStatement.html +5 -0
- package/docs/classes/qasm3_ast.AstNode.html +3 -0
- package/docs/classes/qasm3_ast.Binary.html +6 -0
- package/docs/classes/qasm3_ast.BitType.html +4 -0
- package/docs/classes/qasm3_ast.BitstringLiteral.html +4 -0
- package/docs/classes/qasm3_ast.BoolType.html +3 -0
- package/docs/classes/qasm3_ast.BooleanLiteral.html +4 -0
- package/docs/classes/qasm3_ast.BoxDefinition.html +7 -0
- package/docs/classes/qasm3_ast.BranchingStatement.html +8 -0
- package/docs/classes/qasm3_ast.BreakStatement.html +3 -0
- package/docs/classes/qasm3_ast.CalibrationGrammarDeclaration.html +6 -0
- package/docs/classes/qasm3_ast.CaseStatement.html +5 -0
- package/docs/classes/qasm3_ast.Cast.html +5 -0
- package/docs/classes/qasm3_ast.ClassicalDeclaration.html +7 -0
- package/docs/classes/qasm3_ast.ClassicalType.html +3 -0
- package/docs/classes/qasm3_ast.ComplexType.html +6 -0
- package/docs/classes/qasm3_ast.ContinueStatement.html +3 -0
- package/docs/classes/qasm3_ast.DefaultStatement.html +4 -0
- package/docs/classes/qasm3_ast.DurationLiteral.html +5 -0
- package/docs/classes/qasm3_ast.DurationOf.html +4 -0
- package/docs/classes/qasm3_ast.DurationType.html +3 -0
- package/docs/classes/qasm3_ast.Euler.html +3 -0
- package/docs/classes/qasm3_ast.Expression.html +3 -0
- package/docs/classes/qasm3_ast.ExternSignature.html +8 -0
- package/docs/classes/qasm3_ast.FloatLiteral.html +4 -0
- package/docs/classes/qasm3_ast.FloatType.html +6 -0
- package/docs/classes/qasm3_ast.ForLoopStatement.html +12 -0
- package/docs/classes/qasm3_ast.HardwareQubit.html +5 -0
- package/docs/classes/qasm3_ast.IODeclaration.html +5 -0
- package/docs/classes/qasm3_ast.Identifier.html +4 -0
- package/docs/classes/qasm3_ast.ImaginaryLiteral.html +4 -0
- package/docs/classes/qasm3_ast.Include.html +6 -0
- package/docs/classes/qasm3_ast.IndexSet.html +5 -0
- package/docs/classes/qasm3_ast.IntType.html +4 -0
- package/docs/classes/qasm3_ast.IntegerLiteral.html +4 -0
- package/docs/classes/qasm3_ast.MathFunction.html +5 -0
- package/docs/classes/qasm3_ast.NumericLiteral.html +4 -0
- package/docs/classes/qasm3_ast.Parameters.html +4 -0
- package/docs/classes/qasm3_ast.Pi.html +3 -0
- package/docs/classes/qasm3_ast.ProgramBlock.html +7 -0
- package/docs/classes/qasm3_ast.QuantumBarrier.html +6 -0
- package/docs/classes/qasm3_ast.QuantumBlock.html +6 -0
- package/docs/classes/qasm3_ast.QuantumDeclaration.html +8 -0
- package/docs/classes/qasm3_ast.QuantumDelay.html +5 -0
- package/docs/classes/qasm3_ast.QuantumGateCall.html +9 -0
- package/docs/classes/qasm3_ast.QuantumGateDefinition.html +9 -0
- package/docs/classes/qasm3_ast.QuantumGateModifier.html +5 -0
- package/docs/classes/qasm3_ast.QuantumMeasurement.html +6 -0
- package/docs/classes/qasm3_ast.QuantumMeasurementAssignment.html +8 -0
- package/docs/classes/qasm3_ast.QuantumReset.html +4 -0
- package/docs/classes/qasm3_ast.Range.html +6 -0
- package/docs/classes/qasm3_ast.ReturnStatement.html +4 -0
- package/docs/classes/qasm3_ast.SizeOf.html +5 -0
- package/docs/classes/qasm3_ast.Statement.html +12 -0
- package/docs/classes/qasm3_ast.StretchType.html +3 -0
- package/docs/classes/qasm3_ast.SubroutineBlock.html +6 -0
- package/docs/classes/qasm3_ast.SubroutineCall.html +5 -0
- package/docs/classes/qasm3_ast.SubroutineDefinition.html +10 -0
- package/docs/classes/qasm3_ast.SubscriptedIdentifier.html +5 -0
- package/docs/classes/qasm3_ast.SwitchStatement.html +6 -0
- package/docs/classes/qasm3_ast.Tau.html +3 -0
- package/docs/classes/qasm3_ast.TrigFunction.html +5 -0
- package/docs/classes/qasm3_ast.UIntType.html +4 -0
- package/docs/classes/qasm3_ast.Unary.html +5 -0
- package/docs/classes/qasm3_ast.Version.html +6 -0
- package/docs/classes/qasm3_ast.WhileLoopStatement.html +6 -0
- package/docs/classes/qasm3_lexer.default.html +60 -0
- package/docs/classes/qasm3_parser.default.html +227 -0
- package/docs/classes/version.OpenQASMVersion.html +16 -0
- package/docs/enums/qasm2_token.Token.html +39 -0
- package/docs/enums/qasm3_ast.ArithmeticOp.html +9 -0
- package/docs/enums/qasm3_ast.ArrayReferenceModifier.html +4 -0
- package/docs/enums/qasm3_ast.BinaryOp.html +15 -0
- package/docs/enums/qasm3_ast.DurationUnit.html +7 -0
- package/docs/enums/qasm3_ast.IOModifier.html +4 -0
- package/docs/enums/qasm3_ast.MathFunctionTypes.html +12 -0
- package/docs/enums/qasm3_ast.QuantumGateModifierName.html +6 -0
- package/docs/enums/qasm3_ast.TrigFunctionTypes.html +8 -0
- package/docs/enums/qasm3_ast.UnaryOp.html +5 -0
- package/docs/enums/qasm3_token.Token.html +101 -0
- package/docs/enums/version.OpenQASMMajorVersion.html +4 -0
- package/docs/functions/lexer.lex.html +1 -0
- package/docs/functions/main.parseFile.html +4 -0
- package/docs/functions/main.parseString.html +4 -0
- package/docs/functions/parser.parse.html +1 -0
- package/docs/functions/qasm2_token.inverseLookup.html +3 -0
- package/docs/functions/qasm2_token.lookup.html +4 -0
- package/docs/functions/qasm2_token.notParam.html +3 -0
- package/docs/functions/qasm3_token.inverseLookup.html +3 -0
- package/docs/functions/qasm3_token.lookup.html +4 -0
- package/docs/functions/qasm3_token.notParam.html +3 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +55 -0
- package/docs/modules/errors.html +21 -0
- package/docs/modules/lexer.html +2 -0
- package/docs/modules/main.html +3 -0
- package/docs/modules/parser.html +2 -0
- package/docs/modules/qasm2_ast.html +28 -0
- package/docs/modules/qasm2_lexer.html +2 -0
- package/docs/modules/qasm2_parser.html +2 -0
- package/docs/modules/qasm2_token.html +5 -0
- package/docs/modules/qasm3_ast.html +83 -0
- package/docs/modules/qasm3_lexer.html +2 -0
- package/docs/modules/qasm3_parser.html +2 -0
- package/docs/modules/qasm3_token.html +5 -0
- package/docs/modules/version.html +3 -0
- package/docs/modules.html +14 -0
- package/docs/types/errors.ReturnErrorConstructor.html +2 -0
- package/package.json +5 -4
- package/readme.md +67 -51
- package/dist/example.js +0 -22
|
@@ -1,61 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
exports.
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Token = void 0;
|
|
4
|
+
exports.notParam = notParam;
|
|
5
|
+
exports.lookup = lookup;
|
|
6
|
+
exports.inverseLookup = inverseLookup;
|
|
4
7
|
var Token;
|
|
5
8
|
(function (Token) {
|
|
9
|
+
// 0; invalid or unrecognized token
|
|
6
10
|
Token[Token["Illegal"] = 0] = "Illegal";
|
|
11
|
+
// 1; end of file character
|
|
7
12
|
Token[Token["EndOfFile"] = 1] = "EndOfFile";
|
|
13
|
+
// 2; real number (floating point)
|
|
8
14
|
Token[Token["Real"] = 2] = "Real";
|
|
15
|
+
// 3; non-negative integer
|
|
9
16
|
Token[Token["NNInteger"] = 3] = "NNInteger";
|
|
17
|
+
// 4; identifier (variables names, function names, etc.)
|
|
10
18
|
Token[Token["Id"] = 4] = "Id";
|
|
19
|
+
// 5; OPENQASM version declaration
|
|
11
20
|
Token[Token["OpenQASM"] = 5] = "OpenQASM";
|
|
21
|
+
// 6; semicolon to terminate statements
|
|
12
22
|
Token[Token["Semicolon"] = 6] = "Semicolon";
|
|
23
|
+
// 7; comma
|
|
13
24
|
Token[Token["Comma"] = 7] = "Comma";
|
|
25
|
+
// 8; left paren (
|
|
14
26
|
Token[Token["LParen"] = 8] = "LParen";
|
|
27
|
+
// 9; left square bracket [
|
|
15
28
|
Token[Token["LSParen"] = 9] = "LSParen";
|
|
29
|
+
// 10; left curly brakcet {
|
|
16
30
|
Token[Token["LCParen"] = 10] = "LCParen";
|
|
31
|
+
// 11; right paren )
|
|
17
32
|
Token[Token["RParen"] = 11] = "RParen";
|
|
33
|
+
// 12; right square paren ]
|
|
18
34
|
Token[Token["RSParen"] = 12] = "RSParen";
|
|
35
|
+
// 13; right curly bracket }
|
|
19
36
|
Token[Token["RCParen"] = 13] = "RCParen";
|
|
37
|
+
// 14; arrow (->) used in measurement operations
|
|
20
38
|
Token[Token["Arrow"] = 14] = "Arrow";
|
|
39
|
+
// 15; equality operator (==)
|
|
21
40
|
Token[Token["Equals"] = 15] = "Equals";
|
|
41
|
+
// 16; addition operator (+)
|
|
22
42
|
Token[Token["Plus"] = 16] = "Plus";
|
|
43
|
+
// 17; subtraction operator (-)
|
|
23
44
|
Token[Token["Minus"] = 17] = "Minus";
|
|
45
|
+
// 18; multiplication operator (*)
|
|
24
46
|
Token[Token["Times"] = 18] = "Times";
|
|
47
|
+
// 19; division operator (/)
|
|
25
48
|
Token[Token["Divide"] = 19] = "Divide";
|
|
49
|
+
// 20; exponentiation operator (^)
|
|
26
50
|
Token[Token["Power"] = 20] = "Power";
|
|
51
|
+
// 21; sine function
|
|
27
52
|
Token[Token["Sin"] = 21] = "Sin";
|
|
53
|
+
// 22; cosine function
|
|
28
54
|
Token[Token["Cos"] = 22] = "Cos";
|
|
55
|
+
// 23; tangent function
|
|
29
56
|
Token[Token["Tan"] = 23] = "Tan";
|
|
57
|
+
// 24; exponential function
|
|
30
58
|
Token[Token["Exp"] = 24] = "Exp";
|
|
59
|
+
// 25; natural logarithm function
|
|
31
60
|
Token[Token["Ln"] = 25] = "Ln";
|
|
61
|
+
// 26; square root function
|
|
32
62
|
Token[Token["Sqrt"] = 26] = "Sqrt";
|
|
63
|
+
// 27; mathematical constant pi
|
|
33
64
|
Token[Token["Pi"] = 27] = "Pi";
|
|
65
|
+
// 28; quantum register declaration
|
|
34
66
|
Token[Token["QReg"] = 28] = "QReg";
|
|
67
|
+
// 29; classical register declaration
|
|
35
68
|
Token[Token["CReg"] = 29] = "CReg";
|
|
69
|
+
// 30; barrier operation
|
|
36
70
|
Token[Token["Barrier"] = 30] = "Barrier";
|
|
71
|
+
// 31; gate declaration or application
|
|
37
72
|
Token[Token["Gate"] = 31] = "Gate";
|
|
73
|
+
// 32; measurement operation
|
|
38
74
|
Token[Token["Measure"] = 32] = "Measure";
|
|
75
|
+
// 33; qubit reset operation
|
|
39
76
|
Token[Token["Reset"] = 33] = "Reset";
|
|
77
|
+
// 34; include statement
|
|
40
78
|
Token[Token["Include"] = 34] = "Include";
|
|
79
|
+
// 35; if statement conditional
|
|
41
80
|
Token[Token["If"] = 35] = "If";
|
|
81
|
+
// 36; string literal
|
|
42
82
|
Token[Token["String"] = 36] = "String";
|
|
43
|
-
|
|
44
|
-
|
|
83
|
+
// 37; opaque keyword
|
|
84
|
+
Token[Token["Opaque"] = 37] = "Opaque";
|
|
85
|
+
})(Token || (exports.Token = Token = {}));
|
|
45
86
|
var lookupMap = {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
87
|
+
if: Token.If,
|
|
88
|
+
sin: Token.Sin,
|
|
89
|
+
cos: Token.Cos,
|
|
90
|
+
tan: Token.Tan,
|
|
91
|
+
exp: Token.Exp,
|
|
92
|
+
ln: Token.Ln,
|
|
93
|
+
sqrt: Token.Sqrt,
|
|
94
|
+
pi: Token.Pi,
|
|
95
|
+
"+": Token.Plus,
|
|
96
|
+
"-": Token.Minus,
|
|
97
|
+
"/": Token.Divide,
|
|
98
|
+
"*": Token.Times,
|
|
99
|
+
"^": Token.Power,
|
|
59
100
|
};
|
|
60
101
|
/**
|
|
61
102
|
* Returns the token that represents a given string.
|
|
@@ -65,7 +106,6 @@ var lookupMap = {
|
|
|
65
106
|
function lookup(ident) {
|
|
66
107
|
return ident in lookupMap ? lookupMap[ident] : Token.Id;
|
|
67
108
|
}
|
|
68
|
-
exports.lookup = lookup;
|
|
69
109
|
/**
|
|
70
110
|
* Returns the string representation of a token.
|
|
71
111
|
* @param tokens - The token.
|
|
@@ -74,16 +114,17 @@ exports.lookup = lookup;
|
|
|
74
114
|
function inverseLookup(token) {
|
|
75
115
|
return Object.keys(lookupMap).find(function (ident) { return lookupMap[ident] == token; });
|
|
76
116
|
}
|
|
77
|
-
exports.inverseLookup = inverseLookup;
|
|
78
117
|
/**
|
|
79
118
|
* Determines whether a token denotes a parameter.
|
|
80
119
|
* @param tokens - The token.
|
|
81
120
|
* @return Whether the token does NOT denote a parameter.
|
|
82
121
|
*/
|
|
83
122
|
function notParam(token) {
|
|
84
|
-
if (token == Token.NNInteger ||
|
|
123
|
+
if (token == Token.NNInteger ||
|
|
124
|
+
token == Token.Real ||
|
|
125
|
+
token == Token.Id ||
|
|
126
|
+
inverseLookup(token)) {
|
|
85
127
|
return false;
|
|
86
128
|
}
|
|
87
129
|
return true;
|
|
88
130
|
}
|
|
89
|
-
exports.notParam = notParam;
|