affinirum 1.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/LICENSE +661 -0
- package/README.md +301 -0
- package/dst/Affinirum.d.ts +73 -0
- package/dst/Affinirum.js +536 -0
- package/dst/Constant.d.ts +15 -0
- package/dst/Constant.js +26 -0
- package/dst/Constants.d.ts +2 -0
- package/dst/Constants.js +22 -0
- package/dst/Functions.d.ts +2 -0
- package/dst/Functions.js +85 -0
- package/dst/Keywords.d.ts +1 -0
- package/dst/Keywords.js +17 -0
- package/dst/Node.d.ts +13 -0
- package/dst/Node.js +22 -0
- package/dst/ParserFrame.d.ts +13 -0
- package/dst/ParserFrame.js +80 -0
- package/dst/ParserState.d.ts +54 -0
- package/dst/ParserState.js +562 -0
- package/dst/StaticScope.d.ts +13 -0
- package/dst/StaticScope.js +44 -0
- package/dst/Type.d.ts +72 -0
- package/dst/Type.js +196 -0
- package/dst/Value.d.ts +3 -0
- package/dst/Value.js +1 -0
- package/dst/Variable.d.ts +13 -0
- package/dst/Variable.js +25 -0
- package/dst/atom/ArrayAtom.d.ts +11 -0
- package/dst/atom/ArrayAtom.js +38 -0
- package/dst/atom/FunctionAtom.d.ts +17 -0
- package/dst/atom/FunctionAtom.js +54 -0
- package/dst/atom/ObjectAtom.d.ts +11 -0
- package/dst/atom/ObjectAtom.js +44 -0
- package/dst/atom/PrimitiveAtom.d.ts +8 -0
- package/dst/atom/PrimitiveAtom.js +26 -0
- package/dst/cjs/Affinirum.js +540 -0
- package/dst/cjs/Constant.js +30 -0
- package/dst/cjs/Constants.js +25 -0
- package/dst/cjs/Functions.js +88 -0
- package/dst/cjs/Keywords.js +20 -0
- package/dst/cjs/Node.js +26 -0
- package/dst/cjs/ParserFrame.js +84 -0
- package/dst/cjs/ParserState.js +566 -0
- package/dst/cjs/StaticScope.js +48 -0
- package/dst/cjs/Type.js +200 -0
- package/dst/cjs/Value.js +2 -0
- package/dst/cjs/Variable.js +29 -0
- package/dst/cjs/atom/ArrayAtom.js +42 -0
- package/dst/cjs/atom/FunctionAtom.js +58 -0
- package/dst/cjs/atom/ObjectAtom.js +48 -0
- package/dst/cjs/atom/PrimitiveAtom.js +30 -0
- package/dst/cjs/constant/Array.js +93 -0
- package/dst/cjs/constant/Boolean.js +25 -0
- package/dst/cjs/constant/Buffer.js +68 -0
- package/dst/cjs/constant/Enumerable.js +34 -0
- package/dst/cjs/constant/Float.js +85 -0
- package/dst/cjs/constant/Integer.js +104 -0
- package/dst/cjs/constant/Iterable.js +24 -0
- package/dst/cjs/constant/Number.js +59 -0
- package/dst/cjs/constant/Object.js +13 -0
- package/dst/cjs/constant/String.js +197 -0
- package/dst/cjs/constant/Timestamp.js +56 -0
- package/dst/cjs/constant/Unknown.js +101 -0
- package/dst/cjs/constant/notation/AN.js +46 -0
- package/dst/cjs/constant/notation/JSON.js +14 -0
- package/dst/cjs/index.js +19 -0
- package/dst/cjs/node/ArrayNode.js +34 -0
- package/dst/cjs/node/BlockNode.js +33 -0
- package/dst/cjs/node/CallNode.js +54 -0
- package/dst/cjs/node/ConstantNode.js +33 -0
- package/dst/cjs/node/LoopNode.js +34 -0
- package/dst/cjs/node/ObjectNode.js +42 -0
- package/dst/cjs/node/SwitchNode.js +45 -0
- package/dst/cjs/node/VariableNode.js +30 -0
- package/dst/cjs/package.json +3 -0
- package/dst/constant/Array.d.ts +22 -0
- package/dst/constant/Array.js +90 -0
- package/dst/constant/Boolean.d.ts +11 -0
- package/dst/constant/Boolean.js +22 -0
- package/dst/constant/Buffer.d.ts +10 -0
- package/dst/constant/Buffer.js +61 -0
- package/dst/constant/Enumerable.d.ts +5 -0
- package/dst/constant/Enumerable.js +31 -0
- package/dst/constant/Float.d.ts +22 -0
- package/dst/constant/Float.js +80 -0
- package/dst/constant/Integer.d.ts +10 -0
- package/dst/constant/Integer.js +100 -0
- package/dst/constant/Iterable.d.ts +3 -0
- package/dst/constant/Iterable.js +21 -0
- package/dst/constant/Number.d.ts +14 -0
- package/dst/constant/Number.js +56 -0
- package/dst/constant/Object.d.ts +7 -0
- package/dst/constant/Object.js +10 -0
- package/dst/constant/String.d.ts +34 -0
- package/dst/constant/String.js +179 -0
- package/dst/constant/Timestamp.d.ts +20 -0
- package/dst/constant/Timestamp.js +50 -0
- package/dst/constant/Unknown.d.ts +10 -0
- package/dst/constant/Unknown.js +95 -0
- package/dst/constant/notation/AN.d.ts +6 -0
- package/dst/constant/notation/AN.js +42 -0
- package/dst/constant/notation/JSON.d.ts +7 -0
- package/dst/constant/notation/JSON.js +10 -0
- package/dst/index.d.ts +3 -0
- package/dst/index.js +3 -0
- package/dst/node/ArrayNode.d.ts +12 -0
- package/dst/node/ArrayNode.js +30 -0
- package/dst/node/BlockNode.d.ts +12 -0
- package/dst/node/BlockNode.js +29 -0
- package/dst/node/CallNode.d.ts +14 -0
- package/dst/node/CallNode.js +50 -0
- package/dst/node/ConstantNode.d.ts +15 -0
- package/dst/node/ConstantNode.js +29 -0
- package/dst/node/LoopNode.d.ts +13 -0
- package/dst/node/LoopNode.js +30 -0
- package/dst/node/ObjectNode.d.ts +13 -0
- package/dst/node/ObjectNode.js +38 -0
- package/dst/node/SwitchNode.d.ts +14 -0
- package/dst/node/SwitchNode.js +41 -0
- package/dst/node/VariableNode.d.ts +14 -0
- package/dst/node/VariableNode.js +26 -0
- package/package.json +67 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Keywords = void 0;
|
|
4
|
+
exports.Keywords = [
|
|
5
|
+
'true', 'false',
|
|
6
|
+
'null', 'void',
|
|
7
|
+
'boolean', 'bool',
|
|
8
|
+
'timestamp', 'time',
|
|
9
|
+
'float', 'flo',
|
|
10
|
+
'integer', 'int',
|
|
11
|
+
'buffer', 'buf',
|
|
12
|
+
'string', 'str',
|
|
13
|
+
'array', 'arr',
|
|
14
|
+
'object', 'obj',
|
|
15
|
+
'function', 'func',
|
|
16
|
+
'variable', 'var',
|
|
17
|
+
'constant', 'const',
|
|
18
|
+
'while',
|
|
19
|
+
'if', 'else',
|
|
20
|
+
];
|
package/dst/cjs/Node.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Node = void 0;
|
|
4
|
+
const ParserFrame_js_1 = require("./ParserFrame.js");
|
|
5
|
+
class Node extends ParserFrame_js_1.ParserFrame {
|
|
6
|
+
constructor(frame) {
|
|
7
|
+
super(frame.expr, frame.start, frame.end);
|
|
8
|
+
}
|
|
9
|
+
get constant() {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
reduceType(type) {
|
|
13
|
+
const compiledType = this.type.reduce(type);
|
|
14
|
+
if (compiledType) {
|
|
15
|
+
return compiledType;
|
|
16
|
+
}
|
|
17
|
+
this.throwTypeError(type);
|
|
18
|
+
}
|
|
19
|
+
throwTypeError(type) {
|
|
20
|
+
return this.throwError(`type ${this.type} mismatch with expected type ${type}`);
|
|
21
|
+
}
|
|
22
|
+
toString(ident = 0) {
|
|
23
|
+
return ' '.repeat(ident) + `[${this._start}:${this.end}] <${this.type}>`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Node = Node;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParserFrame = void 0;
|
|
4
|
+
class ParserFrame {
|
|
5
|
+
_expr;
|
|
6
|
+
_start;
|
|
7
|
+
_end;
|
|
8
|
+
constructor(_expr, _start = 0, _end = 0) {
|
|
9
|
+
this._expr = _expr;
|
|
10
|
+
this._start = _start;
|
|
11
|
+
this._end = _end;
|
|
12
|
+
}
|
|
13
|
+
get expr() {
|
|
14
|
+
return this._expr;
|
|
15
|
+
}
|
|
16
|
+
get start() {
|
|
17
|
+
return this._start;
|
|
18
|
+
}
|
|
19
|
+
get end() {
|
|
20
|
+
return this._end;
|
|
21
|
+
}
|
|
22
|
+
starts(frame) {
|
|
23
|
+
if (frame) {
|
|
24
|
+
this._start = frame.start;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
return new ParserFrame(this._expr, this._start, this._end);
|
|
28
|
+
}
|
|
29
|
+
ends(frame) {
|
|
30
|
+
if (frame) {
|
|
31
|
+
this._end = frame.end;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
return new ParserFrame(this._expr, this._start, this._end);
|
|
35
|
+
}
|
|
36
|
+
throwError(message) {
|
|
37
|
+
const offset = this._start < 32 ? 0 : this._start - 32;
|
|
38
|
+
const length = this._end < this._start ? 0 : this._end - this._start - 1;
|
|
39
|
+
let expr = '';
|
|
40
|
+
for (let i = 0; i < this._expr.length; ++i) {
|
|
41
|
+
const c = this._expr[i];
|
|
42
|
+
expr += SPACE_SYMBOLS.includes(c) ? ' ' : c;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`error: ${message} at position ${this._start}:\n${expr.substring(offset, offset + 60)}\n` +
|
|
45
|
+
`${' '.repeat(expr.substring(offset, this._start).length)}^${'\''.repeat(length)}`);
|
|
46
|
+
}
|
|
47
|
+
toString() {
|
|
48
|
+
return `[${this._start}:${this._end}]`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.ParserFrame = ParserFrame;
|
|
52
|
+
const SPACE_SYMBOLS = [
|
|
53
|
+
// Whitespace and line-breaking characters
|
|
54
|
+
'\t', // tab
|
|
55
|
+
'\n', // newline
|
|
56
|
+
'\r', // carriage return
|
|
57
|
+
'\f', // form feed
|
|
58
|
+
'\v', // vertical tab
|
|
59
|
+
// Unicode spaces and separators
|
|
60
|
+
'\u00A0', // no-break space
|
|
61
|
+
'\u1680', // ogham space mark
|
|
62
|
+
'\u180E', // mongolian vowel separator
|
|
63
|
+
'\u2000', // en quad
|
|
64
|
+
'\u2001', // em quad
|
|
65
|
+
'\u2002', // en space
|
|
66
|
+
'\u2003', // em space
|
|
67
|
+
'\u2004', // three-per-em space
|
|
68
|
+
'\u2005', // four-per-em space
|
|
69
|
+
'\u2006', // six-per-em space
|
|
70
|
+
'\u2007', // figure space
|
|
71
|
+
'\u2008', // punctuation space
|
|
72
|
+
'\u2009', // thin space
|
|
73
|
+
'\u200A', // hair space
|
|
74
|
+
'\u2028', // line separator
|
|
75
|
+
'\u2029', // paragraph separator
|
|
76
|
+
'\u205F', // medium mathematical space
|
|
77
|
+
'\u3000', // ideographic space
|
|
78
|
+
// Zero-width & directional formatting characters
|
|
79
|
+
'\u200B', // zero-width space
|
|
80
|
+
'\u200C', // zero-width non-joiner
|
|
81
|
+
'\u200D', // zero-width joiner
|
|
82
|
+
'\u2060', // word joiner
|
|
83
|
+
'\uFEFF', // byte order mark
|
|
84
|
+
];
|
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParserState = void 0;
|
|
4
|
+
const Iterable_js_1 = require("./constant/Iterable.js");
|
|
5
|
+
const Boolean_js_1 = require("./constant/Boolean.js");
|
|
6
|
+
const Buffer_js_1 = require("./constant/Buffer.js");
|
|
7
|
+
const Enumerable_js_1 = require("./constant/Enumerable.js");
|
|
8
|
+
const String_js_1 = require("./constant/String.js");
|
|
9
|
+
const Constant_js_1 = require("./Constant.js");
|
|
10
|
+
const Number_js_1 = require("./constant/Number.js");
|
|
11
|
+
const Unknown_js_1 = require("./constant/Unknown.js");
|
|
12
|
+
const Type_js_1 = require("./Type.js");
|
|
13
|
+
const ParserFrame_js_1 = require("./ParserFrame.js");
|
|
14
|
+
class Literal {
|
|
15
|
+
value;
|
|
16
|
+
constructor(value) {
|
|
17
|
+
this.value = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const valueTrue = new Literal(true);
|
|
21
|
+
const valueFalse = new Literal(false);
|
|
22
|
+
const valueNull = new Literal(undefined);
|
|
23
|
+
class Assignment {
|
|
24
|
+
operator;
|
|
25
|
+
constructor(operator) {
|
|
26
|
+
this.operator = operator;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const funcAssignment = new Assignment();
|
|
30
|
+
const funcOrAssignment = new Assignment(Boolean_js_1.funcOr);
|
|
31
|
+
const funcAndAssignment = new Assignment(Boolean_js_1.funcAnd);
|
|
32
|
+
const funcAddAssignment = new Assignment(Enumerable_js_1.funcAdd);
|
|
33
|
+
const funcSubtractAssignment = new Assignment(Number_js_1.funcSubtract);
|
|
34
|
+
const funcMultiplyAssignment = new Assignment(Number_js_1.funcMultiply);
|
|
35
|
+
const funcDivideAssignment = new Assignment(Number_js_1.funcDivide);
|
|
36
|
+
const funcRemainderAssignment = new Assignment(Number_js_1.funcRemainder);
|
|
37
|
+
const symbolParenthesesOpen = Symbol();
|
|
38
|
+
const symbolParenthesesClose = Symbol();
|
|
39
|
+
const symbolBracketsOpen = Symbol();
|
|
40
|
+
const symbolBracketsClose = Symbol();
|
|
41
|
+
const symbolBracesOpen = Symbol();
|
|
42
|
+
const symbolBracesClose = Symbol();
|
|
43
|
+
const symbolSemicolonSeparator = Symbol();
|
|
44
|
+
const symbolColonSeparator = Symbol();
|
|
45
|
+
const symbolCommaSeparator = Symbol();
|
|
46
|
+
const symbolTildaMark = Symbol();
|
|
47
|
+
const symbolOptionalType = Symbol();
|
|
48
|
+
const symbolVariadicFunction = Symbol();
|
|
49
|
+
const symbolVariableDefinition = Symbol();
|
|
50
|
+
const symbolConstantDefinition = Symbol();
|
|
51
|
+
const symbolWhile = Symbol();
|
|
52
|
+
const symbolIf = Symbol();
|
|
53
|
+
const symbolElse = Symbol();
|
|
54
|
+
class ParserState extends ParserFrame_js_1.ParserFrame {
|
|
55
|
+
_fragment;
|
|
56
|
+
constructor(expr) {
|
|
57
|
+
super(expr);
|
|
58
|
+
}
|
|
59
|
+
get literalValue() {
|
|
60
|
+
return this._fragment.value;
|
|
61
|
+
}
|
|
62
|
+
get assignmentOperator() {
|
|
63
|
+
return this._fragment.operator;
|
|
64
|
+
}
|
|
65
|
+
get operator() {
|
|
66
|
+
return this._fragment;
|
|
67
|
+
}
|
|
68
|
+
get type() {
|
|
69
|
+
return this._fragment;
|
|
70
|
+
}
|
|
71
|
+
get token() {
|
|
72
|
+
return this._fragment;
|
|
73
|
+
}
|
|
74
|
+
get isOperator() {
|
|
75
|
+
return this._fragment instanceof Constant_js_1.Constant;
|
|
76
|
+
}
|
|
77
|
+
get isLiteral() {
|
|
78
|
+
return this._fragment instanceof Literal;
|
|
79
|
+
}
|
|
80
|
+
get isAssignment() {
|
|
81
|
+
return this._fragment instanceof Assignment;
|
|
82
|
+
}
|
|
83
|
+
get isType() {
|
|
84
|
+
return this._fragment instanceof Type_js_1.Type;
|
|
85
|
+
}
|
|
86
|
+
get isToken() {
|
|
87
|
+
return typeof this._fragment === 'string';
|
|
88
|
+
}
|
|
89
|
+
get isParenthesesOpen() {
|
|
90
|
+
return this._fragment === symbolParenthesesOpen;
|
|
91
|
+
}
|
|
92
|
+
get isParenthesesClose() {
|
|
93
|
+
return this._fragment === symbolParenthesesClose;
|
|
94
|
+
}
|
|
95
|
+
get isBracketsOpen() {
|
|
96
|
+
return this._fragment === symbolBracketsOpen;
|
|
97
|
+
}
|
|
98
|
+
get isBracketsClose() {
|
|
99
|
+
return this._fragment === symbolBracketsClose;
|
|
100
|
+
}
|
|
101
|
+
get isBracesOpen() {
|
|
102
|
+
return this._fragment === symbolBracesOpen;
|
|
103
|
+
}
|
|
104
|
+
get isBracesClose() {
|
|
105
|
+
return this._fragment === symbolBracesClose;
|
|
106
|
+
}
|
|
107
|
+
get isSemicolonSeparator() {
|
|
108
|
+
return this._fragment === symbolSemicolonSeparator;
|
|
109
|
+
}
|
|
110
|
+
get isColonSeparator() {
|
|
111
|
+
return this._fragment === symbolColonSeparator;
|
|
112
|
+
}
|
|
113
|
+
get isCommaSeparator() {
|
|
114
|
+
return this._fragment === symbolCommaSeparator;
|
|
115
|
+
}
|
|
116
|
+
get isTildaMark() {
|
|
117
|
+
return this._fragment === symbolTildaMark;
|
|
118
|
+
}
|
|
119
|
+
get isOptionalType() {
|
|
120
|
+
return this._fragment === symbolOptionalType;
|
|
121
|
+
}
|
|
122
|
+
get isVariadicFunction() {
|
|
123
|
+
return this._fragment === symbolVariadicFunction;
|
|
124
|
+
}
|
|
125
|
+
get isVariableDefinition() {
|
|
126
|
+
return this._fragment === symbolVariableDefinition;
|
|
127
|
+
}
|
|
128
|
+
get isConstantDefinition() {
|
|
129
|
+
return this._fragment === symbolConstantDefinition;
|
|
130
|
+
}
|
|
131
|
+
get isWhile() {
|
|
132
|
+
return this._fragment === symbolWhile;
|
|
133
|
+
}
|
|
134
|
+
get isIf() {
|
|
135
|
+
return this._fragment === symbolIf;
|
|
136
|
+
}
|
|
137
|
+
get isElse() {
|
|
138
|
+
return this._fragment === symbolElse;
|
|
139
|
+
}
|
|
140
|
+
get isVoid() {
|
|
141
|
+
return this._fragment == null;
|
|
142
|
+
}
|
|
143
|
+
openParentheses() {
|
|
144
|
+
if (!this.isParenthesesOpen) {
|
|
145
|
+
this.throwError('missing opening parentheses');
|
|
146
|
+
}
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
closeParentheses() {
|
|
150
|
+
if (!this.isParenthesesClose) {
|
|
151
|
+
this.throwError('missing closing parentheses');
|
|
152
|
+
}
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
openBrackets() {
|
|
156
|
+
if (!this.isBracketsOpen) {
|
|
157
|
+
this.throwError('missing opening brackets');
|
|
158
|
+
}
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
closeBrackets() {
|
|
162
|
+
if (!this.isBracketsClose) {
|
|
163
|
+
this.throwError('missing closing brackets');
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
openBraces() {
|
|
168
|
+
if (!this.isBracesOpen) {
|
|
169
|
+
this.throwError('missing opening braces');
|
|
170
|
+
}
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
closeBraces() {
|
|
174
|
+
if (!this.isBracesClose) {
|
|
175
|
+
this.throwError('missing closing braces');
|
|
176
|
+
}
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
separateByColon() {
|
|
180
|
+
if (!this.isColonSeparator) {
|
|
181
|
+
this.throwError('missing colon separator');
|
|
182
|
+
}
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
clone() {
|
|
186
|
+
const state = new ParserState(this._expr);
|
|
187
|
+
state._start = this._start;
|
|
188
|
+
state._end = this._end;
|
|
189
|
+
state._fragment = this._fragment;
|
|
190
|
+
return state;
|
|
191
|
+
}
|
|
192
|
+
next() {
|
|
193
|
+
this._fragment = undefined;
|
|
194
|
+
while (this._end < this._expr.length && this._fragment == null) {
|
|
195
|
+
this._start = this._end;
|
|
196
|
+
const c = this._expr.charAt(this._end);
|
|
197
|
+
++this._end;
|
|
198
|
+
switch (c) {
|
|
199
|
+
case ' ':
|
|
200
|
+
case '\t':
|
|
201
|
+
case '\n':
|
|
202
|
+
case '\r': break;
|
|
203
|
+
case '(':
|
|
204
|
+
this._fragment = symbolParenthesesOpen;
|
|
205
|
+
break;
|
|
206
|
+
case ')':
|
|
207
|
+
this._fragment = symbolParenthesesClose;
|
|
208
|
+
break;
|
|
209
|
+
case '[':
|
|
210
|
+
this._fragment = symbolBracketsOpen;
|
|
211
|
+
break;
|
|
212
|
+
case ']':
|
|
213
|
+
this._fragment = symbolBracketsClose;
|
|
214
|
+
break;
|
|
215
|
+
case '{':
|
|
216
|
+
this._fragment = symbolBracesOpen;
|
|
217
|
+
break;
|
|
218
|
+
case '}':
|
|
219
|
+
this._fragment = symbolBracesClose;
|
|
220
|
+
break;
|
|
221
|
+
case ';':
|
|
222
|
+
this._fragment = symbolSemicolonSeparator;
|
|
223
|
+
break;
|
|
224
|
+
case ':':
|
|
225
|
+
this._fragment = symbolColonSeparator;
|
|
226
|
+
break;
|
|
227
|
+
case ',':
|
|
228
|
+
this._fragment = symbolCommaSeparator;
|
|
229
|
+
break;
|
|
230
|
+
case '~':
|
|
231
|
+
this._fragment = symbolTildaMark;
|
|
232
|
+
break;
|
|
233
|
+
case '?':
|
|
234
|
+
switch (this._expr.charAt(this._end)) {
|
|
235
|
+
case '?':
|
|
236
|
+
++this._end;
|
|
237
|
+
this._fragment = Type_js_1.Type.Unknown;
|
|
238
|
+
break;
|
|
239
|
+
case ':':
|
|
240
|
+
++this._end;
|
|
241
|
+
this._fragment = Unknown_js_1.funcCoalesce;
|
|
242
|
+
break;
|
|
243
|
+
default:
|
|
244
|
+
this._fragment = symbolOptionalType;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
break;
|
|
248
|
+
case '|':
|
|
249
|
+
switch (this._expr.charAt(this._end)) {
|
|
250
|
+
case '=':
|
|
251
|
+
++this._end;
|
|
252
|
+
this._fragment = funcOrAssignment;
|
|
253
|
+
break;
|
|
254
|
+
default:
|
|
255
|
+
this._fragment = Boolean_js_1.funcOr;
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
case '&':
|
|
260
|
+
switch (this._expr.charAt(this._end)) {
|
|
261
|
+
case '=':
|
|
262
|
+
++this._end;
|
|
263
|
+
this._fragment = funcAndAssignment;
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
this._fragment = Boolean_js_1.funcAnd;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
case '>':
|
|
271
|
+
switch (this._expr.charAt(this._end)) {
|
|
272
|
+
case '=':
|
|
273
|
+
++this._end;
|
|
274
|
+
this._fragment = Number_js_1.funcGreaterOrEqual;
|
|
275
|
+
break;
|
|
276
|
+
default:
|
|
277
|
+
this._fragment = Number_js_1.funcGreaterThan;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
case '<':
|
|
282
|
+
switch (this._expr.charAt(this._end)) {
|
|
283
|
+
case '=':
|
|
284
|
+
++this._end;
|
|
285
|
+
this._fragment = Number_js_1.funcLessOrEqual;
|
|
286
|
+
break;
|
|
287
|
+
default:
|
|
288
|
+
this._fragment = Number_js_1.funcLessThan;
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
case '!':
|
|
293
|
+
switch (this._expr.charAt(this._end)) {
|
|
294
|
+
case '=':
|
|
295
|
+
++this._end;
|
|
296
|
+
this._fragment = Unknown_js_1.funcNotEqual;
|
|
297
|
+
break;
|
|
298
|
+
default:
|
|
299
|
+
this._fragment = Boolean_js_1.funcNot;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case '=':
|
|
304
|
+
switch (this._expr.charAt(this._end)) {
|
|
305
|
+
case '=':
|
|
306
|
+
++this._end;
|
|
307
|
+
this._fragment = Unknown_js_1.funcEqual;
|
|
308
|
+
break;
|
|
309
|
+
default:
|
|
310
|
+
this._fragment = funcAssignment;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case '+':
|
|
315
|
+
switch (this._expr.charAt(this._end)) {
|
|
316
|
+
case '=':
|
|
317
|
+
++this._end;
|
|
318
|
+
this._fragment = funcAddAssignment;
|
|
319
|
+
break;
|
|
320
|
+
default:
|
|
321
|
+
this._fragment = Enumerable_js_1.funcAdd;
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
break;
|
|
325
|
+
case '-':
|
|
326
|
+
switch (this._expr.charAt(this._end)) {
|
|
327
|
+
case '=':
|
|
328
|
+
++this._end;
|
|
329
|
+
this._fragment = funcSubtractAssignment;
|
|
330
|
+
break;
|
|
331
|
+
default:
|
|
332
|
+
this._fragment = Number_js_1.funcSubtract;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
break;
|
|
336
|
+
case '*':
|
|
337
|
+
switch (this._expr.charAt(this._end)) {
|
|
338
|
+
case '=':
|
|
339
|
+
++this._end;
|
|
340
|
+
this._fragment = funcMultiplyAssignment;
|
|
341
|
+
break;
|
|
342
|
+
default:
|
|
343
|
+
this._fragment = Number_js_1.funcMultiply;
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
break;
|
|
347
|
+
case '/':
|
|
348
|
+
switch (this._expr.charAt(this._end)) {
|
|
349
|
+
case '=':
|
|
350
|
+
++this._end;
|
|
351
|
+
this._fragment = funcDivideAssignment;
|
|
352
|
+
break;
|
|
353
|
+
default:
|
|
354
|
+
this._fragment = Number_js_1.funcDivide;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
case '%':
|
|
359
|
+
switch (this._expr.charAt(this._end)) {
|
|
360
|
+
case '=':
|
|
361
|
+
++this._end;
|
|
362
|
+
this._fragment = funcRemainderAssignment;
|
|
363
|
+
break;
|
|
364
|
+
default:
|
|
365
|
+
this._fragment = Number_js_1.funcRemainder;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
case '$':
|
|
370
|
+
switch (this._expr.charAt(this._end)) {
|
|
371
|
+
case '$':
|
|
372
|
+
while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== '\n') {
|
|
373
|
+
++this._end;
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== c) {
|
|
378
|
+
++this._end;
|
|
379
|
+
}
|
|
380
|
+
if (this._end >= this._expr.length) {
|
|
381
|
+
this._start = this._expr.length;
|
|
382
|
+
throw new Error(`missing closing comment mark ${c}`);
|
|
383
|
+
}
|
|
384
|
+
++this._end;
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
break;
|
|
388
|
+
case '^':
|
|
389
|
+
this._fragment = Number_js_1.funcPower;
|
|
390
|
+
break;
|
|
391
|
+
case '.':
|
|
392
|
+
switch (this._expr.charAt(this._end)) {
|
|
393
|
+
case '.':
|
|
394
|
+
if (this._expr.charAt(++this._end) === '.') {
|
|
395
|
+
++this._end;
|
|
396
|
+
this._fragment = symbolVariadicFunction;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
throw new Error('incomplete ellipsis ...');
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
default:
|
|
403
|
+
this._fragment = Iterable_js_1.funcAt;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
case '@':
|
|
408
|
+
while ((0, String_js_1.isDateSymbol)(this._expr.charAt(this._end))) {
|
|
409
|
+
++this._end;
|
|
410
|
+
}
|
|
411
|
+
if ((0, String_js_1.isDateTimeSeparator)(this._expr.charAt(this._end))) {
|
|
412
|
+
++this._end;
|
|
413
|
+
while ((0, String_js_1.isTimeSymbol)(this._expr.charAt(this._end))) {
|
|
414
|
+
++this._end;
|
|
415
|
+
}
|
|
416
|
+
if (this._expr.charAt(this._end) === '.') {
|
|
417
|
+
++this._end;
|
|
418
|
+
while ((0, String_js_1.isNumeric)(this._expr.charAt(this._end))) {
|
|
419
|
+
++this._end;
|
|
420
|
+
}
|
|
421
|
+
if (this._expr.charAt(this._end) === 'Z') {
|
|
422
|
+
++this._end;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
this._fragment = new Literal(new Date(this._expr.substring(this._start + 1, this._end)));
|
|
427
|
+
break;
|
|
428
|
+
case '#':
|
|
429
|
+
while ((0, String_js_1.isHexadecimal)(this._expr.charAt(this._end))) {
|
|
430
|
+
++this._end;
|
|
431
|
+
}
|
|
432
|
+
this._fragment = new Literal((0, Buffer_js_1.parseBuffer)(this._expr.substring(this._start + 1, this._end)));
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
if ((0, String_js_1.isAlpha)(c)) {
|
|
436
|
+
while ((0, String_js_1.isAlphanumeric)(this._expr.charAt(this._end))) {
|
|
437
|
+
++this._end;
|
|
438
|
+
}
|
|
439
|
+
const token = this._expr.substring(this._start, this._end);
|
|
440
|
+
switch (token) {
|
|
441
|
+
case 'true':
|
|
442
|
+
this._fragment = valueTrue;
|
|
443
|
+
break;
|
|
444
|
+
case 'false':
|
|
445
|
+
this._fragment = valueFalse;
|
|
446
|
+
break;
|
|
447
|
+
case 'null':
|
|
448
|
+
this._fragment = valueNull;
|
|
449
|
+
break;
|
|
450
|
+
case 'void':
|
|
451
|
+
this._fragment = Type_js_1.Type.Void;
|
|
452
|
+
break;
|
|
453
|
+
case 'bool':
|
|
454
|
+
case 'boolean':
|
|
455
|
+
this._fragment = Type_js_1.Type.Boolean;
|
|
456
|
+
break;
|
|
457
|
+
case 'time':
|
|
458
|
+
case 'timestamp':
|
|
459
|
+
this._fragment = Type_js_1.Type.Timestamp;
|
|
460
|
+
break;
|
|
461
|
+
case 'flo':
|
|
462
|
+
case 'float':
|
|
463
|
+
this._fragment = Type_js_1.Type.Float;
|
|
464
|
+
break;
|
|
465
|
+
case 'int':
|
|
466
|
+
case 'integer':
|
|
467
|
+
this._fragment = Type_js_1.Type.Integer;
|
|
468
|
+
break;
|
|
469
|
+
case 'buf':
|
|
470
|
+
case 'buffer':
|
|
471
|
+
this._fragment = Type_js_1.Type.Buffer;
|
|
472
|
+
break;
|
|
473
|
+
case 'str':
|
|
474
|
+
case 'string':
|
|
475
|
+
this._fragment = Type_js_1.Type.String;
|
|
476
|
+
break;
|
|
477
|
+
case 'arr':
|
|
478
|
+
case 'array':
|
|
479
|
+
this._fragment = Type_js_1.Type.Array;
|
|
480
|
+
break;
|
|
481
|
+
case 'obj':
|
|
482
|
+
case 'object':
|
|
483
|
+
this._fragment = Type_js_1.Type.Object;
|
|
484
|
+
break;
|
|
485
|
+
case 'func':
|
|
486
|
+
case 'function':
|
|
487
|
+
this._fragment = Type_js_1.Type.Function;
|
|
488
|
+
break;
|
|
489
|
+
case 'var':
|
|
490
|
+
case 'variable':
|
|
491
|
+
this._fragment = symbolVariableDefinition;
|
|
492
|
+
break;
|
|
493
|
+
case 'const':
|
|
494
|
+
case 'constant':
|
|
495
|
+
this._fragment = symbolConstantDefinition;
|
|
496
|
+
break;
|
|
497
|
+
case 'while':
|
|
498
|
+
this._fragment = symbolWhile;
|
|
499
|
+
break;
|
|
500
|
+
case 'if':
|
|
501
|
+
this._fragment = symbolIf;
|
|
502
|
+
break;
|
|
503
|
+
case 'else':
|
|
504
|
+
this._fragment = symbolElse;
|
|
505
|
+
break;
|
|
506
|
+
default:
|
|
507
|
+
this._fragment = token;
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
else if ((0, String_js_1.isNumeric)(c)) {
|
|
512
|
+
let integer = true;
|
|
513
|
+
while ((0, String_js_1.isNumeric)(this._expr.charAt(this._end))) {
|
|
514
|
+
++this._end;
|
|
515
|
+
}
|
|
516
|
+
if (this._expr.charAt(this._end) === '.') {
|
|
517
|
+
++this._end;
|
|
518
|
+
if ((0, String_js_1.isNumeric)(this._expr.charAt(this._end))) {
|
|
519
|
+
++this._end;
|
|
520
|
+
while ((0, String_js_1.isNumeric)(this._expr.charAt(this._end))) {
|
|
521
|
+
++this._end;
|
|
522
|
+
}
|
|
523
|
+
integer = false;
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
--this._end;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (this._expr.charAt(this._end) === 'e') {
|
|
530
|
+
++this._end;
|
|
531
|
+
if ((0, String_js_1.isNumeric)(this._expr.charAt(this._end)) || (0, String_js_1.isSign)(this._expr.charAt(this._end))) {
|
|
532
|
+
++this._end;
|
|
533
|
+
while ((0, String_js_1.isNumeric)(this._expr.charAt(this._end))) {
|
|
534
|
+
++this._end;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
integer = false;
|
|
538
|
+
}
|
|
539
|
+
this._fragment = integer
|
|
540
|
+
? new Literal(BigInt(this._expr.substring(this._start, this._end)))
|
|
541
|
+
: new Literal(parseFloat(this._expr.substring(this._start, this._end)));
|
|
542
|
+
}
|
|
543
|
+
else if ((0, String_js_1.isQuotation)(c)) {
|
|
544
|
+
while (this._expr.charAt(this._end) !== '' && this._expr.charAt(this._end) !== c) {
|
|
545
|
+
++this._end;
|
|
546
|
+
}
|
|
547
|
+
if (this._end >= this._expr.length) {
|
|
548
|
+
this._start = this._expr.length;
|
|
549
|
+
throw new Error(`missing closing quotation mark ${c}`);
|
|
550
|
+
}
|
|
551
|
+
this._fragment = new Literal(this._expr.substring(this._start + 1, this._end));
|
|
552
|
+
++this._end;
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
throw new Error(`unknown symbol ${c}`);
|
|
556
|
+
}
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (this._end > this._expr.length) {
|
|
561
|
+
this._start = this._end = this._expr.length;
|
|
562
|
+
}
|
|
563
|
+
return this;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
exports.ParserState = ParserState;
|