@magnusopera/fscript 0.75.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/README.md +5 -0
- package/dist/FScript.Language/Ast.js +234 -0
- package/dist/FScript.Language/BuiltinFunctions.js +2039 -0
- package/dist/FScript.Language/BuiltinSignatures.js +24 -0
- package/dist/FScript.Language/BuiltinTypes.js +13 -0
- package/dist/FScript.Language/Error.js +74 -0
- package/dist/FScript.Language/Eval.js +2404 -0
- package/dist/FScript.Language/IncludeResolver.js +806 -0
- package/dist/FScript.Language/Lexer.js +1067 -0
- package/dist/FScript.Language/Library.js +28 -0
- package/dist/FScript.Language/Parser.js +2368 -0
- package/dist/FScript.Language/Pretty.js +115 -0
- package/dist/FScript.Language/Span.js +33 -0
- package/dist/FScript.Language/Token.js +32 -0
- package/dist/FScript.Language/TypeInfer.js +2561 -0
- package/dist/FScript.Language/Types.js +205 -0
- package/dist/FScript.Language/Value.js +91 -0
- package/dist/Library.js +732 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Array.js +1347 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Async.js +134 -0
- package/dist/fable_modules/fable-library-js.5.2.0/AsyncBuilder.js +183 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BigInt.js +306 -0
- package/dist/fable_modules/fable-library-js.5.2.0/BitConverter.js +138 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Boolean.js +22 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CHANGELOG.md +234 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Char.js +202 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Choice.js +184 -0
- package/dist/fable_modules/fable-library-js.5.2.0/CollectionUtil.js +182 -0
- package/dist/fable_modules/fable-library-js.5.2.0/ConditionalWeakTable.js +21 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Date.js +841 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOffset.js +261 -0
- package/dist/fable_modules/fable-library-js.5.2.0/DateOnly.js +124 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Decimal.js +238 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Double.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Encoding.js +185 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Event.js +93 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Collections.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.CompilerServices.js +27 -0
- package/dist/fable_modules/fable-library-js.5.2.0/FSharp.Core.js +156 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Global.js +29 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Guid.js +161 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Int32.js +135 -0
- package/dist/fable_modules/fable-library-js.5.2.0/List.js +1323 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Long.js +47 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MailboxProcessor.js +94 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Map.js +1396 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MapUtil.js +130 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableMap.js +339 -0
- package/dist/fable_modules/fable-library-js.5.2.0/MutableSet.js +233 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Native.js +14 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Numeric.js +75 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Observable.js +113 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Option.js +104 -0
- package/dist/fable_modules/fable-library-js.5.2.0/README.md +3 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Random.js +172 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Range.js +45 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Reflection.js +479 -0
- package/dist/fable_modules/fable-library-js.5.2.0/RegExp.js +141 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Result.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq.js +1417 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Seq2.js +111 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Set.js +1816 -0
- package/dist/fable_modules/fable-library-js.5.2.0/String.js +674 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Collections.Generic.js +333 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.Text.js +200 -0
- package/dist/fable_modules/fable-library-js.5.2.0/System.js +283 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeOnly.js +122 -0
- package/dist/fable_modules/fable-library-js.5.2.0/TimeSpan.js +180 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Timer.js +67 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Types.js +198 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Unicode.13.0.0.js +4 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Uri.js +165 -0
- package/dist/fable_modules/fable-library-js.5.2.0/Util.js +795 -0
- package/dist/fable_modules/fable-library-js.5.2.0/big.d.ts +338 -0
- package/dist/fable_modules/fable-library-js.5.2.0/lib/big.js +825 -0
- package/dist/fable_modules/fable-library-js.5.2.0/package.json +24 -0
- package/dist/fable_modules/fable-library-js.5.2.0/quotation.js +618 -0
- package/dist/fable_modules/project_cracked.json +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,2368 @@
|
|
|
1
|
+
|
|
2
|
+
import { class_type } from "../fable_modules/fable-library-js.5.2.0/Reflection.js";
|
|
3
|
+
import { singleton, tail as tail_1, head as head_1, isEmpty, foldBack, empty, length, item } from "../fable_modules/fable-library-js.5.2.0/List.js";
|
|
4
|
+
import { equals } from "../fable_modules/fable-library-js.5.2.0/Util.js";
|
|
5
|
+
import { ParseException, ParseError } from "./Error.js";
|
|
6
|
+
import { TokenKind } from "./Token.js";
|
|
7
|
+
import { Span, SpanModule_merge } from "./Span.js";
|
|
8
|
+
import { isNullOrWhiteSpace, substring, concat, join, isNullOrEmpty } from "../fable_modules/fable-library-js.5.2.0/String.js";
|
|
9
|
+
import { isUpper } from "../fable_modules/fable-library-js.5.2.0/Char.js";
|
|
10
|
+
import { MapEntry, Ast_spanOfExpr, InterpolatedPart, Expr, Ast_spanOfPattern, Pattern, Stmt, TypeDef, Param, TypeRef, Literal } from "./Ast.js";
|
|
11
|
+
import { tokenizeWithSourceName } from "./Lexer.js";
|
|
12
|
+
import { addToSet } from "../fable_modules/fable-library-js.5.2.0/MapUtil.js";
|
|
13
|
+
import { foldBack as foldBack_1, toList } from "../fable_modules/fable-library-js.5.2.0/Seq.js";
|
|
14
|
+
import { StringBuilder__Append_244C7CD6, StringBuilder__Clear, StringBuilder__get_Length, StringBuilder_$ctor } from "../fable_modules/fable-library-js.5.2.0/System.Text.js";
|
|
15
|
+
import { toString } from "../fable_modules/fable-library-js.5.2.0/Types.js";
|
|
16
|
+
import { item as item_1 } from "../fable_modules/fable-library-js.5.2.0/Array.js";
|
|
17
|
+
|
|
18
|
+
class TokenStream {
|
|
19
|
+
constructor(tokens) {
|
|
20
|
+
this.tokens = tokens;
|
|
21
|
+
this.index = 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function TokenStream_$reflection() {
|
|
26
|
+
return class_type("FScript.Language.Parser.TokenStream", undefined, TokenStream);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function TokenStream_$ctor_Z3FD4619(tokens) {
|
|
30
|
+
return new TokenStream(tokens);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function TokenStream__Peek(_) {
|
|
34
|
+
return item(_.index, _.tokens);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function TokenStream__PeekAt_Z524259A4(_, offset) {
|
|
38
|
+
return item(_.index + offset, _.tokens);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function TokenStream__TokenAt_Z524259A4(_, i) {
|
|
42
|
+
return item(i, _.tokens);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function TokenStream__get_Index(_) {
|
|
46
|
+
return _.index | 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function TokenStream__Mark(_) {
|
|
50
|
+
return _.index | 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function TokenStream__Restore_Z524259A4(_, mark) {
|
|
54
|
+
_.index = (mark | 0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function TokenStream__Next(_) {
|
|
58
|
+
const t = item(_.index, _.tokens);
|
|
59
|
+
_.index = ((_.index + 1) | 0);
|
|
60
|
+
return t;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function TokenStream__Match_5CEB78CD(_, kind) {
|
|
64
|
+
if (equals(item(_.index, _.tokens).Kind, kind)) {
|
|
65
|
+
_.index = ((_.index + 1) | 0);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function TokenStream__Expect_77B9EE56(_, kind, message) {
|
|
74
|
+
const t = item(_.index, _.tokens);
|
|
75
|
+
if (equals(t.Kind, kind)) {
|
|
76
|
+
_.index = ((_.index + 1) | 0);
|
|
77
|
+
return t;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new ParseException(new ParseError(message, t.Span));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function TokenStream__ExpectIdent_Z721C83C5(_, message) {
|
|
85
|
+
const t = item(_.index, _.tokens);
|
|
86
|
+
if (t.Kind.tag === 4) {
|
|
87
|
+
_.index = ((_.index + 1) | 0);
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new ParseException(new ParseError(message, t.Span));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function TokenStream__get_AtEnd(_) {
|
|
96
|
+
return equals(item(_.index, _.tokens).Kind, new TokenKind(0, []));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function TokenStream__SkipNewlines(_) {
|
|
100
|
+
while (equals(item(_.index, _.tokens).Kind, new TokenKind(1, []))) {
|
|
101
|
+
_.index = ((_.index + 1) | 0);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function mkSpanFrom(a, b) {
|
|
106
|
+
return SpanModule_merge(a, b);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isStartAtom(k) {
|
|
110
|
+
switch (k.tag) {
|
|
111
|
+
case 4:
|
|
112
|
+
case 5:
|
|
113
|
+
case 6:
|
|
114
|
+
case 7:
|
|
115
|
+
case 8:
|
|
116
|
+
case 9:
|
|
117
|
+
case 27:
|
|
118
|
+
case 29:
|
|
119
|
+
case 43:
|
|
120
|
+
case 10:
|
|
121
|
+
case 13:
|
|
122
|
+
case 17:
|
|
123
|
+
case 21:
|
|
124
|
+
case 22:
|
|
125
|
+
case 14:
|
|
126
|
+
case 46:
|
|
127
|
+
case 47:
|
|
128
|
+
return true;
|
|
129
|
+
default:
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isUpperIdent(name) {
|
|
135
|
+
if (!isNullOrEmpty(name)) {
|
|
136
|
+
return isUpper(name[0]);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function isStartPatternAtom(k) {
|
|
144
|
+
switch (k.tag) {
|
|
145
|
+
case 4:
|
|
146
|
+
case 5:
|
|
147
|
+
case 6:
|
|
148
|
+
case 7:
|
|
149
|
+
case 9:
|
|
150
|
+
case 29:
|
|
151
|
+
case 27:
|
|
152
|
+
case 43:
|
|
153
|
+
return true;
|
|
154
|
+
default:
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseLiteral(t) {
|
|
160
|
+
const matchValue = t.Kind;
|
|
161
|
+
switch (matchValue.tag) {
|
|
162
|
+
case 5:
|
|
163
|
+
return new Literal(0, [matchValue.fields[0]]);
|
|
164
|
+
case 6:
|
|
165
|
+
return new Literal(1, [matchValue.fields[0]]);
|
|
166
|
+
case 7:
|
|
167
|
+
return new Literal(3, [matchValue.fields[0]]);
|
|
168
|
+
case 9:
|
|
169
|
+
return new Literal(2, [matchValue.fields[0]]);
|
|
170
|
+
default:
|
|
171
|
+
throw new ParseException(new ParseError("Expected literal", t.Span));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function parseProgramWithSourceName(sourceName, src) {
|
|
176
|
+
const tokens = tokenizeWithSourceName(sourceName, src);
|
|
177
|
+
const stream = TokenStream_$ctor_Z3FD4619(tokens);
|
|
178
|
+
const consumeLayoutSeparators = () => {
|
|
179
|
+
let consumed = false;
|
|
180
|
+
let progress = true;
|
|
181
|
+
while (progress) {
|
|
182
|
+
progress = false;
|
|
183
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
184
|
+
consumed = true;
|
|
185
|
+
progress = true;
|
|
186
|
+
}
|
|
187
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
188
|
+
consumed = true;
|
|
189
|
+
progress = true;
|
|
190
|
+
}
|
|
191
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
192
|
+
consumed = true;
|
|
193
|
+
progress = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return consumed;
|
|
197
|
+
};
|
|
198
|
+
const hasNonLayoutTokenBeforeOnSameLine = (tokenIndex, line) => {
|
|
199
|
+
let i_2 = tokenIndex - 1;
|
|
200
|
+
let keepSearching = true;
|
|
201
|
+
let foundSameLine = false;
|
|
202
|
+
while (keepSearching && (i_2 >= 0)) {
|
|
203
|
+
const tok = TokenStream__TokenAt_Z524259A4(stream, i_2);
|
|
204
|
+
const matchValue_1 = tok.Kind;
|
|
205
|
+
switch (matchValue_1.tag) {
|
|
206
|
+
case 1: {
|
|
207
|
+
keepSearching = false;
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case 2:
|
|
211
|
+
case 3: {
|
|
212
|
+
i_2 = ((i_2 - 1) | 0);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
default: {
|
|
216
|
+
foundSameLine = (tok.Span.Start.Line === line);
|
|
217
|
+
keepSearching = false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return foundSameLine;
|
|
222
|
+
};
|
|
223
|
+
const hasNonLayoutTokenAfterOnSameLine = (tokenIndex_1, line_1) => {
|
|
224
|
+
let i_3 = tokenIndex_1 + 1;
|
|
225
|
+
let keepSearching_1 = true;
|
|
226
|
+
let foundSameLine_1 = false;
|
|
227
|
+
while (keepSearching_1 && (i_3 < length(tokens))) {
|
|
228
|
+
const tok_1 = TokenStream__TokenAt_Z524259A4(stream, i_3);
|
|
229
|
+
const matchValue_2 = tok_1.Kind;
|
|
230
|
+
switch (matchValue_2.tag) {
|
|
231
|
+
case 1:
|
|
232
|
+
case 2:
|
|
233
|
+
case 3: {
|
|
234
|
+
i_3 = ((i_3 + 1) | 0);
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
default: {
|
|
238
|
+
foundSameLine_1 = (tok_1.Span.Start.Line === line_1);
|
|
239
|
+
keepSearching_1 = false;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return foundSameLine_1;
|
|
244
|
+
};
|
|
245
|
+
let allowIndentedApplication = true;
|
|
246
|
+
let allowBinaryNewlineSkipping = true;
|
|
247
|
+
const parseTypeRefAtom = () => {
|
|
248
|
+
let firstName, matchValue_3, parts_1, keepGoing;
|
|
249
|
+
TokenStream__SkipNewlines(stream);
|
|
250
|
+
const matchValue_5 = TokenStream__Peek(stream).Kind;
|
|
251
|
+
switch (matchValue_5.tag) {
|
|
252
|
+
case 4:
|
|
253
|
+
return new TypeRef(0, [(firstName = ((matchValue_3 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected type name").Kind, (matchValue_3.tag === 4) ? matchValue_3.fields[0] : "")), (parts_1 = [], (void (parts_1.push(firstName)), (keepGoing = true, ((() => {
|
|
254
|
+
while (keepGoing && TokenStream__Match_5CEB78CD(stream, new TokenKind(36, []))) {
|
|
255
|
+
const matchValue_4 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'.\' in qualified type name").Kind;
|
|
256
|
+
if (matchValue_4.tag === 4) {
|
|
257
|
+
void (parts_1.push(matchValue_4.fields[0]));
|
|
258
|
+
}
|
|
259
|
+
keepGoing = true;
|
|
260
|
+
}
|
|
261
|
+
})(), join(".", parts_1))))))]);
|
|
262
|
+
case 43: {
|
|
263
|
+
TokenStream__Next(stream);
|
|
264
|
+
const isStructural = TokenStream__Match_5CEB78CD(stream, new TokenKind(26, []));
|
|
265
|
+
const fields = [];
|
|
266
|
+
const seen = new Set([]);
|
|
267
|
+
const parseField = () => {
|
|
268
|
+
const nameTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in inline record type");
|
|
269
|
+
let fieldName;
|
|
270
|
+
const matchValue_6 = nameTok.Kind;
|
|
271
|
+
fieldName = ((matchValue_6.tag === 4) ? matchValue_6.fields[0] : "");
|
|
272
|
+
if (!addToSet(fieldName, seen)) {
|
|
273
|
+
throw new ParseException(new ParseError(concat("Duplicate field \'", fieldName, "\' in inline record type"), nameTok.Span));
|
|
274
|
+
}
|
|
275
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(35, []), "Expected \':\' after inline record type field name");
|
|
276
|
+
const fieldType = parseTypeRef();
|
|
277
|
+
void (fields.push([fieldName, fieldType]));
|
|
278
|
+
};
|
|
279
|
+
if ((isStructural && equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) ? true : (!isStructural && equals(TokenStream__Peek(stream).Kind, new TokenKind(44, [])))) {
|
|
280
|
+
throw new ParseException(new ParseError("Inline record type must define at least one field", TokenStream__Peek(stream).Span));
|
|
281
|
+
}
|
|
282
|
+
parseField();
|
|
283
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
284
|
+
if ((isStructural && !equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) ? true : (!isStructural && !equals(TokenStream__Peek(stream).Kind, new TokenKind(44, [])))) {
|
|
285
|
+
parseField();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (isStructural) {
|
|
289
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(26, []), "Expected \'|\' in structural record type");
|
|
290
|
+
}
|
|
291
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in inline record type");
|
|
292
|
+
if (isStructural) {
|
|
293
|
+
return new TypeRef(5, [toList(fields)]);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
return new TypeRef(4, [toList(fields)]);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
case 27: {
|
|
300
|
+
TokenStream__Next(stream);
|
|
301
|
+
const first_1 = parseTypeRef();
|
|
302
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(51, []))) {
|
|
303
|
+
const items = [];
|
|
304
|
+
void (items.push(first_1));
|
|
305
|
+
void (items.push(parseTypeRef()));
|
|
306
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(51, []))) {
|
|
307
|
+
void (items.push(parseTypeRef()));
|
|
308
|
+
}
|
|
309
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' in tuple type");
|
|
310
|
+
return new TypeRef(1, [toList(items)]);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' in type expression");
|
|
314
|
+
return first_1;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
default:
|
|
318
|
+
throw new ParseException(new ParseError("Expected type expression", TokenStream__Peek(stream).Span));
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
const parseTypeRefPostfix = () => {
|
|
322
|
+
let t = parseTypeRefAtom();
|
|
323
|
+
let loop = true;
|
|
324
|
+
while (loop) {
|
|
325
|
+
const matchValue_7 = TokenStream__Peek(stream).Kind;
|
|
326
|
+
let matchResult;
|
|
327
|
+
if (matchValue_7.tag === 4) {
|
|
328
|
+
switch (matchValue_7.fields[0]) {
|
|
329
|
+
case "list": {
|
|
330
|
+
matchResult = 0;
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
case "option": {
|
|
334
|
+
matchResult = 1;
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case "map": {
|
|
338
|
+
matchResult = 2;
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
case "task": {
|
|
342
|
+
matchResult = 3;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
default:
|
|
346
|
+
matchResult = 4;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
matchResult = 4;
|
|
351
|
+
}
|
|
352
|
+
switch (matchResult) {
|
|
353
|
+
case 0: {
|
|
354
|
+
TokenStream__Next(stream);
|
|
355
|
+
t = (new TypeRef(3, [t, "list"]));
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case 1: {
|
|
359
|
+
TokenStream__Next(stream);
|
|
360
|
+
t = (new TypeRef(3, [t, "option"]));
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
case 2: {
|
|
364
|
+
TokenStream__Next(stream);
|
|
365
|
+
t = (new TypeRef(3, [t, "map"]));
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
case 3: {
|
|
369
|
+
TokenStream__Next(stream);
|
|
370
|
+
t = (new TypeRef(3, [t, "task"]));
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
case 4: {
|
|
374
|
+
loop = false;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return t;
|
|
380
|
+
};
|
|
381
|
+
const parseTypeRef = () => {
|
|
382
|
+
const left = parseTypeRefPostfix();
|
|
383
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(24, []))) {
|
|
384
|
+
return new TypeRef(2, [left, parseTypeRef()]);
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
return left;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
const parseParam = () => {
|
|
391
|
+
TokenStream__SkipNewlines(stream);
|
|
392
|
+
const matchValue_8 = TokenStream__Peek(stream).Kind;
|
|
393
|
+
switch (matchValue_8.tag) {
|
|
394
|
+
case 4:
|
|
395
|
+
return new Param(matchValue_8.fields[0], undefined, TokenStream__Next(stream).Span);
|
|
396
|
+
case 27: {
|
|
397
|
+
const lp = TokenStream__Next(stream);
|
|
398
|
+
TokenStream__SkipNewlines(stream);
|
|
399
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(28, []))) {
|
|
400
|
+
return new Param("()", new TypeRef(0, ["unit"]), mkSpanFrom(lp.Span, TokenStream__TokenAt_Z524259A4(stream, TokenStream__get_Index(stream) - 1).Span));
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
let name;
|
|
404
|
+
const matchValue_9 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected parameter name in annotated parameter").Kind;
|
|
405
|
+
name = ((matchValue_9.tag === 4) ? matchValue_9.fields[0] : "");
|
|
406
|
+
TokenStream__SkipNewlines(stream);
|
|
407
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(35, []), "Expected \':\' in annotated parameter");
|
|
408
|
+
return new Param(name, parseTypeRef(), mkSpanFrom(lp.Span, TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' after annotated parameter").Span));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
default:
|
|
412
|
+
throw new ParseException(new ParseError("Expected parameter", TokenStream__Peek(stream).Span));
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const parseParamsAligned = () => {
|
|
416
|
+
const args = [];
|
|
417
|
+
let argsDone = false;
|
|
418
|
+
let firstParamColumn = undefined;
|
|
419
|
+
while (!argsDone) {
|
|
420
|
+
let sawNewline = false;
|
|
421
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
422
|
+
sawNewline = true;
|
|
423
|
+
}
|
|
424
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
425
|
+
}
|
|
426
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
427
|
+
}
|
|
428
|
+
const matchValue_10 = TokenStream__Peek(stream).Kind;
|
|
429
|
+
switch (matchValue_10.tag) {
|
|
430
|
+
case 4:
|
|
431
|
+
case 27: {
|
|
432
|
+
const param = parseParam();
|
|
433
|
+
if (firstParamColumn != null) {
|
|
434
|
+
const firstCol = firstParamColumn | 0;
|
|
435
|
+
if (sawNewline && (param.Span.Start.Column !== firstCol)) {
|
|
436
|
+
throw new ParseException(new ParseError("Multiline let parameter columns must align", param.Span));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
firstParamColumn = param.Span.Start.Column;
|
|
441
|
+
}
|
|
442
|
+
void (args.push(param));
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
default:
|
|
446
|
+
argsDone = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return args;
|
|
450
|
+
};
|
|
451
|
+
const parseTypeDecl = () => {
|
|
452
|
+
const typeTok = TokenStream__Expect_77B9EE56(stream, new TokenKind(45, []), "Expected \'type\'");
|
|
453
|
+
const isRec = TokenStream__Match_5CEB78CD(stream, new TokenKind(11, []));
|
|
454
|
+
let name_1;
|
|
455
|
+
const matchValue_11 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'type\'").Kind;
|
|
456
|
+
name_1 = ((matchValue_11.tag === 4) ? matchValue_11.fields[0] : "");
|
|
457
|
+
TokenStream__SkipNewlines(stream);
|
|
458
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in type declaration");
|
|
459
|
+
let hasOuterIndent = false;
|
|
460
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
461
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
462
|
+
}
|
|
463
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
464
|
+
hasOuterIndent = true;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
let patternInput_1;
|
|
468
|
+
const matchValue_15 = TokenStream__Peek(stream).Kind;
|
|
469
|
+
switch (matchValue_15.tag) {
|
|
470
|
+
case 43: {
|
|
471
|
+
const lbIndex = TokenStream__get_Index(stream) | 0;
|
|
472
|
+
const lb = TokenStream__Expect_77B9EE56(stream, new TokenKind(43, []), "Expected \'{\' in record type declaration");
|
|
473
|
+
if (!hasNonLayoutTokenAfterOnSameLine(lbIndex, lb.Span.Start.Line)) {
|
|
474
|
+
throw new ParseException(new ParseError("Opening \'{\' cannot be on its own line; keep it with the first field", lb.Span));
|
|
475
|
+
}
|
|
476
|
+
const fields_1 = [];
|
|
477
|
+
const parseField_1 = () => {
|
|
478
|
+
TokenStream__SkipNewlines(stream);
|
|
479
|
+
const fieldTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in type declaration");
|
|
480
|
+
let fieldName_1;
|
|
481
|
+
const matchValue_12 = fieldTok.Kind;
|
|
482
|
+
fieldName_1 = ((matchValue_12.tag === 4) ? matchValue_12.fields[0] : "");
|
|
483
|
+
TokenStream__SkipNewlines(stream);
|
|
484
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(35, []), "Expected \':\' after field name");
|
|
485
|
+
const fieldType_1 = parseTypeRef();
|
|
486
|
+
void (fields_1.push([fieldName_1, fieldType_1]));
|
|
487
|
+
return fieldTok.Span.Start.Column | 0;
|
|
488
|
+
};
|
|
489
|
+
const firstFieldColumn = parseField_1() | 0;
|
|
490
|
+
let doneFields = false;
|
|
491
|
+
while (!doneFields) {
|
|
492
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
493
|
+
if (!equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
494
|
+
parseField_1();
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
doneFields = true;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
let sawNewline_1 = false;
|
|
502
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
503
|
+
sawNewline_1 = true;
|
|
504
|
+
}
|
|
505
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
506
|
+
}
|
|
507
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
508
|
+
}
|
|
509
|
+
if (sawNewline_1) {
|
|
510
|
+
const matchValue_13 = TokenStream__Peek(stream).Kind;
|
|
511
|
+
switch (matchValue_13.tag) {
|
|
512
|
+
case 44: {
|
|
513
|
+
doneFields = true;
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
case 4: {
|
|
517
|
+
if (parseField_1() !== firstFieldColumn) {
|
|
518
|
+
throw new ParseException(new ParseError("Type declaration fields must align", TokenStream__Peek(stream).Span));
|
|
519
|
+
}
|
|
520
|
+
break;
|
|
521
|
+
}
|
|
522
|
+
default:
|
|
523
|
+
throw new ParseException(new ParseError("Expected field or \'}\' in record type declaration", TokenStream__Peek(stream).Span));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
doneFields = true;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
const rbIndex = TokenStream__get_Index(stream) | 0;
|
|
532
|
+
const rb = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in record type declaration");
|
|
533
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex, rb.Span.Start.Line)) {
|
|
534
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last field", rb.Span));
|
|
535
|
+
}
|
|
536
|
+
patternInput_1 = [toList(fields_1), empty(), rb.Span];
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
case 26:
|
|
540
|
+
case 4: {
|
|
541
|
+
const cases = [];
|
|
542
|
+
const parseCase = () => {
|
|
543
|
+
TokenStream__SkipNewlines(stream);
|
|
544
|
+
TokenStream__Match_5CEB78CD(stream, new TokenKind(26, []));
|
|
545
|
+
const caseTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected union case name");
|
|
546
|
+
let caseName;
|
|
547
|
+
const matchValue_14 = caseTok.Kind;
|
|
548
|
+
caseName = ((matchValue_14.tag === 4) ? matchValue_14.fields[0] : "");
|
|
549
|
+
if (!isUpperIdent(caseName)) {
|
|
550
|
+
throw new ParseException(new ParseError("Union case name must start with uppercase letter", caseTok.Span));
|
|
551
|
+
}
|
|
552
|
+
TokenStream__SkipNewlines(stream);
|
|
553
|
+
const payload = TokenStream__Match_5CEB78CD(stream, new TokenKind(48, [])) ? parseTypeRef() : undefined;
|
|
554
|
+
void (cases.push([caseName, payload]));
|
|
555
|
+
return caseTok.Span;
|
|
556
|
+
};
|
|
557
|
+
let lastSpan = parseCase().End;
|
|
558
|
+
let doneCases = false;
|
|
559
|
+
while (!doneCases) {
|
|
560
|
+
let sawNewline_2 = false;
|
|
561
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
562
|
+
sawNewline_2 = true;
|
|
563
|
+
}
|
|
564
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
565
|
+
}
|
|
566
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
567
|
+
const s_1 = parseCase();
|
|
568
|
+
lastSpan = s_1.End;
|
|
569
|
+
}
|
|
570
|
+
else if (sawNewline_2) {
|
|
571
|
+
doneCases = true;
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
doneCases = true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
patternInput_1 = [empty(), toList(cases), new Span(lastSpan, lastSpan)];
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
default:
|
|
581
|
+
throw new ParseException(new ParseError("Expected record or union type declaration body", TokenStream__Peek(stream).Span));
|
|
582
|
+
}
|
|
583
|
+
if (hasOuterIndent) {
|
|
584
|
+
TokenStream__SkipNewlines(stream);
|
|
585
|
+
if (!TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
586
|
+
throw new ParseException(new ParseError("Expected dedent after type declaration", TokenStream__Peek(stream).Span));
|
|
587
|
+
}
|
|
588
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return new Stmt(0, [new TypeDef(name_1, isRec, patternInput_1[0], patternInput_1[1], mkSpanFrom(typeTok.Span, patternInput_1[2]))]);
|
|
592
|
+
};
|
|
593
|
+
const parsePattern = () => {
|
|
594
|
+
TokenStream__SkipNewlines(stream);
|
|
595
|
+
const t_1 = TokenStream__Peek(stream);
|
|
596
|
+
const matchValue_16 = t_1.Kind;
|
|
597
|
+
let matchResult_1, name_3, name_4;
|
|
598
|
+
switch (matchValue_16.tag) {
|
|
599
|
+
case 5:
|
|
600
|
+
case 6:
|
|
601
|
+
case 7:
|
|
602
|
+
case 9: {
|
|
603
|
+
matchResult_1 = 2;
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
case 29: {
|
|
607
|
+
matchResult_1 = 3;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
case 27: {
|
|
611
|
+
matchResult_1 = 4;
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case 43: {
|
|
615
|
+
matchResult_1 = 5;
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case 4: {
|
|
619
|
+
if (matchValue_16.fields[0] === "_") {
|
|
620
|
+
matchResult_1 = 0;
|
|
621
|
+
name_3 = matchValue_16.fields[0];
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
matchResult_1 = 1;
|
|
625
|
+
name_4 = matchValue_16.fields[0];
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
default:
|
|
630
|
+
matchResult_1 = 6;
|
|
631
|
+
}
|
|
632
|
+
switch (matchResult_1) {
|
|
633
|
+
case 0:
|
|
634
|
+
return new Pattern(0, [TokenStream__Next(stream).Span]);
|
|
635
|
+
case 1: {
|
|
636
|
+
const t_3 = TokenStream__Next(stream);
|
|
637
|
+
if (isUpperIdent(name_4) && TokenStream__Match_5CEB78CD(stream, new TokenKind(36, []))) {
|
|
638
|
+
const caseTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected union case name after \'.\'");
|
|
639
|
+
let caseName_1;
|
|
640
|
+
const matchValue_17 = caseTok_1.Kind;
|
|
641
|
+
caseName_1 = ((matchValue_17.tag === 4) ? matchValue_17.fields[0] : "");
|
|
642
|
+
if (!isUpperIdent(caseName_1)) {
|
|
643
|
+
throw new ParseException(new ParseError("Union case name must start with uppercase letter", caseTok_1.Span));
|
|
644
|
+
}
|
|
645
|
+
if (isStartPatternAtom(TokenStream__Peek(stream).Kind)) {
|
|
646
|
+
const p = parsePattern();
|
|
647
|
+
return new Pattern(10, [name_4, caseName_1, p, mkSpanFrom(t_3.Span, Ast_spanOfPattern(p))]);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
return new Pattern(10, [name_4, caseName_1, undefined, mkSpanFrom(t_3.Span, caseTok_1.Span)]);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
switch (name_4) {
|
|
655
|
+
case "None":
|
|
656
|
+
return new Pattern(9, [t_3.Span]);
|
|
657
|
+
case "Some": {
|
|
658
|
+
const p_1 = parsePattern();
|
|
659
|
+
return new Pattern(8, [p_1, mkSpanFrom(t_3.Span, Ast_spanOfPattern(p_1))]);
|
|
660
|
+
}
|
|
661
|
+
default:
|
|
662
|
+
if (isUpperIdent(name_4)) {
|
|
663
|
+
if (isStartPatternAtom(TokenStream__Peek(stream).Kind)) {
|
|
664
|
+
const p_2 = parsePattern();
|
|
665
|
+
return new Pattern(10, [undefined, name_4, p_2, mkSpanFrom(t_3.Span, Ast_spanOfPattern(p_2))]);
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
return new Pattern(10, [undefined, name_4, undefined, t_3.Span]);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
return new Pattern(1, [name_4, t_3.Span]);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
case 2: {
|
|
678
|
+
const t_4 = TokenStream__Next(stream);
|
|
679
|
+
return new Pattern(2, [parseLiteral(t_4), t_4.Span]);
|
|
680
|
+
}
|
|
681
|
+
case 3: {
|
|
682
|
+
const lbIndex_1 = TokenStream__get_Index(stream) | 0;
|
|
683
|
+
const lb_1 = TokenStream__Next(stream);
|
|
684
|
+
if (!hasNonLayoutTokenAfterOnSameLine(lbIndex_1, lb_1.Span.Start.Line)) {
|
|
685
|
+
throw new ParseException(new ParseError("Opening \'[\' cannot be on its own line; keep it with the first element", lb_1.Span));
|
|
686
|
+
}
|
|
687
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(30, []))) {
|
|
688
|
+
return new Pattern(3, [mkSpanFrom(lb_1.Span, lb_1.Span)]);
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
const first_2 = parsePatternCons();
|
|
692
|
+
const elements = [];
|
|
693
|
+
void (elements.push(first_2));
|
|
694
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
695
|
+
if (!equals(TokenStream__Peek(stream).Kind, new TokenKind(30, []))) {
|
|
696
|
+
void (elements.push(parsePatternCons()));
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const rbIndex_1 = TokenStream__get_Index(stream) | 0;
|
|
700
|
+
const rb_1 = TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' in list pattern");
|
|
701
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_1, rb_1.Span.Start.Line)) {
|
|
702
|
+
throw new ParseException(new ParseError("Closing \']\' cannot be on its own line; keep it with the last element", rb_1.Span));
|
|
703
|
+
}
|
|
704
|
+
return foldBack((head, tail) => (new Pattern(4, [head, tail, mkSpanFrom(Ast_spanOfPattern(head), Ast_spanOfPattern(tail))])), toList(elements), new Pattern(3, [mkSpanFrom(rb_1.Span, rb_1.Span)]));
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
case 4: {
|
|
708
|
+
const lp_1 = TokenStream__Next(stream);
|
|
709
|
+
const first_3 = parsePatternCons();
|
|
710
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(34, []))) {
|
|
711
|
+
const elements_1 = [];
|
|
712
|
+
void (elements_1.push(first_3));
|
|
713
|
+
void (elements_1.push(parsePatternCons()));
|
|
714
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(34, []))) {
|
|
715
|
+
void (elements_1.push(parsePatternCons()));
|
|
716
|
+
}
|
|
717
|
+
const rp_2 = TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' after tuple pattern");
|
|
718
|
+
return new Pattern(5, [toList(elements_1), mkSpanFrom(lp_1.Span, rp_2.Span)]);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' after parenthesized pattern");
|
|
722
|
+
return first_3;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
case 5: {
|
|
726
|
+
const lbIndex_2 = TokenStream__get_Index(stream) | 0;
|
|
727
|
+
const lb_2 = TokenStream__Next(stream);
|
|
728
|
+
if (!hasNonLayoutTokenAfterOnSameLine(lbIndex_2, lb_2.Span.Start.Line)) {
|
|
729
|
+
throw new ParseException(new ParseError("Opening \'{\' cannot be on its own line; keep it with the first entry", lb_2.Span));
|
|
730
|
+
}
|
|
731
|
+
TokenStream__SkipNewlines(stream);
|
|
732
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(44, []))) {
|
|
733
|
+
return new Pattern(7, [empty(), undefined, mkSpanFrom(lb_2.Span, lb_2.Span)]);
|
|
734
|
+
}
|
|
735
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
736
|
+
TokenStream__Next(stream);
|
|
737
|
+
const fields_3 = [];
|
|
738
|
+
const seen_1 = new Set([]);
|
|
739
|
+
const parseTypeField = () => {
|
|
740
|
+
const nameTok_3 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record type pattern");
|
|
741
|
+
let fieldName_2;
|
|
742
|
+
const matchValue_18 = nameTok_3.Kind;
|
|
743
|
+
fieldName_2 = ((matchValue_18.tag === 4) ? matchValue_18.fields[0] : "");
|
|
744
|
+
if (!addToSet(fieldName_2, seen_1)) {
|
|
745
|
+
throw new ParseException(new ParseError(concat("Duplicate field \'", fieldName_2, "\' in structural record type pattern"), nameTok_3.Span));
|
|
746
|
+
}
|
|
747
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(35, []), "Expected \':\' in structural record type pattern");
|
|
748
|
+
const fieldType_2 = parseTypeRef();
|
|
749
|
+
void (fields_3.push([fieldName_2, fieldType_2]));
|
|
750
|
+
};
|
|
751
|
+
parseTypeField();
|
|
752
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
753
|
+
if (!equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
754
|
+
parseTypeField();
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(26, []), "Expected \'|\' in structural record type pattern");
|
|
758
|
+
const rbIndex_2 = TokenStream__get_Index(stream) | 0;
|
|
759
|
+
const rb_2 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in structural record type pattern");
|
|
760
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_2, rb_2.Span.Start.Line)) {
|
|
761
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_2.Span));
|
|
762
|
+
}
|
|
763
|
+
return new Pattern(11, [new TypeRef(5, [toList(fields_3)]), mkSpanFrom(lb_2.Span, rb_2.Span)]);
|
|
764
|
+
}
|
|
765
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, []))) {
|
|
766
|
+
const clauses = [];
|
|
767
|
+
const parseClause = () => {
|
|
768
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(29, []), "Expected \'[\' in map pattern key");
|
|
769
|
+
const keyPattern = parsePatternCons();
|
|
770
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' in map pattern key");
|
|
771
|
+
TokenStream__SkipNewlines(stream);
|
|
772
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' after map key pattern");
|
|
773
|
+
const valuePattern = parsePatternCons();
|
|
774
|
+
void (clauses.push([keyPattern, valuePattern]));
|
|
775
|
+
};
|
|
776
|
+
parseClause();
|
|
777
|
+
TokenStream__SkipNewlines(stream);
|
|
778
|
+
let tailPattern = undefined;
|
|
779
|
+
let donePattern = false;
|
|
780
|
+
while (!donePattern) {
|
|
781
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
782
|
+
TokenStream__SkipNewlines(stream);
|
|
783
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(37, []))) {
|
|
784
|
+
TokenStream__Next(stream);
|
|
785
|
+
tailPattern = parsePatternCons();
|
|
786
|
+
TokenStream__SkipNewlines(stream);
|
|
787
|
+
donePattern = true;
|
|
788
|
+
}
|
|
789
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, []))) {
|
|
790
|
+
parseClause();
|
|
791
|
+
TokenStream__SkipNewlines(stream);
|
|
792
|
+
}
|
|
793
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
794
|
+
donePattern = true;
|
|
795
|
+
}
|
|
796
|
+
else {
|
|
797
|
+
throw new ParseException(new ParseError("Expected map pattern clause or \'..tail\'", TokenStream__Peek(stream).Span));
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(37, []))) {
|
|
801
|
+
TokenStream__Next(stream);
|
|
802
|
+
tailPattern = parsePatternCons();
|
|
803
|
+
TokenStream__SkipNewlines(stream);
|
|
804
|
+
donePattern = true;
|
|
805
|
+
}
|
|
806
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, []))) {
|
|
807
|
+
parseClause();
|
|
808
|
+
TokenStream__SkipNewlines(stream);
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
donePattern = true;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
const rbIndex_3 = TokenStream__get_Index(stream) | 0;
|
|
815
|
+
const rb_3 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in map pattern");
|
|
816
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_3, rb_3.Span.Start.Line)) {
|
|
817
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_3.Span));
|
|
818
|
+
}
|
|
819
|
+
return new Pattern(7, [toList(clauses), tailPattern, mkSpanFrom(lb_2.Span, rb_3.Span)]);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
const mark = TokenStream__Mark(stream) | 0;
|
|
823
|
+
let isTypeRefPattern;
|
|
824
|
+
try {
|
|
825
|
+
TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record type pattern");
|
|
826
|
+
TokenStream__SkipNewlines(stream);
|
|
827
|
+
isTypeRefPattern = TokenStream__Match_5CEB78CD(stream, new TokenKind(35, []));
|
|
828
|
+
}
|
|
829
|
+
catch (matchValue_19) {
|
|
830
|
+
isTypeRefPattern = false;
|
|
831
|
+
}
|
|
832
|
+
TokenStream__Restore_Z524259A4(stream, mark);
|
|
833
|
+
if (isTypeRefPattern) {
|
|
834
|
+
const fields_4 = [];
|
|
835
|
+
const seen_2 = new Set([]);
|
|
836
|
+
const parseTypeField_1 = () => {
|
|
837
|
+
TokenStream__SkipNewlines(stream);
|
|
838
|
+
const nameTok_4 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record type pattern");
|
|
839
|
+
let name_5;
|
|
840
|
+
const matchValue_20 = nameTok_4.Kind;
|
|
841
|
+
name_5 = ((matchValue_20.tag === 4) ? matchValue_20.fields[0] : "");
|
|
842
|
+
if (!addToSet(name_5, seen_2)) {
|
|
843
|
+
throw new ParseException(new ParseError(concat("Duplicate field \'", name_5, "\' in record type pattern"), nameTok_4.Span));
|
|
844
|
+
}
|
|
845
|
+
TokenStream__SkipNewlines(stream);
|
|
846
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(35, []), "Expected \':\' in record type pattern field");
|
|
847
|
+
const t_5 = parseTypeRef();
|
|
848
|
+
void (fields_4.push([name_5, t_5]));
|
|
849
|
+
};
|
|
850
|
+
parseTypeField_1();
|
|
851
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
852
|
+
if (!equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
853
|
+
parseTypeField_1();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const rbIndex_4 = TokenStream__get_Index(stream) | 0;
|
|
857
|
+
const rb_4 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in record type pattern");
|
|
858
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_4, rb_4.Span.Start.Line)) {
|
|
859
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last field", rb_4.Span));
|
|
860
|
+
}
|
|
861
|
+
return new Pattern(11, [new TypeRef(4, [toList(fields_4)]), mkSpanFrom(lb_2.Span, rb_4.Span)]);
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
const fields_5 = [];
|
|
865
|
+
const seen_3 = new Set([]);
|
|
866
|
+
const parseField_2 = () => {
|
|
867
|
+
TokenStream__SkipNewlines(stream);
|
|
868
|
+
const nameTok_5 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record pattern");
|
|
869
|
+
let name_6;
|
|
870
|
+
const matchValue_21 = nameTok_5.Kind;
|
|
871
|
+
name_6 = ((matchValue_21.tag === 4) ? matchValue_21.fields[0] : "");
|
|
872
|
+
if (!addToSet(name_6, seen_3)) {
|
|
873
|
+
throw new ParseException(new ParseError(concat("Duplicate field \'", name_6, "\' in record pattern"), nameTok_5.Span));
|
|
874
|
+
}
|
|
875
|
+
TokenStream__SkipNewlines(stream);
|
|
876
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in record pattern field");
|
|
877
|
+
const p_3 = parsePatternCons();
|
|
878
|
+
void (fields_5.push([name_6, p_3]));
|
|
879
|
+
};
|
|
880
|
+
parseField_2();
|
|
881
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, []))) {
|
|
882
|
+
if (!equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
883
|
+
parseField_2();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
const rbIndex_5 = TokenStream__get_Index(stream) | 0;
|
|
887
|
+
const rb_5 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in record pattern");
|
|
888
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_5, rb_5.Span.Start.Line)) {
|
|
889
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last field", rb_5.Span));
|
|
890
|
+
}
|
|
891
|
+
return new Pattern(6, [toList(fields_5), mkSpanFrom(lb_2.Span, rb_5.Span)]);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
default:
|
|
896
|
+
throw new ParseException(new ParseError("Unexpected token in pattern", t_1.Span));
|
|
897
|
+
}
|
|
898
|
+
};
|
|
899
|
+
const parsePatternCons = () => {
|
|
900
|
+
const left_1 = parsePattern();
|
|
901
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(61, []))) {
|
|
902
|
+
const right_1 = parsePatternCons();
|
|
903
|
+
return new Pattern(4, [left_1, right_1, mkSpanFrom(Ast_spanOfPattern(left_1), Ast_spanOfPattern(right_1))]);
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
return left_1;
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
const parseEntryExpr = () => {
|
|
910
|
+
const previousIndentedApplication = allowIndentedApplication;
|
|
911
|
+
const previousBinaryNewlineSkipping = allowBinaryNewlineSkipping;
|
|
912
|
+
allowIndentedApplication = false;
|
|
913
|
+
allowBinaryNewlineSkipping = false;
|
|
914
|
+
try {
|
|
915
|
+
let progress_1 = true;
|
|
916
|
+
while (progress_1) {
|
|
917
|
+
progress_1 = false;
|
|
918
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
919
|
+
progress_1 = true;
|
|
920
|
+
}
|
|
921
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
922
|
+
progress_1 = true;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return parseExpr();
|
|
926
|
+
}
|
|
927
|
+
finally {
|
|
928
|
+
allowIndentedApplication = previousIndentedApplication;
|
|
929
|
+
allowBinaryNewlineSkipping = previousBinaryNewlineSkipping;
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
const parsePrimary = () => {
|
|
933
|
+
let matchValue_29, matchValue_30;
|
|
934
|
+
TokenStream__SkipNewlines(stream);
|
|
935
|
+
const t_6 = TokenStream__Peek(stream);
|
|
936
|
+
const matchValue_22 = t_6.Kind;
|
|
937
|
+
switch (matchValue_22.tag) {
|
|
938
|
+
case 5:
|
|
939
|
+
case 6:
|
|
940
|
+
case 7:
|
|
941
|
+
case 9: {
|
|
942
|
+
const t_7 = TokenStream__Next(stream);
|
|
943
|
+
return new Expr(1, [parseLiteral(t_7), t_7.Span]);
|
|
944
|
+
}
|
|
945
|
+
case 8: {
|
|
946
|
+
const raw = matchValue_22.fields[0];
|
|
947
|
+
const span = TokenStream__Next(stream).Span;
|
|
948
|
+
const parts = [];
|
|
949
|
+
const text = StringBuilder_$ctor();
|
|
950
|
+
const flushText = () => {
|
|
951
|
+
if (StringBuilder__get_Length(text) > 0) {
|
|
952
|
+
void (parts.push(new InterpolatedPart(0, [toString(text)])));
|
|
953
|
+
StringBuilder__Clear(text);
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
let i_1 = 0;
|
|
957
|
+
while (i_1 < raw.length) {
|
|
958
|
+
let parsed;
|
|
959
|
+
const matchValue = raw[i_1];
|
|
960
|
+
let matchResult_2, ch_1;
|
|
961
|
+
switch (matchValue) {
|
|
962
|
+
case "\\": {
|
|
963
|
+
if ((i_1 + 1) < raw.length) {
|
|
964
|
+
matchResult_2 = 4;
|
|
965
|
+
}
|
|
966
|
+
else {
|
|
967
|
+
matchResult_2 = 5;
|
|
968
|
+
ch_1 = matchValue;
|
|
969
|
+
}
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
case "{": {
|
|
973
|
+
if (((i_1 + 1) < raw.length) && (raw[i_1 + 1] === "{")) {
|
|
974
|
+
matchResult_2 = 0;
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
matchResult_2 = 2;
|
|
978
|
+
}
|
|
979
|
+
break;
|
|
980
|
+
}
|
|
981
|
+
case "}": {
|
|
982
|
+
if (((i_1 + 1) < raw.length) && (raw[i_1 + 1] === "}")) {
|
|
983
|
+
matchResult_2 = 1;
|
|
984
|
+
}
|
|
985
|
+
else {
|
|
986
|
+
matchResult_2 = 3;
|
|
987
|
+
}
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
default: {
|
|
991
|
+
matchResult_2 = 5;
|
|
992
|
+
ch_1 = matchValue;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
switch (matchResult_2) {
|
|
996
|
+
case 0: {
|
|
997
|
+
StringBuilder__Append_244C7CD6(text, "{");
|
|
998
|
+
i_1 = ((i_1 + 2) | 0);
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
case 1: {
|
|
1002
|
+
StringBuilder__Append_244C7CD6(text, "}");
|
|
1003
|
+
i_1 = ((i_1 + 2) | 0);
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
case 2: {
|
|
1007
|
+
flushText();
|
|
1008
|
+
let patternInput;
|
|
1009
|
+
const s = raw;
|
|
1010
|
+
const start = (i_1 + 1) | 0;
|
|
1011
|
+
let i = start;
|
|
1012
|
+
let depth = 1;
|
|
1013
|
+
let inString = false;
|
|
1014
|
+
let escaped = false;
|
|
1015
|
+
while ((i < s.length) && (depth > 0)) {
|
|
1016
|
+
const ch = s[i];
|
|
1017
|
+
if (inString) {
|
|
1018
|
+
if (escaped) {
|
|
1019
|
+
escaped = false;
|
|
1020
|
+
i = ((i + 1) | 0);
|
|
1021
|
+
}
|
|
1022
|
+
else {
|
|
1023
|
+
switch (ch) {
|
|
1024
|
+
case "\"": {
|
|
1025
|
+
inString = false;
|
|
1026
|
+
i = ((i + 1) | 0);
|
|
1027
|
+
break;
|
|
1028
|
+
}
|
|
1029
|
+
case "\\": {
|
|
1030
|
+
escaped = true;
|
|
1031
|
+
i = ((i + 1) | 0);
|
|
1032
|
+
break;
|
|
1033
|
+
}
|
|
1034
|
+
default:
|
|
1035
|
+
i = ((i + 1) | 0);
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
switch (ch) {
|
|
1041
|
+
case "\"": {
|
|
1042
|
+
inString = true;
|
|
1043
|
+
i = ((i + 1) | 0);
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
case "{": {
|
|
1047
|
+
depth = ((depth + 1) | 0);
|
|
1048
|
+
i = ((i + 1) | 0);
|
|
1049
|
+
break;
|
|
1050
|
+
}
|
|
1051
|
+
case "}": {
|
|
1052
|
+
depth = ((depth - 1) | 0);
|
|
1053
|
+
i = ((i + 1) | 0);
|
|
1054
|
+
break;
|
|
1055
|
+
}
|
|
1056
|
+
default:
|
|
1057
|
+
i = ((i + 1) | 0);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
if (depth !== 0) {
|
|
1062
|
+
throw new ParseException(new ParseError("Unterminated interpolation placeholder", span));
|
|
1063
|
+
}
|
|
1064
|
+
const exprText_1 = substring(s, start, (i - start) - 1);
|
|
1065
|
+
if (isNullOrWhiteSpace(exprText_1)) {
|
|
1066
|
+
throw new ParseException(new ParseError("Interpolation placeholder cannot be empty", span));
|
|
1067
|
+
}
|
|
1068
|
+
patternInput = [(parsed = parseProgramWithSourceName(undefined, exprText_1), !isEmpty(parsed) ? ((head_1(parsed).tag === 5) ? (isEmpty(tail_1(parsed)) ? head_1(parsed).fields[0] : (() => {
|
|
1069
|
+
throw new ParseException(new ParseError("Interpolation placeholders must contain a single expression", TokenStream__Peek(stream).Span));
|
|
1070
|
+
})()) : (() => {
|
|
1071
|
+
throw new ParseException(new ParseError("Interpolation placeholders must contain a single expression", TokenStream__Peek(stream).Span));
|
|
1072
|
+
})()) : (() => {
|
|
1073
|
+
throw new ParseException(new ParseError("Interpolation placeholders must contain a single expression", TokenStream__Peek(stream).Span));
|
|
1074
|
+
})()), i];
|
|
1075
|
+
void (parts.push(new InterpolatedPart(1, [patternInput[0]])));
|
|
1076
|
+
i_1 = (patternInput[1] | 0);
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
case 3: {
|
|
1080
|
+
throw new ParseException(new ParseError("Unescaped \'}\' in interpolated string", span));
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
case 4: {
|
|
1084
|
+
const next = raw[i_1 + 1];
|
|
1085
|
+
switch (next) {
|
|
1086
|
+
case "\"": {
|
|
1087
|
+
StringBuilder__Append_244C7CD6(text, "\"");
|
|
1088
|
+
break;
|
|
1089
|
+
}
|
|
1090
|
+
case "\\": {
|
|
1091
|
+
StringBuilder__Append_244C7CD6(text, "\\");
|
|
1092
|
+
break;
|
|
1093
|
+
}
|
|
1094
|
+
case "n": {
|
|
1095
|
+
StringBuilder__Append_244C7CD6(text, "\n");
|
|
1096
|
+
break;
|
|
1097
|
+
}
|
|
1098
|
+
case "t": {
|
|
1099
|
+
StringBuilder__Append_244C7CD6(text, "\t");
|
|
1100
|
+
break;
|
|
1101
|
+
}
|
|
1102
|
+
default:
|
|
1103
|
+
StringBuilder__Append_244C7CD6(text, next);
|
|
1104
|
+
}
|
|
1105
|
+
i_1 = ((i_1 + 2) | 0);
|
|
1106
|
+
break;
|
|
1107
|
+
}
|
|
1108
|
+
case 5: {
|
|
1109
|
+
StringBuilder__Append_244C7CD6(text, ch_1);
|
|
1110
|
+
i_1 = ((i_1 + 1) | 0);
|
|
1111
|
+
break;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
flushText();
|
|
1116
|
+
return new Expr(30, [(parts.length === 0) ? singleton(new InterpolatedPart(0, [""])) : toList(parts), span]);
|
|
1117
|
+
}
|
|
1118
|
+
case 4: {
|
|
1119
|
+
const name_7 = matchValue_22.fields[0];
|
|
1120
|
+
const t_9 = TokenStream__Next(stream);
|
|
1121
|
+
switch (name_7) {
|
|
1122
|
+
case "None":
|
|
1123
|
+
return new Expr(27, [t_9.Span]);
|
|
1124
|
+
case "Some": {
|
|
1125
|
+
const arg = parsePrimary();
|
|
1126
|
+
return new Expr(26, [arg, mkSpanFrom(t_9.Span, Ast_spanOfExpr(arg))]);
|
|
1127
|
+
}
|
|
1128
|
+
default:
|
|
1129
|
+
return new Expr(2, [name_7, t_9.Span]);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
case 27: {
|
|
1133
|
+
const lp_2 = TokenStream__Next(stream);
|
|
1134
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(28, []))) {
|
|
1135
|
+
return new Expr(0, [mkSpanFrom(lp_2.Span, TokenStream__Next(stream).Span)]);
|
|
1136
|
+
}
|
|
1137
|
+
else {
|
|
1138
|
+
const first_4 = parseExpr();
|
|
1139
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(34, []))) {
|
|
1140
|
+
const elements_2 = [];
|
|
1141
|
+
void (elements_2.push(first_4));
|
|
1142
|
+
void (elements_2.push(parseExpr()));
|
|
1143
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(34, []))) {
|
|
1144
|
+
void (elements_2.push(parseExpr()));
|
|
1145
|
+
}
|
|
1146
|
+
const rp_4 = TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' after tuple expression");
|
|
1147
|
+
return new Expr(15, [toList(elements_2), mkSpanFrom(lp_2.Span, rp_4.Span)]);
|
|
1148
|
+
}
|
|
1149
|
+
else {
|
|
1150
|
+
return new Expr(3, [first_4, mkSpanFrom(lp_2.Span, TokenStream__Expect_77B9EE56(stream, new TokenKind(28, []), "Expected \')\' after expression").Span)]);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
case 29: {
|
|
1155
|
+
const lbIndex_3 = TokenStream__get_Index(stream) | 0;
|
|
1156
|
+
const lb_3 = TokenStream__Next(stream);
|
|
1157
|
+
if (!hasNonLayoutTokenAfterOnSameLine(lbIndex_3, lb_3.Span.Start.Line)) {
|
|
1158
|
+
throw new ParseException(new ParseError("Opening \'[\' cannot be on its own line; keep it with the first element", lb_3.Span));
|
|
1159
|
+
}
|
|
1160
|
+
consumeLayoutSeparators();
|
|
1161
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(30, []))) {
|
|
1162
|
+
return new Expr(13, [empty(), mkSpanFrom(lb_3.Span, lb_3.Span)]);
|
|
1163
|
+
}
|
|
1164
|
+
else {
|
|
1165
|
+
const first_5 = parseEntryExpr();
|
|
1166
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(37, []))) {
|
|
1167
|
+
const second = parseEntryExpr();
|
|
1168
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? true : TokenStream__Match_5CEB78CD(stream, new TokenKind(37, []))) {
|
|
1169
|
+
throw new ParseException(new ParseError("Invalid range syntax", TokenStream__Peek(stream).Span));
|
|
1170
|
+
}
|
|
1171
|
+
return new Expr(14, [first_5, second, mkSpanFrom(lb_3.Span, TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' in range expression").Span)]);
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
const elements_3 = [];
|
|
1175
|
+
void (elements_3.push(first_5));
|
|
1176
|
+
let keepParsing = true;
|
|
1177
|
+
while (keepParsing) {
|
|
1178
|
+
if ((TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) && !equals(TokenStream__Peek(stream).Kind, new TokenKind(30, []))) {
|
|
1179
|
+
void (elements_3.push(parseEntryExpr()));
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
keepParsing = false;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
const rbIndex_6 = TokenStream__get_Index(stream) | 0;
|
|
1186
|
+
const rb_7 = TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' in list literal");
|
|
1187
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_6, rb_7.Span.Start.Line)) {
|
|
1188
|
+
throw new ParseException(new ParseError("Closing \']\' cannot be on its own line; keep it with the last element", rb_7.Span));
|
|
1189
|
+
}
|
|
1190
|
+
return new Expr(13, [toList(elements_3), mkSpanFrom(lb_3.Span, rb_7.Span)]);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
case 43: {
|
|
1195
|
+
const lbIndex_4 = TokenStream__get_Index(stream) | 0;
|
|
1196
|
+
const lb_4 = TokenStream__Next(stream);
|
|
1197
|
+
if (!hasNonLayoutTokenAfterOnSameLine(lbIndex_4, lb_4.Span.Start.Line)) {
|
|
1198
|
+
throw new ParseException(new ParseError("Opening \'{\' cannot be on its own line; keep it with the first entry", lb_4.Span));
|
|
1199
|
+
}
|
|
1200
|
+
consumeLayoutSeparators();
|
|
1201
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(44, []))) {
|
|
1202
|
+
return new Expr(18, [empty(), mkSpanFrom(lb_4.Span, lb_4.Span)]);
|
|
1203
|
+
}
|
|
1204
|
+
else if (TokenStream__Match_5CEB78CD(stream, new TokenKind(26, []))) {
|
|
1205
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
1206
|
+
throw new ParseException(new ParseError("Structural record literal must define at least one field", TokenStream__Peek(stream).Span));
|
|
1207
|
+
}
|
|
1208
|
+
const mark_1 = TokenStream__Mark(stream) | 0;
|
|
1209
|
+
let matchValue_24;
|
|
1210
|
+
const baseExpr = parseExpr();
|
|
1211
|
+
TokenStream__SkipNewlines(stream);
|
|
1212
|
+
if (!TokenStream__Match_5CEB78CD(stream, new TokenKind(15, []))) {
|
|
1213
|
+
TokenStream__Restore_Z524259A4(stream, mark_1);
|
|
1214
|
+
matchValue_24 = undefined;
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
const updates = [];
|
|
1218
|
+
const parseUpdateField = () => {
|
|
1219
|
+
let name_8;
|
|
1220
|
+
const matchValue_23 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record update").Kind;
|
|
1221
|
+
name_8 = ((matchValue_23.tag === 4) ? matchValue_23.fields[0] : "");
|
|
1222
|
+
TokenStream__SkipNewlines(stream);
|
|
1223
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in structural record update field");
|
|
1224
|
+
const value_40 = parseEntryExpr();
|
|
1225
|
+
void (updates.push([name_8, value_40]));
|
|
1226
|
+
};
|
|
1227
|
+
parseUpdateField();
|
|
1228
|
+
let keepParsing_1 = true;
|
|
1229
|
+
while (keepParsing_1) {
|
|
1230
|
+
if ((TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) && !equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
1231
|
+
parseUpdateField();
|
|
1232
|
+
}
|
|
1233
|
+
else {
|
|
1234
|
+
keepParsing_1 = false;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(26, []), "Expected \'|\' in structural record update");
|
|
1238
|
+
const rbIndex_7 = TokenStream__get_Index(stream) | 0;
|
|
1239
|
+
const rb_8 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in structural record update");
|
|
1240
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_7, rb_8.Span.Start.Line)) {
|
|
1241
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_8.Span));
|
|
1242
|
+
}
|
|
1243
|
+
matchValue_24 = (new Expr(20, [baseExpr, toList(updates), mkSpanFrom(lb_4.Span, rb_8.Span)]));
|
|
1244
|
+
}
|
|
1245
|
+
if (matchValue_24 == null) {
|
|
1246
|
+
const fields_6 = [];
|
|
1247
|
+
const parseField_3 = () => {
|
|
1248
|
+
let name_9;
|
|
1249
|
+
const matchValue_25 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record literal").Kind;
|
|
1250
|
+
name_9 = ((matchValue_25.tag === 4) ? matchValue_25.fields[0] : "");
|
|
1251
|
+
TokenStream__SkipNewlines(stream);
|
|
1252
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in structural record field");
|
|
1253
|
+
const value_44 = parseEntryExpr();
|
|
1254
|
+
void (fields_6.push([name_9, value_44]));
|
|
1255
|
+
};
|
|
1256
|
+
parseField_3();
|
|
1257
|
+
let keepParsing_2 = true;
|
|
1258
|
+
while (keepParsing_2) {
|
|
1259
|
+
if ((TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) && !equals(TokenStream__Peek(stream).Kind, new TokenKind(26, []))) {
|
|
1260
|
+
parseField_3();
|
|
1261
|
+
}
|
|
1262
|
+
else {
|
|
1263
|
+
keepParsing_2 = false;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(26, []), "Expected \'|\' in structural record literal");
|
|
1267
|
+
const rbIndex_8 = TokenStream__get_Index(stream) | 0;
|
|
1268
|
+
const rb_9 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in structural record literal");
|
|
1269
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_8, rb_9.Span.Start.Line)) {
|
|
1270
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_9.Span));
|
|
1271
|
+
}
|
|
1272
|
+
return new Expr(17, [toList(fields_6), mkSpanFrom(lb_4.Span, rb_9.Span)]);
|
|
1273
|
+
}
|
|
1274
|
+
else {
|
|
1275
|
+
return matchValue_24;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, [])) ? true : equals(TokenStream__Peek(stream).Kind, new TokenKind(37, []))) {
|
|
1279
|
+
const parseMapEntry = () => {
|
|
1280
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(37, []))) {
|
|
1281
|
+
return new MapEntry(1, [parseEntryExpr()]);
|
|
1282
|
+
}
|
|
1283
|
+
else {
|
|
1284
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(29, []), "Expected \'[\' in map entry key");
|
|
1285
|
+
const keyExpr = parseExpr();
|
|
1286
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' after map entry key");
|
|
1287
|
+
TokenStream__SkipNewlines(stream);
|
|
1288
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in map entry");
|
|
1289
|
+
return new MapEntry(0, [keyExpr, parseEntryExpr()]);
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
const entries = [];
|
|
1293
|
+
void (entries.push(parseMapEntry()));
|
|
1294
|
+
let keepParsing_3 = true;
|
|
1295
|
+
while (keepParsing_3) {
|
|
1296
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) {
|
|
1297
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
1298
|
+
keepParsing_3 = false;
|
|
1299
|
+
}
|
|
1300
|
+
else {
|
|
1301
|
+
void (entries.push(parseMapEntry()));
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
1305
|
+
keepParsing_3 = false;
|
|
1306
|
+
}
|
|
1307
|
+
else {
|
|
1308
|
+
throw new ParseException(new ParseError("Expected \';\', newline, or \'}\' in map literal", TokenStream__Peek(stream).Span));
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
const rbIndex_9 = TokenStream__get_Index(stream) | 0;
|
|
1312
|
+
const rb_10 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in map literal");
|
|
1313
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_9, rb_10.Span.Start.Line)) {
|
|
1314
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_10.Span));
|
|
1315
|
+
}
|
|
1316
|
+
return new Expr(18, [toList(entries), mkSpanFrom(lb_4.Span, rb_10.Span)]);
|
|
1317
|
+
}
|
|
1318
|
+
else {
|
|
1319
|
+
const mark_2 = TokenStream__Mark(stream) | 0;
|
|
1320
|
+
let matchValue_27;
|
|
1321
|
+
const baseExpr_1 = parseExpr();
|
|
1322
|
+
TokenStream__SkipNewlines(stream);
|
|
1323
|
+
if (!TokenStream__Match_5CEB78CD(stream, new TokenKind(15, []))) {
|
|
1324
|
+
TokenStream__Restore_Z524259A4(stream, mark_2);
|
|
1325
|
+
matchValue_27 = undefined;
|
|
1326
|
+
}
|
|
1327
|
+
else {
|
|
1328
|
+
const updates_1 = [];
|
|
1329
|
+
const parseUpdateField_1 = () => {
|
|
1330
|
+
let name_10;
|
|
1331
|
+
const matchValue_26 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record update").Kind;
|
|
1332
|
+
name_10 = ((matchValue_26.tag === 4) ? matchValue_26.fields[0] : "");
|
|
1333
|
+
TokenStream__SkipNewlines(stream);
|
|
1334
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in record update field");
|
|
1335
|
+
const value_53 = parseEntryExpr();
|
|
1336
|
+
void (updates_1.push([name_10, value_53]));
|
|
1337
|
+
};
|
|
1338
|
+
parseUpdateField_1();
|
|
1339
|
+
let keepParsing_4 = true;
|
|
1340
|
+
while (keepParsing_4) {
|
|
1341
|
+
if ((TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) && !equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
1342
|
+
parseUpdateField_1();
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
keepParsing_4 = false;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
const rbIndex_10 = TokenStream__get_Index(stream) | 0;
|
|
1349
|
+
const rb_11 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in record update");
|
|
1350
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_10, rb_11.Span.Start.Line)) {
|
|
1351
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_11.Span));
|
|
1352
|
+
}
|
|
1353
|
+
matchValue_27 = (new Expr(19, [baseExpr_1, toList(updates_1), mkSpanFrom(lb_4.Span, rb_11.Span)]));
|
|
1354
|
+
}
|
|
1355
|
+
if (matchValue_27 == null) {
|
|
1356
|
+
const fields_7 = [];
|
|
1357
|
+
const parseField_4 = () => {
|
|
1358
|
+
let name_11;
|
|
1359
|
+
const matchValue_28 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record literal").Kind;
|
|
1360
|
+
name_11 = ((matchValue_28.tag === 4) ? matchValue_28.fields[0] : "");
|
|
1361
|
+
TokenStream__SkipNewlines(stream);
|
|
1362
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in record field");
|
|
1363
|
+
const value_56 = parseEntryExpr();
|
|
1364
|
+
void (fields_7.push([name_11, value_56]));
|
|
1365
|
+
};
|
|
1366
|
+
parseField_4();
|
|
1367
|
+
let keepParsing_5 = true;
|
|
1368
|
+
while (keepParsing_5) {
|
|
1369
|
+
if ((TokenStream__Match_5CEB78CD(stream, new TokenKind(33, [])) ? ((void consumeLayoutSeparators(), true)) : consumeLayoutSeparators()) && !equals(TokenStream__Peek(stream).Kind, new TokenKind(44, []))) {
|
|
1370
|
+
parseField_4();
|
|
1371
|
+
}
|
|
1372
|
+
else {
|
|
1373
|
+
keepParsing_5 = false;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
const rbIndex_11 = TokenStream__get_Index(stream) | 0;
|
|
1377
|
+
const rb_12 = TokenStream__Expect_77B9EE56(stream, new TokenKind(44, []), "Expected \'}\' in record literal");
|
|
1378
|
+
if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_11, rb_12.Span.Start.Line)) {
|
|
1379
|
+
throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_12.Span));
|
|
1380
|
+
}
|
|
1381
|
+
return new Expr(16, [toList(fields_7), mkSpanFrom(lb_4.Span, rb_12.Span)]);
|
|
1382
|
+
}
|
|
1383
|
+
else {
|
|
1384
|
+
return matchValue_27;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
case 10:
|
|
1389
|
+
return parseLetExpr();
|
|
1390
|
+
case 13:
|
|
1391
|
+
return parseLambda();
|
|
1392
|
+
case 17:
|
|
1393
|
+
return parseIf();
|
|
1394
|
+
case 21: {
|
|
1395
|
+
const raiseTok = TokenStream__Next(stream);
|
|
1396
|
+
const value_58 = parsePrimary();
|
|
1397
|
+
return new Expr(7, [value_58, mkSpanFrom(raiseTok.Span, Ast_spanOfExpr(value_58))]);
|
|
1398
|
+
}
|
|
1399
|
+
case 22:
|
|
1400
|
+
return parseFor();
|
|
1401
|
+
case 14:
|
|
1402
|
+
return parseMatch();
|
|
1403
|
+
case 46: {
|
|
1404
|
+
const t_10 = TokenStream__Next(stream);
|
|
1405
|
+
const nameTok_10 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected type name after \'typeof\'");
|
|
1406
|
+
return new Expr(28, [(matchValue_29 = nameTok_10.Kind, (matchValue_29.tag === 4) ? matchValue_29.fields[0] : ""), mkSpanFrom(t_10.Span, nameTok_10.Span)]);
|
|
1407
|
+
}
|
|
1408
|
+
case 47: {
|
|
1409
|
+
const t_11 = TokenStream__Next(stream);
|
|
1410
|
+
const nameTok_11 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'nameof\'");
|
|
1411
|
+
return new Expr(29, [(matchValue_30 = nameTok_11.Kind, (matchValue_30.tag === 4) ? matchValue_30.fields[0] : ""), mkSpanFrom(t_11.Span, nameTok_11.Span)]);
|
|
1412
|
+
}
|
|
1413
|
+
case 2:
|
|
1414
|
+
throw new ParseException(new ParseError("Indentation error: unexpected indent in expression", t_6.Span));
|
|
1415
|
+
case 3:
|
|
1416
|
+
throw new ParseException(new ParseError("Indentation error: unexpected dedent in expression", t_6.Span));
|
|
1417
|
+
default:
|
|
1418
|
+
throw new ParseException(new ParseError("Unexpected token in expression", t_6.Span));
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
const parsePostfix = () => {
|
|
1422
|
+
let expr_3 = parsePrimary();
|
|
1423
|
+
let keepGoing_1 = true;
|
|
1424
|
+
while (keepGoing_1) {
|
|
1425
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(36, []))) {
|
|
1426
|
+
const fieldTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name after \'.\'");
|
|
1427
|
+
let fieldName_3;
|
|
1428
|
+
const matchValue_31 = fieldTok_1.Kind;
|
|
1429
|
+
fieldName_3 = ((matchValue_31.tag === 4) ? matchValue_31.fields[0] : "");
|
|
1430
|
+
expr_3 = (new Expr(21, [expr_3, fieldName_3, mkSpanFrom(Ast_spanOfExpr(expr_3), fieldTok_1.Span)]));
|
|
1431
|
+
}
|
|
1432
|
+
else if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, []))) {
|
|
1433
|
+
const lb_5 = TokenStream__Peek(stream);
|
|
1434
|
+
const targetSpan = Ast_spanOfExpr(expr_3);
|
|
1435
|
+
if (((lb_5.Span.Start.Line === targetSpan.End.Line) && (lb_5.Span.Start.Column === targetSpan.End.Column)) && !equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(30, []))) {
|
|
1436
|
+
TokenStream__Next(stream);
|
|
1437
|
+
const keyExpr_1 = parseExpr();
|
|
1438
|
+
const rb_13 = TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' after index expression");
|
|
1439
|
+
expr_3 = (new Expr(22, [expr_3, keyExpr_1, mkSpanFrom(targetSpan, rb_13.Span)]));
|
|
1440
|
+
}
|
|
1441
|
+
else {
|
|
1442
|
+
keepGoing_1 = false;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
else {
|
|
1446
|
+
keepGoing_1 = false;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
return expr_3;
|
|
1450
|
+
};
|
|
1451
|
+
const parseApplication = () => {
|
|
1452
|
+
let expr_4 = parsePostfix();
|
|
1453
|
+
let keepGoing_2 = true;
|
|
1454
|
+
let hasMultilineArgBlock = false;
|
|
1455
|
+
while (keepGoing_2) {
|
|
1456
|
+
const next_2 = TokenStream__Peek(stream);
|
|
1457
|
+
if ((next_2.Span.Start.Line === Ast_spanOfExpr(expr_4).End.Line) && isStartAtom(next_2.Kind)) {
|
|
1458
|
+
const arg_1 = parsePostfix();
|
|
1459
|
+
expr_4 = (new Expr(5, [expr_4, arg_1, mkSpanFrom(Ast_spanOfExpr(expr_4), Ast_spanOfExpr(arg_1))]));
|
|
1460
|
+
}
|
|
1461
|
+
else {
|
|
1462
|
+
const mark_3 = TokenStream__Mark(stream) | 0;
|
|
1463
|
+
let sawNewline_3 = false;
|
|
1464
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
1465
|
+
sawNewline_3 = true;
|
|
1466
|
+
}
|
|
1467
|
+
if (sawNewline_3 && allowIndentedApplication) {
|
|
1468
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
1469
|
+
hasMultilineArgBlock = true;
|
|
1470
|
+
}
|
|
1471
|
+
const candidate = TokenStream__Peek(stream);
|
|
1472
|
+
if ((candidate.Span.Start.Column > Ast_spanOfExpr(expr_4).Start.Column) && isStartAtom(candidate.Kind)) {
|
|
1473
|
+
const arg_2 = parsePostfix();
|
|
1474
|
+
expr_4 = (new Expr(5, [expr_4, arg_2, mkSpanFrom(Ast_spanOfExpr(expr_4), Ast_spanOfExpr(arg_2))]));
|
|
1475
|
+
}
|
|
1476
|
+
else if (hasMultilineArgBlock && equals(candidate.Kind, new TokenKind(3, []))) {
|
|
1477
|
+
TokenStream__Next(stream);
|
|
1478
|
+
hasMultilineArgBlock = false;
|
|
1479
|
+
keepGoing_2 = false;
|
|
1480
|
+
}
|
|
1481
|
+
else {
|
|
1482
|
+
TokenStream__Restore_Z524259A4(stream, mark_3);
|
|
1483
|
+
keepGoing_2 = false;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
else {
|
|
1487
|
+
TokenStream__Restore_Z524259A4(stream, mark_3);
|
|
1488
|
+
keepGoing_2 = false;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
return expr_4;
|
|
1493
|
+
};
|
|
1494
|
+
const parseBinary = (minPrec) => {
|
|
1495
|
+
let left_2 = parseApplication();
|
|
1496
|
+
const precedence = (op) => {
|
|
1497
|
+
switch (op.tag) {
|
|
1498
|
+
case 51:
|
|
1499
|
+
case 52:
|
|
1500
|
+
case 53:
|
|
1501
|
+
return 7;
|
|
1502
|
+
case 49:
|
|
1503
|
+
case 50:
|
|
1504
|
+
return 6;
|
|
1505
|
+
case 62:
|
|
1506
|
+
return 5;
|
|
1507
|
+
case 61:
|
|
1508
|
+
return 4;
|
|
1509
|
+
case 25:
|
|
1510
|
+
case 54:
|
|
1511
|
+
case 55:
|
|
1512
|
+
case 56:
|
|
1513
|
+
case 57:
|
|
1514
|
+
return 3;
|
|
1515
|
+
case 58:
|
|
1516
|
+
return 2;
|
|
1517
|
+
case 59:
|
|
1518
|
+
return 1;
|
|
1519
|
+
case 60:
|
|
1520
|
+
return 0;
|
|
1521
|
+
default:
|
|
1522
|
+
return -1;
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
let looping = true;
|
|
1526
|
+
while (looping) {
|
|
1527
|
+
let op_1;
|
|
1528
|
+
if (allowBinaryNewlineSkipping) {
|
|
1529
|
+
let continueLoop = true;
|
|
1530
|
+
while (continueLoop) {
|
|
1531
|
+
TokenStream__SkipNewlines(stream);
|
|
1532
|
+
const mark_4 = TokenStream__Mark(stream) | 0;
|
|
1533
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
1534
|
+
if (precedence(TokenStream__Peek(stream).Kind) >= minPrec) {
|
|
1535
|
+
}
|
|
1536
|
+
else {
|
|
1537
|
+
TokenStream__Restore_Z524259A4(stream, mark_4);
|
|
1538
|
+
continueLoop = false;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
TokenStream__Restore_Z524259A4(stream, mark_4);
|
|
1543
|
+
continueLoop = false;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
const prec = precedence(TokenStream__Peek(stream).Kind) | 0;
|
|
1548
|
+
if (prec >= minPrec) {
|
|
1549
|
+
const opTok = TokenStream__Next(stream);
|
|
1550
|
+
const right_2 = parseBinary(prec + 1);
|
|
1551
|
+
left_2 = (new Expr(25, [(op_1 = opTok.Kind, (op_1.tag === 49) ? "+" : ((op_1.tag === 50) ? "-" : ((op_1.tag === 51) ? "*" : ((op_1.tag === 52) ? "/" : ((op_1.tag === 53) ? "%" : ((op_1.tag === 25) ? "=" : ((op_1.tag === 54) ? "<" : ((op_1.tag === 55) ? ">" : ((op_1.tag === 56) ? "<=" : ((op_1.tag === 57) ? ">=" : ((op_1.tag === 58) ? "&&" : ((op_1.tag === 59) ? "||" : ((op_1.tag === 60) ? "|>" : ((op_1.tag === 61) ? "::" : ((op_1.tag === 62) ? "@" : "?"))))))))))))))), left_2, right_2, mkSpanFrom(Ast_spanOfExpr(left_2), Ast_spanOfExpr(right_2))]));
|
|
1552
|
+
}
|
|
1553
|
+
else {
|
|
1554
|
+
looping = false;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
return left_2;
|
|
1558
|
+
};
|
|
1559
|
+
const parseIf = () => parseIfAfterKeyword(TokenStream__Expect_77B9EE56(stream, new TokenKind(17, []), "Expected \'if\'").Span);
|
|
1560
|
+
const parseIfAfterKeyword = (startSpan) => {
|
|
1561
|
+
const cond = parseExpr();
|
|
1562
|
+
TokenStream__SkipNewlines(stream);
|
|
1563
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(18, []), "Expected \'then\'");
|
|
1564
|
+
const thenExpr = parseExprOrBlock();
|
|
1565
|
+
TokenStream__SkipNewlines(stream);
|
|
1566
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(3, []))) {
|
|
1567
|
+
TokenStream__SkipNewlines(stream);
|
|
1568
|
+
}
|
|
1569
|
+
let elseExpr;
|
|
1570
|
+
const matchValue_32 = TokenStream__Peek(stream).Kind;
|
|
1571
|
+
switch (matchValue_32.tag) {
|
|
1572
|
+
case 19: {
|
|
1573
|
+
TokenStream__Next(stream);
|
|
1574
|
+
elseExpr = parseExprOrBlock();
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
case 20: {
|
|
1578
|
+
elseExpr = parseIfAfterKeyword(TokenStream__Next(stream).Span);
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
default:
|
|
1582
|
+
throw new ParseException(new ParseError("Expected \'else\' or \'elif\'", TokenStream__Peek(stream).Span));
|
|
1583
|
+
}
|
|
1584
|
+
return new Expr(6, [cond, thenExpr, elseExpr, mkSpanFrom(startSpan, Ast_spanOfExpr(elseExpr))]);
|
|
1585
|
+
};
|
|
1586
|
+
const parseFor = () => {
|
|
1587
|
+
const forTok = TokenStream__Expect_77B9EE56(stream, new TokenKind(22, []), "Expected \'for\'");
|
|
1588
|
+
let name_14;
|
|
1589
|
+
const matchValue_33 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'for\'").Kind;
|
|
1590
|
+
name_14 = ((matchValue_33.tag === 4) ? matchValue_33.fields[0] : "");
|
|
1591
|
+
TokenStream__SkipNewlines(stream);
|
|
1592
|
+
const matchValue_34 = TokenStream__Peek(stream).Kind;
|
|
1593
|
+
let matchResult_3;
|
|
1594
|
+
if (matchValue_34.tag === 4) {
|
|
1595
|
+
if (matchValue_34.fields[0] === "in") {
|
|
1596
|
+
matchResult_3 = 0;
|
|
1597
|
+
}
|
|
1598
|
+
else {
|
|
1599
|
+
matchResult_3 = 1;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
else {
|
|
1603
|
+
matchResult_3 = 1;
|
|
1604
|
+
}
|
|
1605
|
+
switch (matchResult_3) {
|
|
1606
|
+
case 0: {
|
|
1607
|
+
TokenStream__Next(stream);
|
|
1608
|
+
break;
|
|
1609
|
+
}
|
|
1610
|
+
case 1: {
|
|
1611
|
+
throw new ParseException(new ParseError("Expected \'in\' after for loop variable", TokenStream__Peek(stream).Span));
|
|
1612
|
+
break;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
const source_19 = parsePostfix();
|
|
1616
|
+
TokenStream__SkipNewlines(stream);
|
|
1617
|
+
const matchValue_35 = TokenStream__Peek(stream).Kind;
|
|
1618
|
+
let matchResult_4;
|
|
1619
|
+
if (matchValue_35.tag === 4) {
|
|
1620
|
+
if (matchValue_35.fields[0] === "do") {
|
|
1621
|
+
matchResult_4 = 0;
|
|
1622
|
+
}
|
|
1623
|
+
else {
|
|
1624
|
+
matchResult_4 = 1;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
else {
|
|
1628
|
+
matchResult_4 = 1;
|
|
1629
|
+
}
|
|
1630
|
+
switch (matchResult_4) {
|
|
1631
|
+
case 0: {
|
|
1632
|
+
TokenStream__Next(stream);
|
|
1633
|
+
break;
|
|
1634
|
+
}
|
|
1635
|
+
case 1: {
|
|
1636
|
+
throw new ParseException(new ParseError("Expected \'do\' in for loop", TokenStream__Peek(stream).Span));
|
|
1637
|
+
break;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
const body = parseExprOrBlock();
|
|
1641
|
+
return new Expr(8, [name_14, source_19, body, mkSpanFrom(forTok.Span, Ast_spanOfExpr(body))]);
|
|
1642
|
+
};
|
|
1643
|
+
const parseLambda = () => {
|
|
1644
|
+
const funTok = TokenStream__Expect_77B9EE56(stream, new TokenKind(13, []), "Expected \'fun\'");
|
|
1645
|
+
const parameters = [];
|
|
1646
|
+
let doneParams = false;
|
|
1647
|
+
while (!doneParams) {
|
|
1648
|
+
TokenStream__SkipNewlines(stream);
|
|
1649
|
+
const matchValue_36 = TokenStream__Peek(stream).Kind;
|
|
1650
|
+
switch (matchValue_36.tag) {
|
|
1651
|
+
case 4:
|
|
1652
|
+
case 27: {
|
|
1653
|
+
void (parameters.push(parseParam()));
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
default:
|
|
1657
|
+
doneParams = true;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
if (parameters.length === 0) {
|
|
1661
|
+
throw new ParseException(new ParseError("Expected at least one lambda parameter", TokenStream__Peek(stream).Span));
|
|
1662
|
+
}
|
|
1663
|
+
TokenStream__SkipNewlines(stream);
|
|
1664
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(24, []), "Expected \'->\' in lambda");
|
|
1665
|
+
return foldBack_1((param_1, acc) => (new Expr(4, [param_1, acc, mkSpanFrom(funTok.Span, Ast_spanOfExpr(acc))])), parameters, parseExprOrBlock());
|
|
1666
|
+
};
|
|
1667
|
+
const parseMatch = () => {
|
|
1668
|
+
const matchTok = TokenStream__Expect_77B9EE56(stream, new TokenKind(14, []), "Expected \'match\'");
|
|
1669
|
+
const expr_5 = parseExpr();
|
|
1670
|
+
TokenStream__SkipNewlines(stream);
|
|
1671
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(15, []), "Expected \'with\' in match");
|
|
1672
|
+
const cases_2 = [];
|
|
1673
|
+
const parseCase_1 = () => {
|
|
1674
|
+
TokenStream__SkipNewlines(stream);
|
|
1675
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(26, []))) {
|
|
1676
|
+
}
|
|
1677
|
+
const pat = parsePatternCons();
|
|
1678
|
+
TokenStream__SkipNewlines(stream);
|
|
1679
|
+
let guard;
|
|
1680
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(16, []))) {
|
|
1681
|
+
const g = parseExpr();
|
|
1682
|
+
TokenStream__SkipNewlines(stream);
|
|
1683
|
+
guard = g;
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
guard = undefined;
|
|
1687
|
+
}
|
|
1688
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(24, []), "Expected \'->\' in match case");
|
|
1689
|
+
const body_2 = parseExprOrBlock();
|
|
1690
|
+
const span_1 = mkSpanFrom(Ast_spanOfPattern(pat), Ast_spanOfExpr(body_2));
|
|
1691
|
+
void (cases_2.push([pat, guard, body_2, span_1]));
|
|
1692
|
+
};
|
|
1693
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
1694
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
1695
|
+
}
|
|
1696
|
+
const hasIndentedCaseBlock = TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []));
|
|
1697
|
+
const firstCaseToken = TokenStream__Peek(stream);
|
|
1698
|
+
if (equals(firstCaseToken.Kind, new TokenKind(0, [])) ? true : equals(firstCaseToken.Kind, new TokenKind(3, []))) {
|
|
1699
|
+
throw new ParseException(new ParseError("Expected match case", firstCaseToken.Span));
|
|
1700
|
+
}
|
|
1701
|
+
const caseColumn = firstCaseToken.Span.Start.Column | 0;
|
|
1702
|
+
if (caseColumn < matchTok.Span.Start.Column) {
|
|
1703
|
+
throw new ParseException(new ParseError("Match cases must start at match column or deeper", firstCaseToken.Span));
|
|
1704
|
+
}
|
|
1705
|
+
const ensureAlignedCaseStart = () => {
|
|
1706
|
+
const t_12 = TokenStream__Peek(stream);
|
|
1707
|
+
if (t_12.Span.Start.Column !== caseColumn) {
|
|
1708
|
+
throw new ParseException(new ParseError("Match case columns must align", t_12.Span));
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
ensureAlignedCaseStart();
|
|
1712
|
+
parseCase_1();
|
|
1713
|
+
let doneCases_1 = false;
|
|
1714
|
+
while (!doneCases_1) {
|
|
1715
|
+
TokenStream__SkipNewlines(stream);
|
|
1716
|
+
const matchValue_37 = TokenStream__Peek(stream).Kind;
|
|
1717
|
+
let matchResult_5;
|
|
1718
|
+
switch (matchValue_37.tag) {
|
|
1719
|
+
case 26: {
|
|
1720
|
+
matchResult_5 = 0;
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
case 3: {
|
|
1724
|
+
if (hasIndentedCaseBlock) {
|
|
1725
|
+
matchResult_5 = 1;
|
|
1726
|
+
}
|
|
1727
|
+
else {
|
|
1728
|
+
matchResult_5 = 3;
|
|
1729
|
+
}
|
|
1730
|
+
break;
|
|
1731
|
+
}
|
|
1732
|
+
case 2: {
|
|
1733
|
+
matchResult_5 = 2;
|
|
1734
|
+
break;
|
|
1735
|
+
}
|
|
1736
|
+
default:
|
|
1737
|
+
matchResult_5 = 3;
|
|
1738
|
+
}
|
|
1739
|
+
switch (matchResult_5) {
|
|
1740
|
+
case 0: {
|
|
1741
|
+
ensureAlignedCaseStart();
|
|
1742
|
+
parseCase_1();
|
|
1743
|
+
break;
|
|
1744
|
+
}
|
|
1745
|
+
case 1: {
|
|
1746
|
+
TokenStream__Next(stream);
|
|
1747
|
+
doneCases_1 = true;
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
case 2: {
|
|
1751
|
+
throw new ParseException(new ParseError("Match case columns must align", TokenStream__Peek(stream).Span));
|
|
1752
|
+
break;
|
|
1753
|
+
}
|
|
1754
|
+
case 3: {
|
|
1755
|
+
if (hasIndentedCaseBlock) {
|
|
1756
|
+
throw new ParseException(new ParseError("Expected match case or dedent", TokenStream__Peek(stream).Span));
|
|
1757
|
+
}
|
|
1758
|
+
else {
|
|
1759
|
+
doneCases_1 = true;
|
|
1760
|
+
}
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
else {
|
|
1767
|
+
parseCase_1();
|
|
1768
|
+
let doneCases_2 = false;
|
|
1769
|
+
while (!doneCases_2) {
|
|
1770
|
+
TokenStream__SkipNewlines(stream);
|
|
1771
|
+
const matchValue_38 = TokenStream__Peek(stream).Kind;
|
|
1772
|
+
switch (matchValue_38.tag) {
|
|
1773
|
+
case 26: {
|
|
1774
|
+
parseCase_1();
|
|
1775
|
+
break;
|
|
1776
|
+
}
|
|
1777
|
+
case 3:
|
|
1778
|
+
case 0: {
|
|
1779
|
+
doneCases_2 = true;
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
default:
|
|
1783
|
+
doneCases_2 = true;
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
return new Expr(9, [expr_5, toList(cases_2), mkSpanFrom(matchTok.Span, Ast_spanOfExpr(expr_5))]);
|
|
1788
|
+
};
|
|
1789
|
+
const parseLetExpr = () => {
|
|
1790
|
+
let matchValue_41, pattern_2;
|
|
1791
|
+
const letTok = TokenStream__Expect_77B9EE56(stream, new TokenKind(10, []), "Expected \'let\'");
|
|
1792
|
+
const isRec_1 = TokenStream__Match_5CEB78CD(stream, new TokenKind(11, []));
|
|
1793
|
+
let patternInput_2;
|
|
1794
|
+
if (isRec_1) {
|
|
1795
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(27, []))) {
|
|
1796
|
+
throw new ParseException(new ParseError("\'let rec\' does not support pattern bindings", TokenStream__Peek(stream).Span));
|
|
1797
|
+
}
|
|
1798
|
+
const nameTok_13 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
|
|
1799
|
+
let name_15;
|
|
1800
|
+
const matchValue_39 = nameTok_13.Kind;
|
|
1801
|
+
name_15 = ((matchValue_39.tag === 4) ? matchValue_39.fields[0] : "");
|
|
1802
|
+
const args_1 = parseParamsAligned();
|
|
1803
|
+
if (args_1.length === 0) {
|
|
1804
|
+
throw new ParseException(new ParseError("\'let rec\' requires at least one function argument", nameTok_13.Span));
|
|
1805
|
+
}
|
|
1806
|
+
patternInput_2 = [name_15, args_1, undefined, nameTok_13.Span];
|
|
1807
|
+
}
|
|
1808
|
+
else if (TokenStream__Peek(stream).Kind.tag === 27) {
|
|
1809
|
+
let pattern_1;
|
|
1810
|
+
const pattern = parsePatternCons();
|
|
1811
|
+
if (pattern.tag === 5) {
|
|
1812
|
+
pattern_1 = pattern;
|
|
1813
|
+
}
|
|
1814
|
+
else {
|
|
1815
|
+
throw new ParseException(new ParseError("Only tuple patterns are supported in let bindings", Ast_spanOfPattern(pattern)));
|
|
1816
|
+
}
|
|
1817
|
+
patternInput_2 = ["", [], pattern_1, Ast_spanOfPattern(pattern_1)];
|
|
1818
|
+
}
|
|
1819
|
+
else {
|
|
1820
|
+
const nameTok_14 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
|
|
1821
|
+
patternInput_2 = [(matchValue_41 = nameTok_14.Kind, (matchValue_41.tag === 4) ? matchValue_41.fields[0] : ""), parseParamsAligned(), undefined, nameTok_14.Span];
|
|
1822
|
+
}
|
|
1823
|
+
const tuplePatternOpt = patternInput_2[2];
|
|
1824
|
+
const bindingName = patternInput_2[0];
|
|
1825
|
+
const args_2 = patternInput_2[1];
|
|
1826
|
+
TokenStream__SkipNewlines(stream);
|
|
1827
|
+
let returnAnnotation;
|
|
1828
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(35, []))) {
|
|
1829
|
+
if (args_2.length === 0) {
|
|
1830
|
+
throw new ParseException(new ParseError("Return type annotations are only supported on function let bindings", TokenStream__Peek(stream).Span));
|
|
1831
|
+
}
|
|
1832
|
+
returnAnnotation = parseTypeRef();
|
|
1833
|
+
}
|
|
1834
|
+
else {
|
|
1835
|
+
returnAnnotation = undefined;
|
|
1836
|
+
}
|
|
1837
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(35, []))) {
|
|
1838
|
+
throw new ParseException(new ParseError("Annotated parameters must be parenthesized as (x: T)", TokenStream__Peek(stream).Span));
|
|
1839
|
+
}
|
|
1840
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in let binding");
|
|
1841
|
+
const value_70 = parseExprOrBlock();
|
|
1842
|
+
if (isRec_1) {
|
|
1843
|
+
const bindings = [];
|
|
1844
|
+
const firstSpan = mkSpanFrom(patternInput_2[3], Ast_spanOfExpr(value_70));
|
|
1845
|
+
void (bindings.push([bindingName, toList(args_2), returnAnnotation, value_70, firstSpan]));
|
|
1846
|
+
let doneBindings = false;
|
|
1847
|
+
while (!doneBindings) {
|
|
1848
|
+
TokenStream__SkipNewlines(stream);
|
|
1849
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(12, []))) {
|
|
1850
|
+
const nextNameTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'and\'");
|
|
1851
|
+
let nextName;
|
|
1852
|
+
const matchValue_42 = nextNameTok.Kind;
|
|
1853
|
+
nextName = ((matchValue_42.tag === 4) ? matchValue_42.fields[0] : "");
|
|
1854
|
+
const nextArgs = parseParamsAligned();
|
|
1855
|
+
if (nextArgs.length === 0) {
|
|
1856
|
+
throw new ParseException(new ParseError("\'let rec ... and ...\' requires function arguments for each binding", nextNameTok.Span));
|
|
1857
|
+
}
|
|
1858
|
+
TokenStream__SkipNewlines(stream);
|
|
1859
|
+
const nextReturnAnnotation = TokenStream__Match_5CEB78CD(stream, new TokenKind(35, [])) ? parseTypeRef() : undefined;
|
|
1860
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(35, []))) {
|
|
1861
|
+
throw new ParseException(new ParseError("Annotated parameters must be parenthesized as (x: T)", TokenStream__Peek(stream).Span));
|
|
1862
|
+
}
|
|
1863
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in let binding");
|
|
1864
|
+
const nextValue = parseExprOrBlock();
|
|
1865
|
+
const nextSpan = mkSpanFrom(nextNameTok.Span, Ast_spanOfExpr(nextValue));
|
|
1866
|
+
void (bindings.push([nextName, toList(nextArgs), nextReturnAnnotation, nextValue, nextSpan]));
|
|
1867
|
+
}
|
|
1868
|
+
else {
|
|
1869
|
+
doneBindings = true;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
const matchValue_43 = TokenStream__Peek(stream).Kind;
|
|
1873
|
+
let matchResult_6;
|
|
1874
|
+
if (matchValue_43.tag === 4) {
|
|
1875
|
+
if (matchValue_43.fields[0] === "in") {
|
|
1876
|
+
matchResult_6 = 0;
|
|
1877
|
+
}
|
|
1878
|
+
else {
|
|
1879
|
+
matchResult_6 = 1;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
else {
|
|
1883
|
+
matchResult_6 = 1;
|
|
1884
|
+
}
|
|
1885
|
+
switch (matchResult_6) {
|
|
1886
|
+
case 0:
|
|
1887
|
+
throw new ParseException(new ParseError("\'in\' keyword is not supported", TokenStream__Peek(stream).Span));
|
|
1888
|
+
default: {
|
|
1889
|
+
let body_3;
|
|
1890
|
+
if (TokenStream__Peek(stream).Kind.tag === 2) {
|
|
1891
|
+
TokenStream__Next(stream);
|
|
1892
|
+
body_3 = parseBlock();
|
|
1893
|
+
}
|
|
1894
|
+
else {
|
|
1895
|
+
body_3 = parseExprOrBlock();
|
|
1896
|
+
}
|
|
1897
|
+
if (bindings.length === 1) {
|
|
1898
|
+
return new Expr(10, [bindingName, foldBack_1((arg_3, acc_1) => (new Expr(4, [arg_3, acc_1, Ast_spanOfExpr(acc_1)])), args_2, value_70), body_3, true, returnAnnotation, mkSpanFrom(letTok.Span, Ast_spanOfExpr(body_3))]);
|
|
1899
|
+
}
|
|
1900
|
+
else {
|
|
1901
|
+
return new Expr(12, [toList(bindings), body_3, mkSpanFrom(letTok.Span, Ast_spanOfExpr(body_3))]);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
else {
|
|
1907
|
+
const matchValue_45 = TokenStream__Peek(stream).Kind;
|
|
1908
|
+
let matchResult_7;
|
|
1909
|
+
if (matchValue_45.tag === 4) {
|
|
1910
|
+
if (matchValue_45.fields[0] === "in") {
|
|
1911
|
+
matchResult_7 = 0;
|
|
1912
|
+
}
|
|
1913
|
+
else {
|
|
1914
|
+
matchResult_7 = 1;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
matchResult_7 = 1;
|
|
1919
|
+
}
|
|
1920
|
+
switch (matchResult_7) {
|
|
1921
|
+
case 0:
|
|
1922
|
+
throw new ParseException(new ParseError("\'in\' keyword is not supported", TokenStream__Peek(stream).Span));
|
|
1923
|
+
default: {
|
|
1924
|
+
let body_4;
|
|
1925
|
+
if (TokenStream__Peek(stream).Kind.tag === 2) {
|
|
1926
|
+
TokenStream__Next(stream);
|
|
1927
|
+
body_4 = parseBlock();
|
|
1928
|
+
}
|
|
1929
|
+
else {
|
|
1930
|
+
body_4 = parseExprOrBlock();
|
|
1931
|
+
}
|
|
1932
|
+
if (tuplePatternOpt == null) {
|
|
1933
|
+
return new Expr(10, [bindingName, foldBack_1((arg_4, acc_2) => (new Expr(4, [arg_4, acc_2, Ast_spanOfExpr(acc_2)])), args_2, value_70), body_4, false, returnAnnotation, mkSpanFrom(letTok.Span, Ast_spanOfExpr(body_4))]);
|
|
1934
|
+
}
|
|
1935
|
+
else if ((pattern_2 = tuplePatternOpt, args_2.length > 0)) {
|
|
1936
|
+
const pattern_3 = tuplePatternOpt;
|
|
1937
|
+
throw new ParseException(new ParseError("Tuple let binding cannot take function parameters", Ast_spanOfPattern(pattern_3)));
|
|
1938
|
+
}
|
|
1939
|
+
else {
|
|
1940
|
+
const pattern_4 = tuplePatternOpt;
|
|
1941
|
+
return new Expr(11, [pattern_4, value_70, body_4, mkSpanFrom(letTok.Span, Ast_spanOfExpr(body_4))]);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
const parseExprOrBlock = () => {
|
|
1948
|
+
let sawNewline_4 = false;
|
|
1949
|
+
while (TokenStream__Match_5CEB78CD(stream, new TokenKind(1, []))) {
|
|
1950
|
+
sawNewline_4 = true;
|
|
1951
|
+
}
|
|
1952
|
+
if (sawNewline_4 && TokenStream__Match_5CEB78CD(stream, new TokenKind(2, []))) {
|
|
1953
|
+
return parseBlock();
|
|
1954
|
+
}
|
|
1955
|
+
else {
|
|
1956
|
+
return parseExpr();
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
const parseExpr = () => parseBinary(0);
|
|
1960
|
+
const parseBlock = () => {
|
|
1961
|
+
const statements = [];
|
|
1962
|
+
let doneBlock = false;
|
|
1963
|
+
let blockStatementColumn = undefined;
|
|
1964
|
+
while (!doneBlock) {
|
|
1965
|
+
let col, matchValue_49;
|
|
1966
|
+
TokenStream__SkipNewlines(stream);
|
|
1967
|
+
const matchValue_47 = TokenStream__Peek(stream).Kind;
|
|
1968
|
+
let matchResult_8;
|
|
1969
|
+
switch (matchValue_47.tag) {
|
|
1970
|
+
case 3: {
|
|
1971
|
+
matchResult_8 = 0;
|
|
1972
|
+
break;
|
|
1973
|
+
}
|
|
1974
|
+
case 28:
|
|
1975
|
+
case 30:
|
|
1976
|
+
case 44: {
|
|
1977
|
+
matchResult_8 = 1;
|
|
1978
|
+
break;
|
|
1979
|
+
}
|
|
1980
|
+
case 0: {
|
|
1981
|
+
matchResult_8 = 2;
|
|
1982
|
+
break;
|
|
1983
|
+
}
|
|
1984
|
+
case 10: {
|
|
1985
|
+
matchResult_8 = 3;
|
|
1986
|
+
break;
|
|
1987
|
+
}
|
|
1988
|
+
case 39: {
|
|
1989
|
+
matchResult_8 = 4;
|
|
1990
|
+
break;
|
|
1991
|
+
}
|
|
1992
|
+
case 42: {
|
|
1993
|
+
matchResult_8 = 6;
|
|
1994
|
+
break;
|
|
1995
|
+
}
|
|
1996
|
+
case 38: {
|
|
1997
|
+
if (equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(39, [])) ? true : equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(41, []))) {
|
|
1998
|
+
matchResult_8 = 5;
|
|
1999
|
+
}
|
|
2000
|
+
else {
|
|
2001
|
+
matchResult_8 = 8;
|
|
2002
|
+
}
|
|
2003
|
+
break;
|
|
2004
|
+
}
|
|
2005
|
+
case 29: {
|
|
2006
|
+
if (equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(54, []))) {
|
|
2007
|
+
matchResult_8 = 7;
|
|
2008
|
+
}
|
|
2009
|
+
else {
|
|
2010
|
+
matchResult_8 = 8;
|
|
2011
|
+
}
|
|
2012
|
+
break;
|
|
2013
|
+
}
|
|
2014
|
+
default:
|
|
2015
|
+
matchResult_8 = 8;
|
|
2016
|
+
}
|
|
2017
|
+
switch (matchResult_8) {
|
|
2018
|
+
case 0: {
|
|
2019
|
+
TokenStream__Next(stream);
|
|
2020
|
+
TokenStream__SkipNewlines(stream);
|
|
2021
|
+
const findNextNonLayout = (offset_mut) => {
|
|
2022
|
+
findNextNonLayout:
|
|
2023
|
+
while (true) {
|
|
2024
|
+
const offset = offset_mut;
|
|
2025
|
+
const matchValue_48 = TokenStream__PeekAt_Z524259A4(stream, offset).Kind;
|
|
2026
|
+
switch (matchValue_48.tag) {
|
|
2027
|
+
case 1:
|
|
2028
|
+
case 2:
|
|
2029
|
+
case 3: {
|
|
2030
|
+
offset_mut = (offset + 1);
|
|
2031
|
+
continue findNextNonLayout;
|
|
2032
|
+
}
|
|
2033
|
+
default:
|
|
2034
|
+
return TokenStream__PeekAt_Z524259A4(stream, offset);
|
|
2035
|
+
}
|
|
2036
|
+
break;
|
|
2037
|
+
}
|
|
2038
|
+
};
|
|
2039
|
+
const nextSignificant = findNextNonLayout(0);
|
|
2040
|
+
const next_4 = TokenStream__Peek(stream);
|
|
2041
|
+
if (!((blockStatementColumn == null) ? false : ((col = (blockStatementColumn | 0), (matchValue_49 = nextSignificant.Kind, (matchValue_49.tag === 0) ? false : ((matchValue_49.tag === 3) ? false : ((matchValue_49.tag === 28) ? false : ((matchValue_49.tag === 30) ? false : ((matchValue_49.tag === 44) ? false : (nextSignificant.Span.Start.Column >= col)))))))))) {
|
|
2042
|
+
doneBlock = true;
|
|
2043
|
+
}
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
case 1: {
|
|
2047
|
+
doneBlock = true;
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
case 2: {
|
|
2051
|
+
doneBlock = true;
|
|
2052
|
+
break;
|
|
2053
|
+
}
|
|
2054
|
+
case 3: {
|
|
2055
|
+
if (blockStatementColumn == null) {
|
|
2056
|
+
blockStatementColumn = TokenStream__Peek(stream).Span.Start.Column;
|
|
2057
|
+
}
|
|
2058
|
+
void (statements.push(parseLetStmt(false)));
|
|
2059
|
+
break;
|
|
2060
|
+
}
|
|
2061
|
+
case 4: {
|
|
2062
|
+
throw new ParseException(new ParseError("\'import\' is only supported at top level", TokenStream__Peek(stream).Span));
|
|
2063
|
+
break;
|
|
2064
|
+
}
|
|
2065
|
+
case 5: {
|
|
2066
|
+
throw new ParseException(new ParseError("Use \'import \"file.fss\"\' at top level", TokenStream__Peek(stream).Span));
|
|
2067
|
+
break;
|
|
2068
|
+
}
|
|
2069
|
+
case 6: {
|
|
2070
|
+
throw new ParseException(new ParseError("\'module\' declarations were removed; module names are derived from imported filenames", TokenStream__Peek(stream).Span));
|
|
2071
|
+
break;
|
|
2072
|
+
}
|
|
2073
|
+
case 7: {
|
|
2074
|
+
throw new ParseException(new ParseError("\'[<export>]\' is only supported at top level", TokenStream__Peek(stream).Span));
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
case 8: {
|
|
2078
|
+
if (blockStatementColumn == null) {
|
|
2079
|
+
blockStatementColumn = TokenStream__Peek(stream).Span.Start.Column;
|
|
2080
|
+
}
|
|
2081
|
+
const expr_6 = parseExpr();
|
|
2082
|
+
void (statements.push(new Stmt(5, [expr_6])));
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
if (statements.length === 0) {
|
|
2088
|
+
throw new ParseException(new ParseError("Empty block", TokenStream__Peek(stream).Span));
|
|
2089
|
+
}
|
|
2090
|
+
const desugar = (stmts) => {
|
|
2091
|
+
if (!isEmpty(stmts)) {
|
|
2092
|
+
switch (head_1(stmts).tag) {
|
|
2093
|
+
case 2:
|
|
2094
|
+
if (isEmpty(tail_1(stmts))) {
|
|
2095
|
+
throw new ParseException(new ParseError("Block cannot end with a let binding; add a final expression", head_1(stmts).fields[6]));
|
|
2096
|
+
}
|
|
2097
|
+
else {
|
|
2098
|
+
const valExpr = foldBack_1((arg_5, acc_3) => (new Expr(4, [arg_5, acc_3, head_1(stmts).fields[6]])), head_1(stmts).fields[1], head_1(stmts).fields[3]);
|
|
2099
|
+
const body_5 = desugar(tail_1(stmts));
|
|
2100
|
+
return new Expr(10, [head_1(stmts).fields[0], valExpr, body_5, head_1(stmts).fields[4], head_1(stmts).fields[2], mkSpanFrom(head_1(stmts).fields[6], Ast_spanOfExpr(body_5))]);
|
|
2101
|
+
}
|
|
2102
|
+
case 3:
|
|
2103
|
+
if (isEmpty(tail_1(stmts))) {
|
|
2104
|
+
throw new ParseException(new ParseError("Block cannot end with a let binding; add a final expression", head_1(stmts).fields[3]));
|
|
2105
|
+
}
|
|
2106
|
+
else {
|
|
2107
|
+
const body_6 = desugar(tail_1(stmts));
|
|
2108
|
+
return new Expr(11, [head_1(stmts).fields[0], head_1(stmts).fields[1], body_6, mkSpanFrom(head_1(stmts).fields[3], Ast_spanOfExpr(body_6))]);
|
|
2109
|
+
}
|
|
2110
|
+
case 4:
|
|
2111
|
+
if (isEmpty(tail_1(stmts))) {
|
|
2112
|
+
throw new ParseException(new ParseError("Block cannot end with a let binding; add a final expression", head_1(stmts).fields[2]));
|
|
2113
|
+
}
|
|
2114
|
+
else {
|
|
2115
|
+
const body_7 = desugar(tail_1(stmts));
|
|
2116
|
+
return new Expr(12, [head_1(stmts).fields[0], body_7, mkSpanFrom(head_1(stmts).fields[2], Ast_spanOfExpr(body_7))]);
|
|
2117
|
+
}
|
|
2118
|
+
case 0:
|
|
2119
|
+
throw new ParseException(new ParseError("Type declarations are only supported at top level", head_1(stmts).fields[0].Span));
|
|
2120
|
+
case 1:
|
|
2121
|
+
throw new ParseException(new ParseError("\'import\' is only supported at top level", head_1(stmts).fields[2]));
|
|
2122
|
+
default:
|
|
2123
|
+
if (isEmpty(tail_1(stmts))) {
|
|
2124
|
+
return head_1(stmts).fields[0];
|
|
2125
|
+
}
|
|
2126
|
+
else {
|
|
2127
|
+
const body_8 = desugar(tail_1(stmts));
|
|
2128
|
+
return new Expr(10, ["_", head_1(stmts).fields[0], body_8, false, undefined, mkSpanFrom(Ast_spanOfExpr(head_1(stmts).fields[0]), Ast_spanOfExpr(body_8))]);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
else {
|
|
2133
|
+
return new Expr(0, [TokenStream__Peek(stream).Span]);
|
|
2134
|
+
}
|
|
2135
|
+
};
|
|
2136
|
+
return desugar(toList(statements));
|
|
2137
|
+
};
|
|
2138
|
+
const parseLetStmt = (isExported) => {
|
|
2139
|
+
let matchValue_52, pattern_8;
|
|
2140
|
+
const letTok_1 = TokenStream__Next(stream);
|
|
2141
|
+
const isRec_3 = TokenStream__Match_5CEB78CD(stream, new TokenKind(11, []));
|
|
2142
|
+
let patternInput_3;
|
|
2143
|
+
if (isRec_3) {
|
|
2144
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(27, []))) {
|
|
2145
|
+
throw new ParseException(new ParseError("\'let rec\' does not support pattern bindings", TokenStream__Peek(stream).Span));
|
|
2146
|
+
}
|
|
2147
|
+
const nameTok_15 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
|
|
2148
|
+
let name_18;
|
|
2149
|
+
const matchValue_50 = nameTok_15.Kind;
|
|
2150
|
+
name_18 = ((matchValue_50.tag === 4) ? matchValue_50.fields[0] : "");
|
|
2151
|
+
const args_4 = parseParamsAligned();
|
|
2152
|
+
if (args_4.length === 0) {
|
|
2153
|
+
throw new ParseException(new ParseError("\'let rec\' requires at least one function argument", nameTok_15.Span));
|
|
2154
|
+
}
|
|
2155
|
+
patternInput_3 = [name_18, args_4, undefined, nameTok_15.Span];
|
|
2156
|
+
}
|
|
2157
|
+
else if (TokenStream__Peek(stream).Kind.tag === 27) {
|
|
2158
|
+
if (isExported) {
|
|
2159
|
+
throw new ParseException(new ParseError("Exported let binding requires a single identifier, not a tuple pattern", TokenStream__Peek(stream).Span));
|
|
2160
|
+
}
|
|
2161
|
+
let pattern_7;
|
|
2162
|
+
const pattern_6 = parsePatternCons();
|
|
2163
|
+
if (pattern_6.tag === 5) {
|
|
2164
|
+
pattern_7 = pattern_6;
|
|
2165
|
+
}
|
|
2166
|
+
else {
|
|
2167
|
+
throw new ParseException(new ParseError("Only tuple patterns are supported in let bindings", Ast_spanOfPattern(pattern_6)));
|
|
2168
|
+
}
|
|
2169
|
+
patternInput_3 = ["", [], pattern_7, Ast_spanOfPattern(pattern_7)];
|
|
2170
|
+
}
|
|
2171
|
+
else {
|
|
2172
|
+
const nameTok_16 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
|
|
2173
|
+
patternInput_3 = [(matchValue_52 = nameTok_16.Kind, (matchValue_52.tag === 4) ? matchValue_52.fields[0] : ""), parseParamsAligned(), undefined, nameTok_16.Span];
|
|
2174
|
+
}
|
|
2175
|
+
const tuplePatternOpt_1 = patternInput_3[2];
|
|
2176
|
+
const bindingName_1 = patternInput_3[0];
|
|
2177
|
+
const args_5 = patternInput_3[1];
|
|
2178
|
+
TokenStream__SkipNewlines(stream);
|
|
2179
|
+
let returnAnnotation_2;
|
|
2180
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(35, []))) {
|
|
2181
|
+
if (args_5.length === 0) {
|
|
2182
|
+
throw new ParseException(new ParseError("Return type annotations are only supported on function let bindings", TokenStream__Peek(stream).Span));
|
|
2183
|
+
}
|
|
2184
|
+
returnAnnotation_2 = parseTypeRef();
|
|
2185
|
+
}
|
|
2186
|
+
else {
|
|
2187
|
+
returnAnnotation_2 = undefined;
|
|
2188
|
+
}
|
|
2189
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(35, []))) {
|
|
2190
|
+
throw new ParseException(new ParseError("Annotated parameters must be parenthesized as (x: T)", TokenStream__Peek(stream).Span));
|
|
2191
|
+
}
|
|
2192
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in let binding");
|
|
2193
|
+
const value_78 = parseExprOrBlock();
|
|
2194
|
+
if (isRec_3) {
|
|
2195
|
+
const bindings_2 = [];
|
|
2196
|
+
const firstSpan_1 = mkSpanFrom(patternInput_3[3], Ast_spanOfExpr(value_78));
|
|
2197
|
+
void (bindings_2.push([bindingName_1, toList(args_5), returnAnnotation_2, value_78, firstSpan_1]));
|
|
2198
|
+
let doneBindings_1 = false;
|
|
2199
|
+
while (!doneBindings_1) {
|
|
2200
|
+
TokenStream__SkipNewlines(stream);
|
|
2201
|
+
if (TokenStream__Match_5CEB78CD(stream, new TokenKind(12, []))) {
|
|
2202
|
+
const nextNameTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'and\'");
|
|
2203
|
+
let nextName_1;
|
|
2204
|
+
const matchValue_53 = nextNameTok_1.Kind;
|
|
2205
|
+
nextName_1 = ((matchValue_53.tag === 4) ? matchValue_53.fields[0] : "");
|
|
2206
|
+
const nextArgs_1 = parseParamsAligned();
|
|
2207
|
+
if (nextArgs_1.length === 0) {
|
|
2208
|
+
throw new ParseException(new ParseError("\'let rec ... and ...\' requires function arguments for each binding", nextNameTok_1.Span));
|
|
2209
|
+
}
|
|
2210
|
+
TokenStream__SkipNewlines(stream);
|
|
2211
|
+
const nextReturnAnnotation_1 = TokenStream__Match_5CEB78CD(stream, new TokenKind(35, [])) ? parseTypeRef() : undefined;
|
|
2212
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(35, []))) {
|
|
2213
|
+
throw new ParseException(new ParseError("Annotated parameters must be parenthesized as (x: T)", TokenStream__Peek(stream).Span));
|
|
2214
|
+
}
|
|
2215
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(25, []), "Expected \'=\' in let binding");
|
|
2216
|
+
const nextValue_1 = parseExprOrBlock();
|
|
2217
|
+
const nextSpan_1 = mkSpanFrom(nextNameTok_1.Span, Ast_spanOfExpr(nextValue_1));
|
|
2218
|
+
void (bindings_2.push([nextName_1, toList(nextArgs_1), nextReturnAnnotation_1, nextValue_1, nextSpan_1]));
|
|
2219
|
+
}
|
|
2220
|
+
else {
|
|
2221
|
+
doneBindings_1 = true;
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
if (bindings_2.length === 1) {
|
|
2225
|
+
return new Stmt(2, [bindingName_1, toList(args_5), returnAnnotation_2, value_78, true, isExported, mkSpanFrom(letTok_1.Span, Ast_spanOfExpr(value_78))]);
|
|
2226
|
+
}
|
|
2227
|
+
else {
|
|
2228
|
+
const patternInput_4 = item_1(bindings_2.length - 1, bindings_2);
|
|
2229
|
+
return new Stmt(4, [toList(bindings_2), isExported, mkSpanFrom(letTok_1.Span, patternInput_4[4])]);
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
else if (tuplePatternOpt_1 == null) {
|
|
2233
|
+
return new Stmt(2, [bindingName_1, toList(args_5), returnAnnotation_2, value_78, false, isExported, mkSpanFrom(letTok_1.Span, Ast_spanOfExpr(value_78))]);
|
|
2234
|
+
}
|
|
2235
|
+
else if ((pattern_8 = tuplePatternOpt_1, args_5.length > 0)) {
|
|
2236
|
+
const pattern_9 = tuplePatternOpt_1;
|
|
2237
|
+
throw new ParseException(new ParseError("Tuple let binding cannot take function parameters", Ast_spanOfPattern(pattern_9)));
|
|
2238
|
+
}
|
|
2239
|
+
else {
|
|
2240
|
+
const pattern_10 = tuplePatternOpt_1;
|
|
2241
|
+
return new Stmt(3, [pattern_10, value_78, isExported, mkSpanFrom(letTok_1.Span, Ast_spanOfExpr(value_78))]);
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
const parseAttributeName = () => {
|
|
2245
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(29, []), "Expected \'[\' in attribute");
|
|
2246
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(54, []), "Expected \'<\' in attribute");
|
|
2247
|
+
const nameTok_17 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected attribute name");
|
|
2248
|
+
let name_20;
|
|
2249
|
+
const matchValue_54 = nameTok_17.Kind;
|
|
2250
|
+
name_20 = ((matchValue_54.tag === 4) ? matchValue_54.fields[0] : "");
|
|
2251
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(55, []), "Expected \'>\' in attribute");
|
|
2252
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(30, []), "Expected \']\' in attribute");
|
|
2253
|
+
return [name_20, nameTok_17.Span];
|
|
2254
|
+
};
|
|
2255
|
+
const parseStmt = () => {
|
|
2256
|
+
let matchValue_58;
|
|
2257
|
+
TokenStream__SkipNewlines(stream);
|
|
2258
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(4, ["export"])) && equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(10, []))) {
|
|
2259
|
+
throw new ParseException(new ParseError("\'export let\' is no longer supported; use \'[<export>] let ...\'", TokenStream__Peek(stream).Span));
|
|
2260
|
+
}
|
|
2261
|
+
let isExported_1 = false;
|
|
2262
|
+
let hasAttributes = false;
|
|
2263
|
+
let parsingAttributes = true;
|
|
2264
|
+
while (parsingAttributes) {
|
|
2265
|
+
if (equals(TokenStream__Peek(stream).Kind, new TokenKind(29, [])) && equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, new TokenKind(54, []))) {
|
|
2266
|
+
hasAttributes = true;
|
|
2267
|
+
const patternInput_5 = parseAttributeName();
|
|
2268
|
+
const span_9 = patternInput_5[1];
|
|
2269
|
+
const name_21 = patternInput_5[0];
|
|
2270
|
+
if (name_21 === "export") {
|
|
2271
|
+
if (isExported_1) {
|
|
2272
|
+
throw new ParseException(new ParseError("Duplicate attribute \'export\'", span_9));
|
|
2273
|
+
}
|
|
2274
|
+
isExported_1 = true;
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
throw new ParseException(new ParseError(concat("Unknown attribute \'", name_21, "\'"), span_9));
|
|
2278
|
+
}
|
|
2279
|
+
TokenStream__SkipNewlines(stream);
|
|
2280
|
+
}
|
|
2281
|
+
else {
|
|
2282
|
+
parsingAttributes = false;
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
const matchValue_55 = TokenStream__Peek(stream).Kind;
|
|
2286
|
+
switch (matchValue_55.tag) {
|
|
2287
|
+
case 38: {
|
|
2288
|
+
if (hasAttributes ? true : isExported_1) {
|
|
2289
|
+
throw new ParseException(new ParseError("Attributes are not supported on \'import\' directives", TokenStream__Peek(stream).Span));
|
|
2290
|
+
}
|
|
2291
|
+
const hashTok = TokenStream__Next(stream);
|
|
2292
|
+
const matchValue_56 = TokenStream__Next(stream).Kind;
|
|
2293
|
+
switch (matchValue_56.tag) {
|
|
2294
|
+
case 41:
|
|
2295
|
+
throw new ParseException(new ParseError("\'#include\' was removed in 0.32.0; use \'import \"file.fss\" as Alias\'", hashTok.Span));
|
|
2296
|
+
case 39:
|
|
2297
|
+
throw new ParseException(new ParseError("\'#import\' was removed in 0.32.0; use \'import \"file.fss\" as Alias\'", hashTok.Span));
|
|
2298
|
+
default:
|
|
2299
|
+
throw new ParseException(new ParseError("Unexpected \'#\'; use \'import \"file.fss\" as Alias\'", hashTok.Span));
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
case 39: {
|
|
2303
|
+
if (hasAttributes ? true : isExported_1) {
|
|
2304
|
+
throw new ParseException(new ParseError("Attributes are not supported on \'import\' directives", TokenStream__Peek(stream).Span));
|
|
2305
|
+
}
|
|
2306
|
+
const importTok = TokenStream__Next(stream);
|
|
2307
|
+
const pathTok = TokenStream__Next(stream);
|
|
2308
|
+
const matchValue_57 = pathTok.Kind;
|
|
2309
|
+
if (matchValue_57.tag === 7) {
|
|
2310
|
+
if (!isNullOrWhiteSpace(matchValue_57.fields[0])) {
|
|
2311
|
+
TokenStream__Expect_77B9EE56(stream, new TokenKind(40, []), "Expected \'as\' in import directive. Use: import \"file.fss\" as Alias");
|
|
2312
|
+
const aliasTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected module alias after \'as\'");
|
|
2313
|
+
return new Stmt(1, [(matchValue_58 = aliasTok.Kind, (matchValue_58.tag === 4) ? matchValue_58.fields[0] : ""), matchValue_57.fields[0], mkSpanFrom(importTok.Span, aliasTok.Span)]);
|
|
2314
|
+
}
|
|
2315
|
+
else {
|
|
2316
|
+
throw new ParseException(new ParseError("Import path cannot be empty", pathTok.Span));
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
else {
|
|
2320
|
+
throw new ParseException(new ParseError("Expected string literal import path after \'import\'", pathTok.Span));
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
case 42:
|
|
2324
|
+
throw new ParseException(new ParseError("\'module\' declarations are not supported in scripts", TokenStream__Peek(stream).Span));
|
|
2325
|
+
case 45: {
|
|
2326
|
+
if (isExported_1) {
|
|
2327
|
+
throw new ParseException(new ParseError("\'[<export>]\' is only valid for top-level let bindings", TokenStream__Peek(stream).Span));
|
|
2328
|
+
}
|
|
2329
|
+
return parseTypeDecl();
|
|
2330
|
+
}
|
|
2331
|
+
case 10:
|
|
2332
|
+
return parseLetStmt(isExported_1);
|
|
2333
|
+
default:
|
|
2334
|
+
if (hasAttributes) {
|
|
2335
|
+
throw new ParseException(new ParseError("\'[<export>]\' must be followed by a top-level let binding", TokenStream__Peek(stream).Span));
|
|
2336
|
+
}
|
|
2337
|
+
else {
|
|
2338
|
+
return new Stmt(5, [parseExpr()]);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
};
|
|
2342
|
+
const program = [];
|
|
2343
|
+
TokenStream__SkipNewlines(stream);
|
|
2344
|
+
while (!TokenStream__get_AtEnd(stream)) {
|
|
2345
|
+
const matchValue_59 = TokenStream__Peek(stream).Kind;
|
|
2346
|
+
switch (matchValue_59.tag) {
|
|
2347
|
+
case 0: {
|
|
2348
|
+
TokenStream__Next(stream);
|
|
2349
|
+
break;
|
|
2350
|
+
}
|
|
2351
|
+
case 3: {
|
|
2352
|
+
TokenStream__Next(stream);
|
|
2353
|
+
break;
|
|
2354
|
+
}
|
|
2355
|
+
default: {
|
|
2356
|
+
const stmt = parseStmt();
|
|
2357
|
+
void (program.push(stmt));
|
|
2358
|
+
TokenStream__SkipNewlines(stream);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return toList(program);
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
export function parseProgram(src) {
|
|
2366
|
+
return parseProgramWithSourceName(undefined, src);
|
|
2367
|
+
}
|
|
2368
|
+
|