@junoscript/juno 0.0.0-stage → 0.1.2
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/Modules/async.ts +81 -0
- package/Modules/juno-node-fs.ts +105 -0
- package/Modules/juno-test.jn +156 -0
- package/dist/CLI/build-juno.d.ts +5 -0
- package/dist/CLI/build-juno.js +58 -0
- package/dist/CLI/generate-juno-types.d.ts +1 -0
- package/dist/CLI/generate-juno-types.js +54 -0
- package/dist/CLI/junode.d.ts +2 -0
- package/dist/CLI/junode.js +58 -0
- package/dist/Lexer/lexer.d.ts +42 -0
- package/dist/Lexer/lexer.js +300 -0
- package/dist/Lexer/parser.d.ts +403 -0
- package/dist/Lexer/parser.js +1930 -0
- package/dist/Modules/async.d.ts +33 -0
- package/dist/Modules/async.js +76 -0
- package/dist/Modules/bytes.d.ts +15 -0
- package/dist/Modules/bytes.js +35 -0
- package/dist/Modules/index.d.ts +201 -0
- package/dist/Modules/index.js +35 -0
- package/dist/Modules/juno-node-fs.d.ts +52 -0
- package/dist/Modules/juno-node-fs.js +129 -0
- package/dist/Modules/juno-node.d.ts +74 -0
- package/dist/Modules/juno-node.js +56 -0
- package/dist/Modules/juno-test.d.ts +141 -0
- package/dist/Modules/juno-test.js +134 -0
- package/dist/Modules/juno-types.d.ts +35 -0
- package/dist/Modules/juno-types.js +2 -0
- package/dist/Modules/juno.d.ts +24 -0
- package/dist/Modules/juno.js +84 -0
- package/dist/Modules/types.d.ts +61 -0
- package/dist/Modules/types.js +95 -0
- package/dist/Runtime/interpreter.d.ts +64 -0
- package/dist/Runtime/interpreter.js +2630 -0
- package/dist/Runtime/resolve-import.d.ts +2 -0
- package/dist/Runtime/resolve-import.js +30 -0
- package/dist/vscode-junoscript/src/language.d.ts +86 -0
- package/dist/vscode-junoscript/src/language.js +4481 -0
- package/package.json +20 -4
- package/types/array.jn +158 -0
- package/types/boolean.jn +18 -0
- package/types/error.jn +28 -0
- package/types/error.ts +9 -0
- package/types/index.jn +11 -0
- package/types/iterable.jn +211 -0
- package/types/map.jn +44 -0
- package/types/map.ts +132 -0
- package/types/number.ts +52 -0
- package/types/object.jn +94 -0
- package/types/object.ts +49 -0
- package/types/queue.jn +46 -0
- package/types/random.jn +25 -0
- package/types/random.ts +1 -0
- package/types/range.jn +27 -0
- package/types/set.jn +139 -0
- package/types/set.ts +209 -0
- package/types/string.jn +33 -0
- package/types/string.ts +1 -0
- package/types/tuple.jn +11 -0
- package/README.md +0 -3
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Lexer = Lexer;
|
|
4
|
+
const keywords = new Set([
|
|
5
|
+
'let', 'const', 'fun', 'type', 'return', 'break', 'if', 'else', 'for', 'of',
|
|
6
|
+
'while', 'match', 'case', 'when', 'true', 'false', 'null', 'readonly', 'sealed', 'static', 'as', 'in',
|
|
7
|
+
'import', 'from', 'export', 'default', 'constructor', 'try', 'catch', 'finally', 'await'
|
|
8
|
+
]);
|
|
9
|
+
function Lexer(source) {
|
|
10
|
+
return {
|
|
11
|
+
pos: 0,
|
|
12
|
+
source,
|
|
13
|
+
get current() {
|
|
14
|
+
return source[this.pos] ?? '';
|
|
15
|
+
},
|
|
16
|
+
get isAtEnd() {
|
|
17
|
+
return this.pos >= source.length;
|
|
18
|
+
},
|
|
19
|
+
tokenize() {
|
|
20
|
+
const tokens = [];
|
|
21
|
+
const indents = [0];
|
|
22
|
+
let line = 1;
|
|
23
|
+
let column = 1;
|
|
24
|
+
let lineStart = true;
|
|
25
|
+
let continuedLine = false;
|
|
26
|
+
const push = (type, value, l = line, c = column) => {
|
|
27
|
+
if (type === 'Number') {
|
|
28
|
+
tokens.push({ type, value: value, line: l, column: c });
|
|
29
|
+
}
|
|
30
|
+
else if (type === 'BigInt') {
|
|
31
|
+
tokens.push({ type, value: value, line: l, column: c });
|
|
32
|
+
}
|
|
33
|
+
else if (type === 'String') {
|
|
34
|
+
tokens.push({ type, value: value, line: l, column: c });
|
|
35
|
+
}
|
|
36
|
+
else if (type === 'RegEx') {
|
|
37
|
+
tokens.push({ type, value: value, line: l, column: c });
|
|
38
|
+
}
|
|
39
|
+
else if (type === 'Identifier' || type === 'Keyword') {
|
|
40
|
+
tokens.push({ type, value: String(value), line: l, column: c });
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
tokens.push({ type, line: l, column: c });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const advance = () => {
|
|
47
|
+
const character = this.current;
|
|
48
|
+
this.pos++;
|
|
49
|
+
if (character === '\n') {
|
|
50
|
+
line++;
|
|
51
|
+
column = 1;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
column++;
|
|
55
|
+
}
|
|
56
|
+
return character;
|
|
57
|
+
};
|
|
58
|
+
while (!this.isAtEnd) {
|
|
59
|
+
if (lineStart) {
|
|
60
|
+
let width = 0;
|
|
61
|
+
while (this.current === ' ' || this.current === '\t') {
|
|
62
|
+
width += advance() === '\t' ? 4 : 1;
|
|
63
|
+
}
|
|
64
|
+
if (this.current === '\r')
|
|
65
|
+
advance();
|
|
66
|
+
if (this.current === '\n') {
|
|
67
|
+
advance();
|
|
68
|
+
push('Newline', undefined, line - 1, 1);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (this.current === '#') {
|
|
72
|
+
while (!this.isAtEnd && source[this.pos] !== '\n')
|
|
73
|
+
advance();
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (continuedLine) {
|
|
77
|
+
continuedLine = false;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const currentIndent = indents[indents.length - 1];
|
|
81
|
+
if (width > currentIndent) {
|
|
82
|
+
indents.push(width);
|
|
83
|
+
push('Indent');
|
|
84
|
+
}
|
|
85
|
+
else if (width < currentIndent) {
|
|
86
|
+
while (indents.length > 1 && width < indents[indents.length - 1]) {
|
|
87
|
+
indents.pop();
|
|
88
|
+
push('Dedent');
|
|
89
|
+
}
|
|
90
|
+
if (width !== indents[indents.length - 1]) {
|
|
91
|
+
throw new SyntaxError(`Inconsistent indentation at ${line}:${column}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
lineStart = false;
|
|
96
|
+
}
|
|
97
|
+
const character = this.current;
|
|
98
|
+
const tokenLine = line;
|
|
99
|
+
const tokenColumn = column;
|
|
100
|
+
if (source.slice(this.pos, this.pos + 3) === '...') {
|
|
101
|
+
advance();
|
|
102
|
+
advance();
|
|
103
|
+
advance();
|
|
104
|
+
push('Ellipsis', undefined, tokenLine, tokenColumn);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (character === ' ' || character === '\t' || character === '\r') {
|
|
108
|
+
advance();
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (character === '\n') {
|
|
112
|
+
advance();
|
|
113
|
+
push('Newline', undefined, tokenLine, tokenColumn);
|
|
114
|
+
lineStart = true;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
// A trailing backslash joins the next physical line to the
|
|
118
|
+
// current expression. Keep indentation processing on the next
|
|
119
|
+
// line, but do not emit a statement-separating Newline token.
|
|
120
|
+
if (character === '\\' && (source[this.pos + 1] === '\n' || source[this.pos + 1] === '\r')) {
|
|
121
|
+
advance();
|
|
122
|
+
if (this.current === '\r')
|
|
123
|
+
advance();
|
|
124
|
+
if (this.current === '\n')
|
|
125
|
+
advance();
|
|
126
|
+
lineStart = true;
|
|
127
|
+
continuedLine = true;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
if (character === '#') {
|
|
131
|
+
while (!this.isAtEnd && this.current !== '\n')
|
|
132
|
+
advance();
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (/[0-9]/.test(character)) {
|
|
136
|
+
let raw = '';
|
|
137
|
+
while (/[0-9]/.test(this.current))
|
|
138
|
+
raw += advance();
|
|
139
|
+
const isDecimal = this.current === '.' &&
|
|
140
|
+
/[0-9]/.test(source[this.pos + 1] ?? '');
|
|
141
|
+
if (isDecimal) {
|
|
142
|
+
raw += advance();
|
|
143
|
+
while (/[0-9]/.test(this.current))
|
|
144
|
+
raw += advance();
|
|
145
|
+
}
|
|
146
|
+
if (!isDecimal && this.current === 'n') {
|
|
147
|
+
advance();
|
|
148
|
+
push('BigInt', BigInt(raw), tokenLine, tokenColumn);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
push('Number', Number(raw), tokenLine, tokenColumn);
|
|
152
|
+
}
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (/[A-Za-z_$]/.test(character)) {
|
|
156
|
+
let value = '';
|
|
157
|
+
while (/[A-Za-z0-9_$]/.test(this.current))
|
|
158
|
+
value += advance();
|
|
159
|
+
push(keywords.has(value) ? 'Keyword' : 'Identifier', value, tokenLine, tokenColumn);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (character === '"' || character === "'" || character === '`') {
|
|
163
|
+
const quote = advance();
|
|
164
|
+
let value = '';
|
|
165
|
+
let closed = false;
|
|
166
|
+
while (!this.isAtEnd) {
|
|
167
|
+
const current = advance();
|
|
168
|
+
if (current === '\n' && quote !== '`') {
|
|
169
|
+
throw new SyntaxError(`Unterminated string at ${tokenLine}:${tokenColumn}`);
|
|
170
|
+
}
|
|
171
|
+
if (current === quote) {
|
|
172
|
+
closed = true;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
if (current === '\\') {
|
|
176
|
+
if (this.isAtEnd)
|
|
177
|
+
break;
|
|
178
|
+
const escaped = advance();
|
|
179
|
+
value += escaped === '$' ? '\uE000' : ({ n: '\n', r: '\r', t: '\t', '0': '\0' }[escaped] ?? escaped);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
value += current;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (!closed) {
|
|
186
|
+
throw new SyntaxError(`Unterminated string at ${tokenLine}:${tokenColumn}`);
|
|
187
|
+
}
|
|
188
|
+
push('String', value, tokenLine, tokenColumn);
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
// A slash starts a regular-expression literal only where an
|
|
192
|
+
// expression can begin; after a value it remains division.
|
|
193
|
+
if (character === '/') {
|
|
194
|
+
const previous = tokens[tokens.length - 1];
|
|
195
|
+
const endsExpression = previous && (['Number', 'BigInt', 'String', 'RegEx', 'Identifier', 'RightParen', 'RightBracket', 'RightBrace', 'Increment', 'Decrement'].includes(previous.type) ||
|
|
196
|
+
previous.type === 'Keyword' && ['true', 'false', 'null'].includes(previous.value));
|
|
197
|
+
if (!endsExpression && source[this.pos + 1] !== '=' && source[this.pos + 1] !== '/') {
|
|
198
|
+
advance();
|
|
199
|
+
let pattern = '';
|
|
200
|
+
let escaped = false;
|
|
201
|
+
let inClass = false;
|
|
202
|
+
let closed = false;
|
|
203
|
+
while (!this.isAtEnd) {
|
|
204
|
+
const current = advance();
|
|
205
|
+
if (current === '\n' || current === '\r')
|
|
206
|
+
throw new SyntaxError(`Unterminated regular expression at ${tokenLine}:${tokenColumn}`);
|
|
207
|
+
if (!escaped && current === '[')
|
|
208
|
+
inClass = true;
|
|
209
|
+
else if (!escaped && current === ']')
|
|
210
|
+
inClass = false;
|
|
211
|
+
else if (!escaped && current === '/' && !inClass) {
|
|
212
|
+
closed = true;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
pattern += current;
|
|
216
|
+
escaped = !escaped && current === '\\';
|
|
217
|
+
if (current !== '\\')
|
|
218
|
+
escaped = false;
|
|
219
|
+
}
|
|
220
|
+
if (!closed)
|
|
221
|
+
throw new SyntaxError(`Unterminated regular expression at ${tokenLine}:${tokenColumn}`);
|
|
222
|
+
let flags = '';
|
|
223
|
+
while (/[A-Za-z]/.test(this.current))
|
|
224
|
+
flags += advance();
|
|
225
|
+
try {
|
|
226
|
+
new RegExp(pattern, flags);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
throw new SyntaxError(`Invalid regular expression at ${tokenLine}:${tokenColumn}: ${error instanceof Error ? error.message : String(error)}`);
|
|
230
|
+
}
|
|
231
|
+
push('RegEx', { source: pattern, flags }, tokenLine, tokenColumn);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const pairs = {
|
|
236
|
+
'++': 'Increment',
|
|
237
|
+
'--': 'Decrement',
|
|
238
|
+
'+=': 'PlusEqual',
|
|
239
|
+
'-=': 'MinusEqual',
|
|
240
|
+
'*=': 'MultiplyEqual',
|
|
241
|
+
'/=': 'DivideEqual',
|
|
242
|
+
'%=': 'PercentEqual',
|
|
243
|
+
'|=': 'PipeEqual',
|
|
244
|
+
'&=': 'AmpersandEqual',
|
|
245
|
+
'==': 'EqualEqual',
|
|
246
|
+
'!=': 'NotEqual',
|
|
247
|
+
'<=': 'LessEqual',
|
|
248
|
+
'>=': 'GreaterEqual',
|
|
249
|
+
'??': 'Nullish',
|
|
250
|
+
'=>': 'FatArrow',
|
|
251
|
+
'->': 'Arrow'
|
|
252
|
+
};
|
|
253
|
+
const pair = character + (source[this.pos + 1] ?? '');
|
|
254
|
+
if (pairs[pair]) {
|
|
255
|
+
advance();
|
|
256
|
+
advance();
|
|
257
|
+
push(pairs[pair], undefined, tokenLine, tokenColumn);
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const singles = {
|
|
261
|
+
'+': 'Plus',
|
|
262
|
+
'-': 'Minus',
|
|
263
|
+
'*': 'Multiply',
|
|
264
|
+
'/': 'Divide',
|
|
265
|
+
'%': 'Percent',
|
|
266
|
+
'=': 'Equal',
|
|
267
|
+
'<': 'Less',
|
|
268
|
+
'>': 'Greater',
|
|
269
|
+
':': 'Colon',
|
|
270
|
+
',': 'Comma',
|
|
271
|
+
'.': 'Dot',
|
|
272
|
+
'?': 'Question',
|
|
273
|
+
'|': 'Pipe',
|
|
274
|
+
'&': 'Ampersand',
|
|
275
|
+
'!': 'Bang',
|
|
276
|
+
'(': 'LeftParen',
|
|
277
|
+
')': 'RightParen',
|
|
278
|
+
'[': 'LeftBracket',
|
|
279
|
+
']': 'RightBracket',
|
|
280
|
+
'{': 'LeftBrace',
|
|
281
|
+
'}': 'RightBrace'
|
|
282
|
+
};
|
|
283
|
+
if (!singles[character]) {
|
|
284
|
+
throw new SyntaxError(`Unexpected character '${character}' at ${tokenLine}:${tokenColumn}`);
|
|
285
|
+
}
|
|
286
|
+
advance();
|
|
287
|
+
push(singles[character], undefined, tokenLine, tokenColumn);
|
|
288
|
+
}
|
|
289
|
+
if (source.length && !lineStart && tokens[tokens.length - 1]?.type !== 'Newline') {
|
|
290
|
+
push('Newline', undefined, line, column);
|
|
291
|
+
}
|
|
292
|
+
while (indents.length > 1) {
|
|
293
|
+
indents.pop();
|
|
294
|
+
push('Dedent');
|
|
295
|
+
}
|
|
296
|
+
push('EOF');
|
|
297
|
+
return tokens;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Token } from './lexer';
|
|
2
|
+
export type Loc = {
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function indexedTypeQuery(expression: Expression): (Extract<TypeNode, {
|
|
7
|
+
kind: 'IndexedAccessType';
|
|
8
|
+
}> & {
|
|
9
|
+
object: Extract<TypeNode, {
|
|
10
|
+
kind: 'NamedType';
|
|
11
|
+
}>;
|
|
12
|
+
}) | undefined;
|
|
13
|
+
export type TypeNode = {
|
|
14
|
+
kind: 'NamedType';
|
|
15
|
+
name: string;
|
|
16
|
+
loc?: Loc;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'LiteralType';
|
|
19
|
+
value: string | number | boolean;
|
|
20
|
+
loc?: Loc;
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'GenericType';
|
|
23
|
+
name: string;
|
|
24
|
+
args: TypeNode[];
|
|
25
|
+
loc?: Loc;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'UnionType' | 'IntersectionType';
|
|
28
|
+
types: TypeNode[];
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'ArrayType';
|
|
31
|
+
element: TypeNode;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'IndexedAccessType';
|
|
34
|
+
object: TypeNode;
|
|
35
|
+
index: TypeNode;
|
|
36
|
+
loc?: Loc;
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'TypeOfType';
|
|
39
|
+
expression: Expression;
|
|
40
|
+
loc?: Loc;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'ConditionalType';
|
|
43
|
+
check: TypeNode;
|
|
44
|
+
target: TypeNode;
|
|
45
|
+
consequent: TypeNode;
|
|
46
|
+
alternate: TypeNode;
|
|
47
|
+
loc?: Loc;
|
|
48
|
+
} | {
|
|
49
|
+
kind: 'ObjectType';
|
|
50
|
+
members: TypeMember[];
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'FunctionType';
|
|
53
|
+
params: TypeNode[];
|
|
54
|
+
paramNames?: (string | undefined)[];
|
|
55
|
+
optionalFrom?: number;
|
|
56
|
+
rest?: TypeNode;
|
|
57
|
+
restName?: string;
|
|
58
|
+
genericParameters?: GenericParameter[];
|
|
59
|
+
result: TypeNode;
|
|
60
|
+
};
|
|
61
|
+
type GenericParameter = {
|
|
62
|
+
name: string;
|
|
63
|
+
loc: Loc;
|
|
64
|
+
constraint?: TypeNode;
|
|
65
|
+
defaultType?: TypeNode;
|
|
66
|
+
};
|
|
67
|
+
export type TypeMember = {
|
|
68
|
+
name: string;
|
|
69
|
+
loc?: Loc;
|
|
70
|
+
type: TypeNode;
|
|
71
|
+
optional: boolean;
|
|
72
|
+
readonly: boolean;
|
|
73
|
+
sealed?: boolean;
|
|
74
|
+
constant: boolean;
|
|
75
|
+
defaultValue?: Expression;
|
|
76
|
+
method?: boolean;
|
|
77
|
+
accessor?: 'get' | 'set';
|
|
78
|
+
indexType?: TypeNode;
|
|
79
|
+
generics?: string[];
|
|
80
|
+
genericLocs?: Loc[];
|
|
81
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
82
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
83
|
+
params?: Parameter[];
|
|
84
|
+
body?: Statement[];
|
|
85
|
+
};
|
|
86
|
+
export type Parameter = {
|
|
87
|
+
name: string;
|
|
88
|
+
loc?: Loc;
|
|
89
|
+
type?: TypeNode;
|
|
90
|
+
defaultValue?: Expression;
|
|
91
|
+
rest?: boolean;
|
|
92
|
+
};
|
|
93
|
+
export type MatchPattern = {
|
|
94
|
+
kind: 'PatternLiteral';
|
|
95
|
+
value: string | number | bigint | boolean | null;
|
|
96
|
+
loc?: Loc;
|
|
97
|
+
} | {
|
|
98
|
+
kind: 'PatternIdentifier';
|
|
99
|
+
name: string;
|
|
100
|
+
nullable?: boolean;
|
|
101
|
+
loc?: Loc;
|
|
102
|
+
} | {
|
|
103
|
+
kind: 'PatternObject';
|
|
104
|
+
properties: {
|
|
105
|
+
name: string;
|
|
106
|
+
pattern?: MatchPattern;
|
|
107
|
+
loc?: Loc;
|
|
108
|
+
}[];
|
|
109
|
+
loc?: Loc;
|
|
110
|
+
} | {
|
|
111
|
+
kind: 'PatternUnion';
|
|
112
|
+
patterns: MatchPattern[];
|
|
113
|
+
loc?: Loc;
|
|
114
|
+
};
|
|
115
|
+
export type Expression = {
|
|
116
|
+
kind: 'Literal';
|
|
117
|
+
value: string | number | bigint | boolean | null;
|
|
118
|
+
loc?: Loc;
|
|
119
|
+
} | {
|
|
120
|
+
kind: 'RegEx';
|
|
121
|
+
source: string;
|
|
122
|
+
flags: string;
|
|
123
|
+
loc?: Loc;
|
|
124
|
+
} | {
|
|
125
|
+
kind: 'Template';
|
|
126
|
+
parts: (string | Expression)[];
|
|
127
|
+
loc?: Loc;
|
|
128
|
+
} | {
|
|
129
|
+
kind: 'Identifier';
|
|
130
|
+
name: string;
|
|
131
|
+
loc?: Loc;
|
|
132
|
+
} | {
|
|
133
|
+
kind: 'Array';
|
|
134
|
+
elements: Expression[];
|
|
135
|
+
loc?: Loc;
|
|
136
|
+
} | {
|
|
137
|
+
kind: 'Spread';
|
|
138
|
+
value: Expression;
|
|
139
|
+
loc?: Loc;
|
|
140
|
+
} | {
|
|
141
|
+
kind: 'Object';
|
|
142
|
+
properties: {
|
|
143
|
+
key: string;
|
|
144
|
+
keyLoc?: Loc;
|
|
145
|
+
value: Expression;
|
|
146
|
+
accessor?: 'get' | 'set';
|
|
147
|
+
spread?: boolean;
|
|
148
|
+
readonly?: boolean;
|
|
149
|
+
sealed?: boolean;
|
|
150
|
+
typeOnly?: boolean;
|
|
151
|
+
indexType?: TypeNode;
|
|
152
|
+
declaredType?: TypeNode;
|
|
153
|
+
}[];
|
|
154
|
+
loc?: Loc;
|
|
155
|
+
} | {
|
|
156
|
+
kind: 'Unary';
|
|
157
|
+
operator: string;
|
|
158
|
+
operand: Expression;
|
|
159
|
+
loc?: Loc;
|
|
160
|
+
} | {
|
|
161
|
+
kind: 'Assignment';
|
|
162
|
+
name: string;
|
|
163
|
+
loc?: Loc;
|
|
164
|
+
operatorLoc?: Loc;
|
|
165
|
+
operator?: string;
|
|
166
|
+
value: Expression;
|
|
167
|
+
} | {
|
|
168
|
+
kind: 'MemberAssignment';
|
|
169
|
+
object: Expression;
|
|
170
|
+
property?: string;
|
|
171
|
+
propertyLoc?: Loc;
|
|
172
|
+
index?: Expression;
|
|
173
|
+
loc?: Loc;
|
|
174
|
+
operator?: string;
|
|
175
|
+
value: Expression;
|
|
176
|
+
} | {
|
|
177
|
+
kind: 'Binary';
|
|
178
|
+
operator: string;
|
|
179
|
+
left: Expression;
|
|
180
|
+
right: Expression;
|
|
181
|
+
loc?: Loc;
|
|
182
|
+
} | {
|
|
183
|
+
kind: 'Conditional';
|
|
184
|
+
condition: Expression;
|
|
185
|
+
consequent: Expression;
|
|
186
|
+
alternate: Expression;
|
|
187
|
+
loc?: Loc;
|
|
188
|
+
} | {
|
|
189
|
+
kind: 'Match';
|
|
190
|
+
value: Expression;
|
|
191
|
+
cases: {
|
|
192
|
+
pattern?: MatchPattern;
|
|
193
|
+
guard?: Expression;
|
|
194
|
+
body: Statement[];
|
|
195
|
+
loc?: Loc;
|
|
196
|
+
}[];
|
|
197
|
+
loc?: Loc;
|
|
198
|
+
} | {
|
|
199
|
+
kind: 'Try';
|
|
200
|
+
value?: Expression;
|
|
201
|
+
body?: Statement[];
|
|
202
|
+
catches: {
|
|
203
|
+
binding?: string;
|
|
204
|
+
bindingLoc?: Loc;
|
|
205
|
+
type?: TypeNode;
|
|
206
|
+
body: Statement[];
|
|
207
|
+
loc?: Loc;
|
|
208
|
+
}[];
|
|
209
|
+
finallyBody?: Statement[];
|
|
210
|
+
loc?: Loc;
|
|
211
|
+
} | {
|
|
212
|
+
kind: 'Is';
|
|
213
|
+
value: Expression;
|
|
214
|
+
type: TypeNode;
|
|
215
|
+
loc?: Loc;
|
|
216
|
+
} | {
|
|
217
|
+
kind: 'Member';
|
|
218
|
+
object: Expression;
|
|
219
|
+
property: string;
|
|
220
|
+
optional: boolean;
|
|
221
|
+
loc?: Loc;
|
|
222
|
+
} | {
|
|
223
|
+
kind: 'Index';
|
|
224
|
+
object: Expression;
|
|
225
|
+
index: Expression;
|
|
226
|
+
loc?: Loc;
|
|
227
|
+
} | {
|
|
228
|
+
kind: 'Call';
|
|
229
|
+
callee: Expression;
|
|
230
|
+
args: Expression[];
|
|
231
|
+
typeArguments?: TypeNode[];
|
|
232
|
+
} | {
|
|
233
|
+
kind: 'Function';
|
|
234
|
+
loc?: Loc;
|
|
235
|
+
generics?: string[];
|
|
236
|
+
genericLocs?: Loc[];
|
|
237
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
238
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
239
|
+
params: Parameter[];
|
|
240
|
+
returnType?: TypeNode;
|
|
241
|
+
body: Statement[];
|
|
242
|
+
expressionBody?: Expression;
|
|
243
|
+
};
|
|
244
|
+
export type Statement = {
|
|
245
|
+
kind: 'Variable';
|
|
246
|
+
name: string;
|
|
247
|
+
loc?: Loc;
|
|
248
|
+
mutable: boolean;
|
|
249
|
+
type?: TypeNode;
|
|
250
|
+
initializer?: Expression;
|
|
251
|
+
} | {
|
|
252
|
+
kind: 'Destructure';
|
|
253
|
+
bindings: {
|
|
254
|
+
name: string;
|
|
255
|
+
loc?: Loc;
|
|
256
|
+
}[];
|
|
257
|
+
mutable: boolean;
|
|
258
|
+
initializer: Expression;
|
|
259
|
+
} | {
|
|
260
|
+
kind: 'ArrayDestructure';
|
|
261
|
+
bindings: {
|
|
262
|
+
name?: string;
|
|
263
|
+
loc?: Loc;
|
|
264
|
+
index: number;
|
|
265
|
+
rest?: boolean;
|
|
266
|
+
}[];
|
|
267
|
+
mutable: boolean;
|
|
268
|
+
initializer: Expression;
|
|
269
|
+
} | {
|
|
270
|
+
kind: 'Import';
|
|
271
|
+
module: string;
|
|
272
|
+
defaultImport?: string;
|
|
273
|
+
defaultImportLoc?: Loc;
|
|
274
|
+
namedImports: string[];
|
|
275
|
+
namedImportLocs?: Loc[];
|
|
276
|
+
importedTypes?: Record<string, TypeNode>;
|
|
277
|
+
importedSymbols?: Record<string, {
|
|
278
|
+
kind: string;
|
|
279
|
+
value?: TypeNode;
|
|
280
|
+
generics?: string[];
|
|
281
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
282
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
283
|
+
params?: Parameter[];
|
|
284
|
+
returnType?: TypeNode;
|
|
285
|
+
type?: TypeNode;
|
|
286
|
+
inheritedType?: TypeNode;
|
|
287
|
+
overloads?: {
|
|
288
|
+
params: Parameter[];
|
|
289
|
+
returnType: TypeNode;
|
|
290
|
+
}[];
|
|
291
|
+
methods?: {
|
|
292
|
+
name: string;
|
|
293
|
+
generics?: string[];
|
|
294
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
295
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
296
|
+
params: Parameter[];
|
|
297
|
+
returnType: TypeNode;
|
|
298
|
+
}[];
|
|
299
|
+
}>;
|
|
300
|
+
} | {
|
|
301
|
+
kind: 'Export';
|
|
302
|
+
declaration: Statement;
|
|
303
|
+
default?: boolean;
|
|
304
|
+
} | {
|
|
305
|
+
kind: 'FunctionDeclaration';
|
|
306
|
+
name: string;
|
|
307
|
+
loc?: Loc;
|
|
308
|
+
generics?: string[];
|
|
309
|
+
genericLocs?: Loc[];
|
|
310
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
311
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
312
|
+
params: Parameter[];
|
|
313
|
+
returnType?: TypeNode;
|
|
314
|
+
body: Statement[];
|
|
315
|
+
} | {
|
|
316
|
+
kind: 'TypeDeclaration';
|
|
317
|
+
name: string;
|
|
318
|
+
loc?: Loc;
|
|
319
|
+
generics: string[];
|
|
320
|
+
genericLocs?: Loc[];
|
|
321
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
322
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
323
|
+
value: TypeNode;
|
|
324
|
+
} | {
|
|
325
|
+
kind: 'ConstructorDeclaration';
|
|
326
|
+
name: string;
|
|
327
|
+
loc?: Loc;
|
|
328
|
+
generics: string[];
|
|
329
|
+
genericLocs?: Loc[];
|
|
330
|
+
genericConstraints?: (TypeNode | undefined)[];
|
|
331
|
+
genericDefaults?: (TypeNode | undefined)[];
|
|
332
|
+
inheritedType: TypeNode;
|
|
333
|
+
overloads: Extract<Expression, {
|
|
334
|
+
kind: 'Function';
|
|
335
|
+
}>[];
|
|
336
|
+
methods: Extract<Statement, {
|
|
337
|
+
kind: 'FunctionDeclaration';
|
|
338
|
+
}>[];
|
|
339
|
+
} | {
|
|
340
|
+
kind: 'Return';
|
|
341
|
+
value?: Expression;
|
|
342
|
+
} | {
|
|
343
|
+
kind: 'Break';
|
|
344
|
+
loc?: Loc;
|
|
345
|
+
} | {
|
|
346
|
+
kind: 'ExpressionStatement';
|
|
347
|
+
expression: Expression;
|
|
348
|
+
} | {
|
|
349
|
+
kind: 'If';
|
|
350
|
+
condition: Expression;
|
|
351
|
+
consequent: Statement[];
|
|
352
|
+
alternate?: Statement[];
|
|
353
|
+
} | {
|
|
354
|
+
kind: 'ForOf';
|
|
355
|
+
binding: string;
|
|
356
|
+
loc?: Loc;
|
|
357
|
+
mutable: boolean;
|
|
358
|
+
iterable: Expression;
|
|
359
|
+
body: Statement[];
|
|
360
|
+
} | {
|
|
361
|
+
kind: 'While';
|
|
362
|
+
condition: Expression;
|
|
363
|
+
body: Statement[];
|
|
364
|
+
};
|
|
365
|
+
export declare class Parser {
|
|
366
|
+
private readonly tokens;
|
|
367
|
+
private pos;
|
|
368
|
+
private softExpressionIndents;
|
|
369
|
+
constructor(tokens: Token[]);
|
|
370
|
+
get current(): Token;
|
|
371
|
+
private is;
|
|
372
|
+
private take;
|
|
373
|
+
private value;
|
|
374
|
+
private match;
|
|
375
|
+
private fail;
|
|
376
|
+
private loc;
|
|
377
|
+
private identifier;
|
|
378
|
+
private propertyName;
|
|
379
|
+
private separators;
|
|
380
|
+
private objectSeparators;
|
|
381
|
+
private parenthesisSeparators;
|
|
382
|
+
parse(): Statement[];
|
|
383
|
+
parseExpressionOnly(): Expression;
|
|
384
|
+
private statement;
|
|
385
|
+
private importStatement;
|
|
386
|
+
private block;
|
|
387
|
+
private matchPattern;
|
|
388
|
+
private matchPatternAtom;
|
|
389
|
+
private matchExpression;
|
|
390
|
+
private parameters;
|
|
391
|
+
private genericParameters;
|
|
392
|
+
private type;
|
|
393
|
+
private typeAtom;
|
|
394
|
+
private expression;
|
|
395
|
+
private templateExpression;
|
|
396
|
+
private prefix;
|
|
397
|
+
private tryExpression;
|
|
398
|
+
}
|
|
399
|
+
export declare function parse(source: string, options?: {
|
|
400
|
+
validate?: boolean;
|
|
401
|
+
filePath?: string;
|
|
402
|
+
}): Statement[];
|
|
403
|
+
export {};
|