@magnusopera/fscript 0.83.3 → 0.84.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.
@@ -1,14 +1,14 @@
1
1
 
2
2
  import { class_type } from "../fable_modules/fable-library-js.5.13.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.13.0/List.js";
3
+ import { singleton, foldBack, head as head_1, tail as tail_1, isEmpty, empty, length, item } from "../fable_modules/fable-library-js.5.13.0/List.js";
4
4
  import { equals } from "../fable_modules/fable-library-js.5.13.0/Util.js";
5
5
  import { ParseException, ParseError } from "./Error.js";
6
6
  import { TokenKind } from "./Token.js";
7
7
  import { Span, SpanModule_merge } from "./Span.js";
8
- import { isNullOrWhiteSpace, substring, concat, join, isNullOrEmpty } from "../fable_modules/fable-library-js.5.13.0/String.js";
8
+ import { substring, isNullOrWhiteSpace, concat, join, isNullOrEmpty } from "../fable_modules/fable-library-js.5.13.0/String.js";
9
9
  import { isUpper } from "../fable_modules/fable-library-js.5.13.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";
10
+ import { Ast_spanOfStmt, Attribute, MapEntry, Ast_spanOfExpr, InterpolatedPart, Expr, Ast_spanOfPattern, Pattern, Stmt, TypeDef, BackendImport, Param, TypeRef, Literal } from "./Ast.js";
11
+ import { tokenizeWithSourceNameAndOrigin } from "./Lexer.js";
12
12
  import { addToSet } from "../fable_modules/fable-library-js.5.13.0/MapUtil.js";
13
13
  import { foldBack as foldBack_1, toList } from "../fable_modules/fable-library-js.5.13.0/Seq.js";
14
14
  import { StringBuilder__Append_244C7CD6, StringBuilder__Clear, StringBuilder__get_Length, StringBuilder_$ctor } from "../fable_modules/fable-library-js.5.13.0/System.Text.js";
@@ -172,8 +172,8 @@ function parseLiteral(t) {
172
172
  }
173
173
  }
174
174
 
175
- export function parseProgramWithSourceName(sourceName, src) {
176
- const tokens = tokenizeWithSourceName(sourceName, src);
175
+ function parseProgramWithSourceNameAndOrigin(sourceName, startLine, startColumn, src) {
176
+ const tokens = tokenizeWithSourceNameAndOrigin(sourceName, startLine, startColumn, src);
177
177
  const stream = TokenStream_$ctor_Z3FD4619(tokens);
178
178
  const consumeLayoutSeparators = () => {
179
179
  let consumed = false;
@@ -455,7 +455,8 @@ export function parseProgramWithSourceName(sourceName, src) {
455
455
  }
456
456
  return args;
457
457
  };
458
- const parseTypeDecl = () => {
458
+ const parseTypeDecl = (backendImport) => {
459
+ let option_1, attribute, matchValue_16;
459
460
  const typeTok = TokenStream__Expect_77B9EE56(stream, TokenKind.Type, "Expected \'type\'");
460
461
  const isRec = TokenStream__Match_5CEB78CD(stream, TokenKind.Rec);
461
462
  let name_1;
@@ -595,14 +596,22 @@ export function parseProgramWithSourceName(sourceName, src) {
595
596
  while (TokenStream__Match_5CEB78CD(stream, TokenKind.Dedent)) {
596
597
  }
597
598
  }
598
- return new Stmt(/* SType */ 0, [new TypeDef(name_1, isRec, patternInput_1[0], patternInput_1[1], mkSpanFrom(typeTok.Span, patternInput_1[2]))]);
599
+ return new Stmt(/* SType */ 0, [new TypeDef(name_1, isRec, patternInput_1[0], patternInput_1[1], (option_1 = backendImport, (option_1 != null) ? ((attribute = option_1, (matchValue_16 = attribute.Arguments, !isEmpty(matchValue_16) ? (!isEmpty(tail_1(matchValue_16)) ? (isEmpty(tail_1(tail_1(matchValue_16))) ? ((!isNullOrWhiteSpace(head_1(matchValue_16)) && !isNullOrWhiteSpace(head_1(tail_1(matchValue_16)))) ? (new BackendImport(head_1(matchValue_16), head_1(tail_1(matchValue_16)), attribute.Span)) : (() => {
600
+ throw new ParseException(new ParseError("Import requires module path and member name: [<Import(\"module/path\", \"Member\")>]", attribute.Span));
601
+ })()) : (() => {
602
+ throw new ParseException(new ParseError("Import requires module path and member name: [<Import(\"module/path\", \"Member\")>]", attribute.Span));
603
+ })()) : (() => {
604
+ throw new ParseException(new ParseError("Import requires module path and member name: [<Import(\"module/path\", \"Member\")>]", attribute.Span));
605
+ })()) : (() => {
606
+ throw new ParseException(new ParseError("Import requires module path and member name: [<Import(\"module/path\", \"Member\")>]", attribute.Span));
607
+ })()))) : undefined), mkSpanFrom(typeTok.Span, patternInput_1[2]))]);
599
608
  };
600
609
  const parsePattern = () => {
601
610
  TokenStream__SkipNewlines(stream);
602
611
  const t_1 = TokenStream__Peek(stream);
603
- const matchValue_16 = t_1.Kind;
612
+ const matchValue_17 = t_1.Kind;
604
613
  let matchResult_1, name_3, name_4;
605
- switch (matchValue_16.tag) {
614
+ switch (matchValue_17.tag) {
606
615
  case 5:
607
616
  case 6:
608
617
  case 7:
@@ -623,13 +632,13 @@ export function parseProgramWithSourceName(sourceName, src) {
623
632
  break;
624
633
  }
625
634
  case 4: {
626
- if (matchValue_16.fields[0] === "_") {
635
+ if (matchValue_17.fields[0] === "_") {
627
636
  matchResult_1 = 0;
628
- name_3 = matchValue_16.fields[0];
637
+ name_3 = matchValue_17.fields[0];
629
638
  }
630
639
  else {
631
640
  matchResult_1 = 1;
632
- name_4 = matchValue_16.fields[0];
641
+ name_4 = matchValue_17.fields[0];
633
642
  }
634
643
  break;
635
644
  }
@@ -644,8 +653,8 @@ export function parseProgramWithSourceName(sourceName, src) {
644
653
  if (isUpperIdent(name_4) && TokenStream__Match_5CEB78CD(stream, TokenKind.Dot)) {
645
654
  const caseTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected union case name after \'.\'");
646
655
  let caseName_1;
647
- const matchValue_17 = caseTok_1.Kind;
648
- caseName_1 = ((matchValue_17.tag === 4) ? matchValue_17.fields[0] : "");
656
+ const matchValue_18 = caseTok_1.Kind;
657
+ caseName_1 = ((matchValue_18.tag === 4) ? matchValue_18.fields[0] : "");
649
658
  if (!isUpperIdent(caseName_1)) {
650
659
  throw new ParseException(new ParseError("Union case name must start with uppercase letter", caseTok_1.Span));
651
660
  }
@@ -746,8 +755,8 @@ export function parseProgramWithSourceName(sourceName, src) {
746
755
  const parseTypeField = () => {
747
756
  const nameTok_3 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record type pattern");
748
757
  let fieldName_2;
749
- const matchValue_18 = nameTok_3.Kind;
750
- fieldName_2 = ((matchValue_18.tag === 4) ? matchValue_18.fields[0] : "");
758
+ const matchValue_19 = nameTok_3.Kind;
759
+ fieldName_2 = ((matchValue_19.tag === 4) ? matchValue_19.fields[0] : "");
751
760
  if (!addToSet(fieldName_2, seen_1)) {
752
761
  throw new ParseException(new ParseError(concat("Duplicate field \'", fieldName_2, "\' in structural record type pattern"), nameTok_3.Span));
753
762
  }
@@ -833,7 +842,7 @@ export function parseProgramWithSourceName(sourceName, src) {
833
842
  TokenStream__SkipNewlines(stream);
834
843
  isTypeRefPattern = TokenStream__Match_5CEB78CD(stream, TokenKind.Colon);
835
844
  }
836
- catch (matchValue_19) {
845
+ catch (matchValue_20) {
837
846
  isTypeRefPattern = false;
838
847
  }
839
848
  TokenStream__Restore_Z524259A4(stream, mark);
@@ -844,8 +853,8 @@ export function parseProgramWithSourceName(sourceName, src) {
844
853
  TokenStream__SkipNewlines(stream);
845
854
  const nameTok_4 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record type pattern");
846
855
  let name_5;
847
- const matchValue_20 = nameTok_4.Kind;
848
- name_5 = ((matchValue_20.tag === 4) ? matchValue_20.fields[0] : "");
856
+ const matchValue_21 = nameTok_4.Kind;
857
+ name_5 = ((matchValue_21.tag === 4) ? matchValue_21.fields[0] : "");
849
858
  if (!addToSet(name_5, seen_2)) {
850
859
  throw new ParseException(new ParseError(concat("Duplicate field \'", name_5, "\' in record type pattern"), nameTok_4.Span));
851
860
  }
@@ -874,8 +883,8 @@ export function parseProgramWithSourceName(sourceName, src) {
874
883
  TokenStream__SkipNewlines(stream);
875
884
  const nameTok_5 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record pattern");
876
885
  let name_6;
877
- const matchValue_21 = nameTok_5.Kind;
878
- name_6 = ((matchValue_21.tag === 4) ? matchValue_21.fields[0] : "");
886
+ const matchValue_22 = nameTok_5.Kind;
887
+ name_6 = ((matchValue_22.tag === 4) ? matchValue_22.fields[0] : "");
879
888
  if (!addToSet(name_6, seen_3)) {
880
889
  throw new ParseException(new ParseError(concat("Duplicate field \'", name_6, "\' in record pattern"), nameTok_5.Span));
881
890
  }
@@ -937,12 +946,12 @@ export function parseProgramWithSourceName(sourceName, src) {
937
946
  }
938
947
  };
939
948
  const parsePrimary = () => {
940
- let matchValue_29, matchValue_30;
949
+ let matchValue_30, matchValue_31;
941
950
  TokenStream__SkipNewlines(stream);
942
951
  const t_6 = TokenStream__Peek(stream);
943
- const matchValue_22 = t_6.Kind;
952
+ const matchValue_23 = t_6.Kind;
944
953
  let matchResult_2, raw_1, name_7;
945
- switch (matchValue_22.tag) {
954
+ switch (matchValue_23.tag) {
946
955
  case 5:
947
956
  case 6:
948
957
  case 7:
@@ -1004,22 +1013,22 @@ export function parseProgramWithSourceName(sourceName, src) {
1004
1013
  }
1005
1014
  case 8: {
1006
1015
  matchResult_2 = 1;
1007
- raw_1 = matchValue_22.fields[0];
1016
+ raw_1 = matchValue_23.fields[0];
1008
1017
  break;
1009
1018
  }
1010
1019
  case 4: {
1011
- if (matchValue_22.fields[0] === "export") {
1020
+ if (matchValue_23.fields[0] === "export") {
1012
1021
  if (equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, TokenKind.Let)) {
1013
1022
  matchResult_2 = 2;
1014
1023
  }
1015
1024
  else {
1016
1025
  matchResult_2 = 3;
1017
- name_7 = matchValue_22.fields[0];
1026
+ name_7 = matchValue_23.fields[0];
1018
1027
  }
1019
1028
  }
1020
1029
  else {
1021
1030
  matchResult_2 = 3;
1022
- name_7 = matchValue_22.fields[0];
1031
+ name_7 = matchValue_23.fields[0];
1023
1032
  }
1024
1033
  break;
1025
1034
  }
@@ -1154,7 +1163,18 @@ export function parseProgramWithSourceName(sourceName, src) {
1154
1163
  if (isNullOrWhiteSpace(exprText_1)) {
1155
1164
  throw new ParseException(new ParseError("Interpolation placeholder cannot be empty", span));
1156
1165
  }
1157
- patternInput = [(parsed = parseProgramWithSourceName(undefined, exprText_1), !isEmpty(parsed) ? ((head_1(parsed).tag === 5) ? (isEmpty(tail_1(parsed)) ? head_1(parsed).fields[0] : (() => {
1166
+ let originLine_1 = span.Start.Line;
1167
+ let originColumn_1 = span.Start.Column + 2;
1168
+ for (let offset = 0; offset <= (start - 1); offset++) {
1169
+ if (s[offset] === "\n") {
1170
+ originLine_1 = ((originLine_1 + 1) | 0);
1171
+ originColumn_1 = 1;
1172
+ }
1173
+ else {
1174
+ originColumn_1 = ((originColumn_1 + 1) | 0);
1175
+ }
1176
+ }
1177
+ patternInput = [(parsed = parseProgramWithSourceNameAndOrigin(sourceName, originLine_1, originColumn_1, exprText_1), !isEmpty(parsed) ? ((head_1(parsed).tag === 7) ? (isEmpty(tail_1(parsed)) ? head_1(parsed).fields[0] : (() => {
1158
1178
  throw new ParseException(new ParseError("Interpolation placeholders must contain a single expression", TokenStream__Peek(stream).Span));
1159
1179
  })()) : (() => {
1160
1180
  throw new ParseException(new ParseError("Interpolation placeholders must contain a single expression", TokenStream__Peek(stream).Span));
@@ -1296,19 +1316,19 @@ export function parseProgramWithSourceName(sourceName, src) {
1296
1316
  throw new ParseException(new ParseError("Structural record literal must define at least one field", TokenStream__Peek(stream).Span));
1297
1317
  }
1298
1318
  const mark_1 = TokenStream__Mark(stream) | 0;
1299
- let matchValue_24;
1319
+ let matchValue_25;
1300
1320
  const baseExpr = parseExpr();
1301
1321
  TokenStream__SkipNewlines(stream);
1302
1322
  if (!TokenStream__Match_5CEB78CD(stream, TokenKind.With)) {
1303
1323
  TokenStream__Restore_Z524259A4(stream, mark_1);
1304
- matchValue_24 = undefined;
1324
+ matchValue_25 = undefined;
1305
1325
  }
1306
1326
  else {
1307
1327
  const updates = [];
1308
1328
  const parseUpdateField = () => {
1309
1329
  let name_8;
1310
- const matchValue_23 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record update").Kind;
1311
- name_8 = ((matchValue_23.tag === 4) ? matchValue_23.fields[0] : "");
1330
+ const matchValue_24 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record update").Kind;
1331
+ name_8 = ((matchValue_24.tag === 4) ? matchValue_24.fields[0] : "");
1312
1332
  TokenStream__SkipNewlines(stream);
1313
1333
  TokenStream__Expect_77B9EE56(stream, TokenKind.Equals, "Expected \'=\' in structural record update field");
1314
1334
  const value_41 = parseEntryExpr();
@@ -1330,14 +1350,14 @@ export function parseProgramWithSourceName(sourceName, src) {
1330
1350
  if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_7, rb_8.Span.Start.Line)) {
1331
1351
  throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_8.Span));
1332
1352
  }
1333
- matchValue_24 = (new Expr(/* EStructuralRecordUpdate */ 20, [baseExpr, toList(updates), mkSpanFrom(lb_4.Span, rb_8.Span)]));
1353
+ matchValue_25 = (new Expr(/* EStructuralRecordUpdate */ 20, [baseExpr, toList(updates), mkSpanFrom(lb_4.Span, rb_8.Span)]));
1334
1354
  }
1335
- if (matchValue_24 == null) {
1355
+ if (matchValue_25 == null) {
1336
1356
  const fields_6 = [];
1337
1357
  const parseField_3 = () => {
1338
1358
  let name_9;
1339
- const matchValue_25 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record literal").Kind;
1340
- name_9 = ((matchValue_25.tag === 4) ? matchValue_25.fields[0] : "");
1359
+ const matchValue_26 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in structural record literal").Kind;
1360
+ name_9 = ((matchValue_26.tag === 4) ? matchValue_26.fields[0] : "");
1341
1361
  TokenStream__SkipNewlines(stream);
1342
1362
  TokenStream__Expect_77B9EE56(stream, TokenKind.Equals, "Expected \'=\' in structural record field");
1343
1363
  const value_45 = parseEntryExpr();
@@ -1362,7 +1382,7 @@ export function parseProgramWithSourceName(sourceName, src) {
1362
1382
  return new Expr(/* EStructuralRecord */ 17, [toList(fields_6), mkSpanFrom(lb_4.Span, rb_9.Span)]);
1363
1383
  }
1364
1384
  else {
1365
- return matchValue_24;
1385
+ return matchValue_25;
1366
1386
  }
1367
1387
  }
1368
1388
  else if (equals(TokenStream__Peek(stream).Kind, TokenKind.LBracket) ? true : equals(TokenStream__Peek(stream).Kind, TokenKind.RangeDots)) {
@@ -1407,19 +1427,19 @@ export function parseProgramWithSourceName(sourceName, src) {
1407
1427
  }
1408
1428
  else {
1409
1429
  const mark_2 = TokenStream__Mark(stream) | 0;
1410
- let matchValue_27;
1430
+ let matchValue_28;
1411
1431
  const baseExpr_1 = parseExpr();
1412
1432
  TokenStream__SkipNewlines(stream);
1413
1433
  if (!TokenStream__Match_5CEB78CD(stream, TokenKind.With)) {
1414
1434
  TokenStream__Restore_Z524259A4(stream, mark_2);
1415
- matchValue_27 = undefined;
1435
+ matchValue_28 = undefined;
1416
1436
  }
1417
1437
  else {
1418
1438
  const updates_1 = [];
1419
1439
  const parseUpdateField_1 = () => {
1420
1440
  let name_10;
1421
- const matchValue_26 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record update").Kind;
1422
- name_10 = ((matchValue_26.tag === 4) ? matchValue_26.fields[0] : "");
1441
+ const matchValue_27 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record update").Kind;
1442
+ name_10 = ((matchValue_27.tag === 4) ? matchValue_27.fields[0] : "");
1423
1443
  TokenStream__SkipNewlines(stream);
1424
1444
  TokenStream__Expect_77B9EE56(stream, TokenKind.Equals, "Expected \'=\' in record update field");
1425
1445
  const value_54 = parseEntryExpr();
@@ -1440,14 +1460,14 @@ export function parseProgramWithSourceName(sourceName, src) {
1440
1460
  if (!hasNonLayoutTokenBeforeOnSameLine(rbIndex_10, rb_11.Span.Start.Line)) {
1441
1461
  throw new ParseException(new ParseError("Closing \'}\' cannot be on its own line; keep it with the last entry", rb_11.Span));
1442
1462
  }
1443
- matchValue_27 = (new Expr(/* ERecordUpdate */ 19, [baseExpr_1, toList(updates_1), mkSpanFrom(lb_4.Span, rb_11.Span)]));
1463
+ matchValue_28 = (new Expr(/* ERecordUpdate */ 19, [baseExpr_1, toList(updates_1), mkSpanFrom(lb_4.Span, rb_11.Span)]));
1444
1464
  }
1445
- if (matchValue_27 == null) {
1465
+ if (matchValue_28 == null) {
1446
1466
  const fields_7 = [];
1447
1467
  const parseField_4 = () => {
1448
1468
  let name_11;
1449
- const matchValue_28 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record literal").Kind;
1450
- name_11 = ((matchValue_28.tag === 4) ? matchValue_28.fields[0] : "");
1469
+ const matchValue_29 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name in record literal").Kind;
1470
+ name_11 = ((matchValue_29.tag === 4) ? matchValue_29.fields[0] : "");
1451
1471
  TokenStream__SkipNewlines(stream);
1452
1472
  TokenStream__Expect_77B9EE56(stream, TokenKind.Equals, "Expected \'=\' in record field");
1453
1473
  const value_57 = parseEntryExpr();
@@ -1471,7 +1491,7 @@ export function parseProgramWithSourceName(sourceName, src) {
1471
1491
  return new Expr(/* ERecord */ 16, [toList(fields_7), mkSpanFrom(lb_4.Span, rb_12.Span)]);
1472
1492
  }
1473
1493
  else {
1474
- return matchValue_27;
1494
+ return matchValue_28;
1475
1495
  }
1476
1496
  }
1477
1497
  }
@@ -1493,12 +1513,12 @@ export function parseProgramWithSourceName(sourceName, src) {
1493
1513
  case 13: {
1494
1514
  const t_10 = TokenStream__Next(stream);
1495
1515
  const nameTok_10 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected type name after \'typeof\'");
1496
- return new Expr(/* ETypeOf */ 28, [(matchValue_29 = nameTok_10.Kind, (matchValue_29.tag === 4) ? matchValue_29.fields[0] : ""), mkSpanFrom(t_10.Span, nameTok_10.Span)]);
1516
+ return new Expr(/* ETypeOf */ 28, [(matchValue_30 = nameTok_10.Kind, (matchValue_30.tag === 4) ? matchValue_30.fields[0] : ""), mkSpanFrom(t_10.Span, nameTok_10.Span)]);
1497
1517
  }
1498
1518
  case 14: {
1499
1519
  const t_11 = TokenStream__Next(stream);
1500
1520
  const nameTok_11 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'nameof\'");
1501
- return new Expr(/* ENameOf */ 29, [(matchValue_30 = nameTok_11.Kind, (matchValue_30.tag === 4) ? matchValue_30.fields[0] : ""), mkSpanFrom(t_11.Span, nameTok_11.Span)]);
1521
+ return new Expr(/* ENameOf */ 29, [(matchValue_31 = nameTok_11.Kind, (matchValue_31.tag === 4) ? matchValue_31.fields[0] : ""), mkSpanFrom(t_11.Span, nameTok_11.Span)]);
1502
1522
  }
1503
1523
  case 15:
1504
1524
  throw new ParseException(new ParseError("Indentation error: unexpected indent in expression", t_6.Span));
@@ -1515,8 +1535,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1515
1535
  if (TokenStream__Match_5CEB78CD(stream, TokenKind.Dot)) {
1516
1536
  const fieldTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected field name after \'.\'");
1517
1537
  let fieldName_3;
1518
- const matchValue_31 = fieldTok_1.Kind;
1519
- fieldName_3 = ((matchValue_31.tag === 4) ? matchValue_31.fields[0] : "");
1538
+ const matchValue_32 = fieldTok_1.Kind;
1539
+ fieldName_3 = ((matchValue_32.tag === 4) ? matchValue_32.fields[0] : "");
1520
1540
  expr_3 = (new Expr(/* EFieldGet */ 21, [expr_3, fieldName_3, mkSpanFrom(Ast_spanOfExpr(expr_3), fieldTok_1.Span)]));
1521
1541
  }
1522
1542
  else if (equals(TokenStream__Peek(stream).Kind, TokenKind.LBracket)) {
@@ -1659,8 +1679,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1659
1679
  TokenStream__SkipNewlines(stream);
1660
1680
  }
1661
1681
  let elseExpr;
1662
- const matchValue_32 = TokenStream__Peek(stream).Kind;
1663
- switch (matchValue_32.tag) {
1682
+ const matchValue_33 = TokenStream__Peek(stream).Kind;
1683
+ switch (matchValue_33.tag) {
1664
1684
  case 19: {
1665
1685
  TokenStream__Next(stream);
1666
1686
  elseExpr = parseExprOrBlock();
@@ -1678,13 +1698,13 @@ export function parseProgramWithSourceName(sourceName, src) {
1678
1698
  const parseFor = () => {
1679
1699
  const forTok = TokenStream__Expect_77B9EE56(stream, TokenKind.For, "Expected \'for\'");
1680
1700
  let name_14;
1681
- const matchValue_33 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'for\'").Kind;
1682
- name_14 = ((matchValue_33.tag === 4) ? matchValue_33.fields[0] : "");
1701
+ const matchValue_34 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'for\'").Kind;
1702
+ name_14 = ((matchValue_34.tag === 4) ? matchValue_34.fields[0] : "");
1683
1703
  TokenStream__SkipNewlines(stream);
1684
- const matchValue_34 = TokenStream__Peek(stream).Kind;
1704
+ const matchValue_35 = TokenStream__Peek(stream).Kind;
1685
1705
  let matchResult_4;
1686
- if (matchValue_34.tag === 4) {
1687
- if (matchValue_34.fields[0] === "in") {
1706
+ if (matchValue_35.tag === 4) {
1707
+ if (matchValue_35.fields[0] === "in") {
1688
1708
  matchResult_4 = 0;
1689
1709
  }
1690
1710
  else {
@@ -1706,10 +1726,10 @@ export function parseProgramWithSourceName(sourceName, src) {
1706
1726
  }
1707
1727
  const source_19 = parsePostfix();
1708
1728
  TokenStream__SkipNewlines(stream);
1709
- const matchValue_35 = TokenStream__Peek(stream).Kind;
1729
+ const matchValue_36 = TokenStream__Peek(stream).Kind;
1710
1730
  let matchResult_5;
1711
- if (matchValue_35.tag === 4) {
1712
- if (matchValue_35.fields[0] === "do") {
1731
+ if (matchValue_36.tag === 4) {
1732
+ if (matchValue_36.fields[0] === "do") {
1713
1733
  matchResult_5 = 0;
1714
1734
  }
1715
1735
  else {
@@ -1738,8 +1758,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1738
1758
  let doneParams = false;
1739
1759
  while (!doneParams) {
1740
1760
  TokenStream__SkipNewlines(stream);
1741
- const matchValue_36 = TokenStream__Peek(stream).Kind;
1742
- switch (matchValue_36.tag) {
1761
+ const matchValue_37 = TokenStream__Peek(stream).Kind;
1762
+ switch (matchValue_37.tag) {
1743
1763
  case 4:
1744
1764
  case 27: {
1745
1765
  void (parameters.push(parseParam()));
@@ -1805,9 +1825,9 @@ export function parseProgramWithSourceName(sourceName, src) {
1805
1825
  let doneCases_1 = false;
1806
1826
  while (!doneCases_1) {
1807
1827
  TokenStream__SkipNewlines(stream);
1808
- const matchValue_37 = TokenStream__Peek(stream).Kind;
1828
+ const matchValue_38 = TokenStream__Peek(stream).Kind;
1809
1829
  let matchResult_6;
1810
- switch (matchValue_37.tag) {
1830
+ switch (matchValue_38.tag) {
1811
1831
  case 26: {
1812
1832
  matchResult_6 = 0;
1813
1833
  break;
@@ -1860,8 +1880,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1860
1880
  let doneCases_2 = false;
1861
1881
  while (!doneCases_2) {
1862
1882
  TokenStream__SkipNewlines(stream);
1863
- const matchValue_38 = TokenStream__Peek(stream).Kind;
1864
- switch (matchValue_38.tag) {
1883
+ const matchValue_39 = TokenStream__Peek(stream).Kind;
1884
+ switch (matchValue_39.tag) {
1865
1885
  case 26: {
1866
1886
  parseCase_1();
1867
1887
  break;
@@ -1879,7 +1899,7 @@ export function parseProgramWithSourceName(sourceName, src) {
1879
1899
  return new Expr(/* EMatch */ 9, [expr_5, toList(cases_2), mkSpanFrom(matchTok.Span, Ast_spanOfExpr(expr_5))]);
1880
1900
  };
1881
1901
  const parseLetExpr = () => {
1882
- let matchValue_41;
1902
+ let matchValue_42;
1883
1903
  const letTok = TokenStream__Expect_77B9EE56(stream, TokenKind.Let, "Expected \'let\'");
1884
1904
  const isRec_1 = TokenStream__Match_5CEB78CD(stream, TokenKind.Rec);
1885
1905
  let patternInput_2;
@@ -1889,8 +1909,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1889
1909
  }
1890
1910
  const nameTok_13 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
1891
1911
  let name_15;
1892
- const matchValue_39 = nameTok_13.Kind;
1893
- name_15 = ((matchValue_39.tag === 4) ? matchValue_39.fields[0] : "");
1912
+ const matchValue_40 = nameTok_13.Kind;
1913
+ name_15 = ((matchValue_40.tag === 4) ? matchValue_40.fields[0] : "");
1894
1914
  const args_1 = parseParamsAligned();
1895
1915
  if (args_1.length === 0) {
1896
1916
  throw new ParseException(new ParseError("\'let rec\' requires at least one function argument", nameTok_13.Span));
@@ -1910,7 +1930,7 @@ export function parseProgramWithSourceName(sourceName, src) {
1910
1930
  }
1911
1931
  else {
1912
1932
  const nameTok_14 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
1913
- patternInput_2 = [(matchValue_41 = nameTok_14.Kind, (matchValue_41.tag === 4) ? matchValue_41.fields[0] : ""), parseParamsAligned(), undefined, nameTok_14.Span];
1933
+ patternInput_2 = [(matchValue_42 = nameTok_14.Kind, (matchValue_42.tag === 4) ? matchValue_42.fields[0] : ""), parseParamsAligned(), undefined, nameTok_14.Span];
1914
1934
  }
1915
1935
  const tuplePatternOpt = patternInput_2[2];
1916
1936
  const bindingName = patternInput_2[0];
@@ -1941,8 +1961,8 @@ export function parseProgramWithSourceName(sourceName, src) {
1941
1961
  if (TokenStream__Match_5CEB78CD(stream, TokenKind.And)) {
1942
1962
  const nextNameTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'and\'");
1943
1963
  let nextName;
1944
- const matchValue_42 = nextNameTok.Kind;
1945
- nextName = ((matchValue_42.tag === 4) ? matchValue_42.fields[0] : "");
1964
+ const matchValue_43 = nextNameTok.Kind;
1965
+ nextName = ((matchValue_43.tag === 4) ? matchValue_43.fields[0] : "");
1946
1966
  const nextArgs = parseParamsAligned();
1947
1967
  if (nextArgs.length === 0) {
1948
1968
  throw new ParseException(new ParseError("\'let rec ... and ...\' requires function arguments for each binding", nextNameTok.Span));
@@ -1961,10 +1981,10 @@ export function parseProgramWithSourceName(sourceName, src) {
1961
1981
  doneBindings = true;
1962
1982
  }
1963
1983
  }
1964
- const matchValue_43 = TokenStream__Peek(stream).Kind;
1984
+ const matchValue_44 = TokenStream__Peek(stream).Kind;
1965
1985
  let matchResult_7;
1966
- if (matchValue_43.tag === 4) {
1967
- if (matchValue_43.fields[0] === "in") {
1986
+ if (matchValue_44.tag === 4) {
1987
+ if (matchValue_44.fields[0] === "in") {
1968
1988
  matchResult_7 = 0;
1969
1989
  }
1970
1990
  else {
@@ -1996,10 +2016,10 @@ export function parseProgramWithSourceName(sourceName, src) {
1996
2016
  }
1997
2017
  }
1998
2018
  else {
1999
- const matchValue_45 = TokenStream__Peek(stream).Kind;
2019
+ const matchValue_46 = TokenStream__Peek(stream).Kind;
2000
2020
  let matchResult_8;
2001
- if (matchValue_45.tag === 4) {
2002
- if (matchValue_45.fields[0] === "in") {
2021
+ if (matchValue_46.tag === 4) {
2022
+ if (matchValue_46.fields[0] === "in") {
2003
2023
  matchResult_8 = 0;
2004
2024
  }
2005
2025
  else {
@@ -2054,11 +2074,11 @@ export function parseProgramWithSourceName(sourceName, src) {
2054
2074
  let doneBlock = false;
2055
2075
  let blockStatementColumn = undefined;
2056
2076
  while (!doneBlock) {
2057
- let col, matchValue_49;
2077
+ let col, matchValue_50;
2058
2078
  TokenStream__SkipNewlines(stream);
2059
- const matchValue_47 = TokenStream__Peek(stream).Kind;
2079
+ const matchValue_48 = TokenStream__Peek(stream).Kind;
2060
2080
  let matchResult_9;
2061
- switch (matchValue_47.tag) {
2081
+ switch (matchValue_48.tag) {
2062
2082
  case 3: {
2063
2083
  matchResult_9 = 0;
2064
2084
  break;
@@ -2110,27 +2130,27 @@ export function parseProgramWithSourceName(sourceName, src) {
2110
2130
  case 0: {
2111
2131
  TokenStream__Next(stream);
2112
2132
  TokenStream__SkipNewlines(stream);
2113
- const findNextNonLayout = (offset_mut) => {
2133
+ const findNextNonLayout = (offset_1_mut) => {
2114
2134
  findNextNonLayout:
2115
2135
  while (true) {
2116
- const offset = offset_mut;
2117
- const matchValue_48 = TokenStream__PeekAt_Z524259A4(stream, offset).Kind;
2118
- switch (matchValue_48.tag) {
2136
+ const offset_1 = offset_1_mut;
2137
+ const matchValue_49 = TokenStream__PeekAt_Z524259A4(stream, offset_1).Kind;
2138
+ switch (matchValue_49.tag) {
2119
2139
  case 1:
2120
2140
  case 2:
2121
2141
  case 3: {
2122
- offset_mut = (offset + 1);
2142
+ offset_1_mut = (offset_1 + 1);
2123
2143
  continue findNextNonLayout;
2124
2144
  }
2125
2145
  default:
2126
- return TokenStream__PeekAt_Z524259A4(stream, offset);
2146
+ return TokenStream__PeekAt_Z524259A4(stream, offset_1);
2127
2147
  }
2128
2148
  break;
2129
2149
  }
2130
2150
  };
2131
2151
  const nextSignificant = findNextNonLayout(0);
2132
2152
  TokenStream__Peek(stream);
2133
- 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)))))))))) {
2153
+ if (!((blockStatementColumn == null) ? false : ((col = (blockStatementColumn | 0), (matchValue_50 = nextSignificant.Kind, (matchValue_50.tag === 0) ? false : ((matchValue_50.tag === 3) ? false : ((matchValue_50.tag === 28) ? false : ((matchValue_50.tag === 30) ? false : ((matchValue_50.tag === 44) ? false : (nextSignificant.Span.Start.Column >= col)))))))))) {
2134
2154
  doneBlock = true;
2135
2155
  }
2136
2156
  break;
@@ -2171,7 +2191,7 @@ export function parseProgramWithSourceName(sourceName, src) {
2171
2191
  blockStatementColumn = TokenStream__Peek(stream).Span.Start.Column;
2172
2192
  }
2173
2193
  const expr_6 = parseExpr();
2174
- void (statements.push(new Stmt(/* SExpr */ 5, [expr_6])));
2194
+ void (statements.push(new Stmt(/* SExpr */ 7, [expr_6])));
2175
2195
  break;
2176
2196
  }
2177
2197
  }
@@ -2207,10 +2227,14 @@ export function parseProgramWithSourceName(sourceName, src) {
2207
2227
  const body_7 = desugar(tail_1(stmts));
2208
2228
  return new Expr(/* ELetRecGroup */ 12, [head_1(stmts).fields[0], body_7, mkSpanFrom(head_1(stmts).fields[2], Ast_spanOfExpr(body_7))]);
2209
2229
  }
2230
+ case 5:
2231
+ throw new ParseException(new ParseError("Backend imports are only supported at top level", head_1(stmts).fields[3]));
2210
2232
  case 0:
2211
2233
  throw new ParseException(new ParseError("Type declarations are only supported at top level", head_1(stmts).fields[0].Span));
2212
2234
  case 1:
2213
2235
  throw new ParseException(new ParseError("\'import\' is only supported at top level", head_1(stmts).fields[2]));
2236
+ case 6:
2237
+ throw new ParseException(new ParseError("Attributes are only supported at top level", head_1(stmts).fields[2]));
2214
2238
  default:
2215
2239
  if (isEmpty(tail_1(stmts))) {
2216
2240
  return head_1(stmts).fields[0];
@@ -2228,7 +2252,7 @@ export function parseProgramWithSourceName(sourceName, src) {
2228
2252
  return desugar(toList(statements));
2229
2253
  };
2230
2254
  const parseLetStmt = (isExported) => {
2231
- let matchValue_52;
2255
+ let matchValue_53;
2232
2256
  const letTok_1 = TokenStream__Next(stream);
2233
2257
  const isRec_3 = TokenStream__Match_5CEB78CD(stream, TokenKind.Rec);
2234
2258
  let patternInput_3;
@@ -2238,8 +2262,8 @@ export function parseProgramWithSourceName(sourceName, src) {
2238
2262
  }
2239
2263
  const nameTok_15 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
2240
2264
  let name_18;
2241
- const matchValue_50 = nameTok_15.Kind;
2242
- name_18 = ((matchValue_50.tag === 4) ? matchValue_50.fields[0] : "");
2265
+ const matchValue_51 = nameTok_15.Kind;
2266
+ name_18 = ((matchValue_51.tag === 4) ? matchValue_51.fields[0] : "");
2243
2267
  const args_4 = parseParamsAligned();
2244
2268
  if (args_4.length === 0) {
2245
2269
  throw new ParseException(new ParseError("\'let rec\' requires at least one function argument", nameTok_15.Span));
@@ -2262,7 +2286,7 @@ export function parseProgramWithSourceName(sourceName, src) {
2262
2286
  }
2263
2287
  else {
2264
2288
  const nameTok_16 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'let\'");
2265
- patternInput_3 = [(matchValue_52 = nameTok_16.Kind, (matchValue_52.tag === 4) ? matchValue_52.fields[0] : ""), parseParamsAligned(), undefined, nameTok_16.Span];
2289
+ patternInput_3 = [(matchValue_53 = nameTok_16.Kind, (matchValue_53.tag === 4) ? matchValue_53.fields[0] : ""), parseParamsAligned(), undefined, nameTok_16.Span];
2266
2290
  }
2267
2291
  const tuplePatternOpt_1 = patternInput_3[2];
2268
2292
  const bindingName_1 = patternInput_3[0];
@@ -2293,8 +2317,8 @@ export function parseProgramWithSourceName(sourceName, src) {
2293
2317
  if (TokenStream__Match_5CEB78CD(stream, TokenKind.And)) {
2294
2318
  const nextNameTok_1 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected identifier after \'and\'");
2295
2319
  let nextName_1;
2296
- const matchValue_53 = nextNameTok_1.Kind;
2297
- nextName_1 = ((matchValue_53.tag === 4) ? matchValue_53.fields[0] : "");
2320
+ const matchValue_54 = nextNameTok_1.Kind;
2321
+ nextName_1 = ((matchValue_54.tag === 4) ? matchValue_54.fields[0] : "");
2298
2322
  const nextArgs_1 = parseParamsAligned();
2299
2323
  if (nextArgs_1.length === 0) {
2300
2324
  throw new ParseException(new ParseError("\'let rec ... and ...\' requires function arguments for each binding", nextNameTok_1.Span));
@@ -2333,86 +2357,177 @@ export function parseProgramWithSourceName(sourceName, src) {
2333
2357
  return new Stmt(/* SLetPattern */ 3, [pattern_10, value_79, isExported, mkSpanFrom(letTok_1.Span, Ast_spanOfExpr(value_79))]);
2334
2358
  }
2335
2359
  };
2336
- const parseStmt = () => {
2337
- let matchValue_57;
2338
- TokenStream__SkipNewlines(stream);
2339
- const matchValue_54 = TokenStream__Peek(stream).Kind;
2340
- let matchResult_10;
2341
- switch (matchValue_54.tag) {
2342
- case 4: {
2343
- if (matchValue_54.fields[0] === "export") {
2344
- if (equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, TokenKind.Let)) {
2360
+ const parseAttribute = () => {
2361
+ TokenStream__Expect_77B9EE56(stream, TokenKind.LBracket, "Expected \'[\' in attribute");
2362
+ TokenStream__Expect_77B9EE56(stream, TokenKind.Less, "Expected \'<\' in attribute");
2363
+ const nameTok_17 = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected attribute name");
2364
+ let name_20;
2365
+ const matchValue_55 = nameTok_17.Kind;
2366
+ name_20 = ((matchValue_55.tag === 4) ? matchValue_55.fields[0] : "");
2367
+ const arguments$ = [];
2368
+ if (TokenStream__Match_5CEB78CD(stream, TokenKind.LParen)) {
2369
+ let doneArguments = false;
2370
+ while (!doneArguments) {
2371
+ const argument = TokenStream__Next(stream);
2372
+ const matchValue_56 = argument.Kind;
2373
+ let matchResult_10, value_83;
2374
+ switch (matchValue_56.tag) {
2375
+ case 7: {
2345
2376
  matchResult_10 = 0;
2377
+ value_83 = matchValue_56.fields[0];
2378
+ break;
2346
2379
  }
2347
- else {
2348
- matchResult_10 = 7;
2380
+ case 4: {
2381
+ matchResult_10 = 0;
2382
+ value_83 = matchValue_56.fields[0];
2383
+ break;
2384
+ }
2385
+ default:
2386
+ matchResult_10 = 1;
2387
+ }
2388
+ switch (matchResult_10) {
2389
+ case 0: {
2390
+ void (arguments$.push(value_83));
2391
+ break;
2392
+ }
2393
+ case 1: {
2394
+ throw new ParseException(new ParseError("Attribute arguments must be strings or identifiers", argument.Span));
2395
+ break;
2349
2396
  }
2350
2397
  }
2398
+ if (TokenStream__Match_5CEB78CD(stream, TokenKind.Comma)) {
2399
+ }
2351
2400
  else {
2352
- matchResult_10 = 7;
2401
+ TokenStream__Expect_77B9EE56(stream, TokenKind.RParen, "Expected \')\' after attribute arguments");
2402
+ doneArguments = true;
2353
2403
  }
2354
- break;
2355
2404
  }
2356
- case 29: {
2357
- if (equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, TokenKind.Less)) {
2358
- matchResult_10 = 1;
2405
+ }
2406
+ TokenStream__Expect_77B9EE56(stream, TokenKind.Greater, "Expected \'>\' in attribute");
2407
+ TokenStream__Expect_77B9EE56(stream, TokenKind.RBracket, "Expected \']\' in attribute");
2408
+ return new Attribute(name_20, toList(arguments$), nameTok_17.Span);
2409
+ };
2410
+ const parseBackendImport = (attribute_1) => {
2411
+ const letToken = TokenStream__Expect_77B9EE56(stream, TokenKind.Let, "Expected \'let\' after Import attribute");
2412
+ const nameToken = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected imported binding name");
2413
+ let name_21;
2414
+ const matchValue_57 = nameToken.Kind;
2415
+ name_21 = ((matchValue_57.tag === 4) ? matchValue_57.fields[0] : "");
2416
+ TokenStream__Expect_77B9EE56(stream, TokenKind.Colon, "Imported binding requires a complete type signature");
2417
+ const signature = parseTypeRef();
2418
+ if (equals(TokenStream__Peek(stream).Kind, TokenKind.Equals)) {
2419
+ throw new ParseException(new ParseError("Imported bindings must not have a body", TokenStream__Peek(stream).Span));
2420
+ }
2421
+ const matchValue_58 = attribute_1.Arguments;
2422
+ let matchResult_11, memberName_3, modulePath_3;
2423
+ if (!isEmpty(matchValue_58)) {
2424
+ if (!isEmpty(tail_1(matchValue_58))) {
2425
+ if (isEmpty(tail_1(tail_1(matchValue_58)))) {
2426
+ if (!isNullOrWhiteSpace(head_1(matchValue_58)) && !isNullOrWhiteSpace(head_1(tail_1(matchValue_58)))) {
2427
+ matchResult_11 = 0;
2428
+ memberName_3 = head_1(tail_1(matchValue_58));
2429
+ modulePath_3 = head_1(matchValue_58);
2430
+ }
2431
+ else {
2432
+ matchResult_11 = 1;
2433
+ }
2359
2434
  }
2360
2435
  else {
2361
- matchResult_10 = 7;
2436
+ matchResult_11 = 1;
2362
2437
  }
2363
- break;
2364
- }
2365
- case 38: {
2366
- matchResult_10 = 2;
2367
- break;
2368
- }
2369
- case 39: {
2370
- matchResult_10 = 3;
2371
- break;
2372
- }
2373
- case 42: {
2374
- matchResult_10 = 4;
2375
- break;
2376
2438
  }
2377
- case 45: {
2378
- matchResult_10 = 5;
2379
- break;
2380
- }
2381
- case 10: {
2382
- matchResult_10 = 6;
2383
- break;
2439
+ else {
2440
+ matchResult_11 = 1;
2384
2441
  }
2442
+ }
2443
+ else {
2444
+ matchResult_11 = 1;
2445
+ }
2446
+ switch (matchResult_11) {
2447
+ case 0:
2448
+ return new Stmt(/* SBackendImport */ 5, [name_21, signature, new BackendImport(modulePath_3, memberName_3, attribute_1.Span), mkSpanFrom(letToken.Span, nameToken.Span)]);
2385
2449
  default:
2386
- matchResult_10 = 7;
2450
+ throw new ParseException(new ParseError("Import requires module path and member name: [<Import(\"module/path\", \"Member\")>]", attribute_1.Span));
2387
2451
  }
2388
- switch (matchResult_10) {
2389
- case 0: {
2390
- TokenStream__Next(stream);
2391
- return parseLetStmt(true);
2452
+ };
2453
+ const parseStmt = () => {
2454
+ TokenStream__SkipNewlines(stream);
2455
+ if (equals(TokenStream__Peek(stream).Kind, new TokenKind(/* Ident */ 4, ["export"])) && equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, TokenKind.Let)) {
2456
+ TokenStream__Next(stream);
2457
+ return parseLetStmt(true);
2458
+ }
2459
+ else {
2460
+ return parseAttributedStmt();
2461
+ }
2462
+ };
2463
+ const parseAttributedStmt = () => {
2464
+ let matchValue_63;
2465
+ let hasAttributes = false;
2466
+ let backendImport_1 = undefined;
2467
+ const structuredAttributes = [];
2468
+ let parsingAttributes = true;
2469
+ while (parsingAttributes) {
2470
+ if (equals(TokenStream__Peek(stream).Kind, TokenKind.LBracket) && equals(TokenStream__PeekAt_Z524259A4(stream, 1).Kind, TokenKind.Less)) {
2471
+ hasAttributes = true;
2472
+ const attribute_2 = parseAttribute();
2473
+ const matchValue_59 = attribute_2.Name;
2474
+ switch (matchValue_59) {
2475
+ case "export":
2476
+ case "Export": {
2477
+ throw new ParseException(new ParseError("Unexpected attribute", attribute_2.Span));
2478
+ break;
2479
+ }
2480
+ case "Import": {
2481
+ if (backendImport_1 != null) {
2482
+ throw new ParseException(new ParseError("Duplicate attribute \'Import\'", attribute_2.Span));
2483
+ }
2484
+ backendImport_1 = attribute_2;
2485
+ break;
2486
+ }
2487
+ default:
2488
+ void (structuredAttributes.push(attribute_2));
2489
+ }
2490
+ TokenStream__SkipNewlines(stream);
2392
2491
  }
2393
- case 1:
2394
- throw new ParseException(new ParseError("Attributes are not supported in scripts; use \'export let\' for exported bindings", TokenStream__Peek(stream).Span));
2395
- case 2: {
2492
+ else {
2493
+ parsingAttributes = false;
2494
+ }
2495
+ }
2496
+ let statement;
2497
+ const matchValue_60 = TokenStream__Peek(stream).Kind;
2498
+ switch (matchValue_60.tag) {
2499
+ case 38: {
2500
+ if (hasAttributes) {
2501
+ throw new ParseException(new ParseError("Attributes are not supported on \'import\' directives", TokenStream__Peek(stream).Span));
2502
+ }
2396
2503
  const hashTok = TokenStream__Next(stream);
2397
- const matchValue_55 = TokenStream__Next(stream).Kind;
2398
- switch (matchValue_55.tag) {
2399
- case 41:
2504
+ const matchValue_61 = TokenStream__Next(stream).Kind;
2505
+ switch (matchValue_61.tag) {
2506
+ case 41: {
2400
2507
  throw new ParseException(new ParseError("\'#include\' was removed in 0.32.0; use \'import \"file.fss\" as Alias\'", hashTok.Span));
2401
- case 39:
2508
+ break;
2509
+ }
2510
+ case 39: {
2402
2511
  throw new ParseException(new ParseError("\'#import\' was removed in 0.32.0; use \'import \"file.fss\" as Alias\'", hashTok.Span));
2512
+ break;
2513
+ }
2403
2514
  default:
2404
2515
  throw new ParseException(new ParseError("Unexpected \'#\'; use \'import \"file.fss\" as Alias\'", hashTok.Span));
2405
2516
  }
2517
+ break;
2406
2518
  }
2407
- case 3: {
2519
+ case 39: {
2520
+ if (hasAttributes) {
2521
+ throw new ParseException(new ParseError("Attributes are not supported on \'import\' directives", TokenStream__Peek(stream).Span));
2522
+ }
2408
2523
  const importTok = TokenStream__Next(stream);
2409
2524
  const pathTok = TokenStream__Next(stream);
2410
- const matchValue_56 = pathTok.Kind;
2411
- if (matchValue_56.tag === 7) {
2412
- if (!isNullOrWhiteSpace(matchValue_56.fields[0])) {
2525
+ const matchValue_62 = pathTok.Kind;
2526
+ if (matchValue_62.tag === 7) {
2527
+ if (!isNullOrWhiteSpace(matchValue_62.fields[0])) {
2413
2528
  TokenStream__Expect_77B9EE56(stream, TokenKind.As, "Expected \'as\' in import directive. Use: import \"file.fss\" as Alias");
2414
2529
  const aliasTok = TokenStream__ExpectIdent_Z721C83C5(stream, "Expected module alias after \'as\'");
2415
- return new Stmt(/* SImport */ 1, [(matchValue_57 = aliasTok.Kind, (matchValue_57.tag === 4) ? matchValue_57.fields[0] : ""), matchValue_56.fields[0], mkSpanFrom(importTok.Span, aliasTok.Span)]);
2530
+ statement = (new Stmt(/* SImport */ 1, [(matchValue_63 = aliasTok.Kind, (matchValue_63.tag === 4) ? matchValue_63.fields[0] : ""), matchValue_62.fields[0], mkSpanFrom(importTok.Span, aliasTok.Span)]));
2416
2531
  }
2417
2532
  else {
2418
2533
  throw new ParseException(new ParseError("Import path cannot be empty", pathTok.Span));
@@ -2421,22 +2536,40 @@ export function parseProgramWithSourceName(sourceName, src) {
2421
2536
  else {
2422
2537
  throw new ParseException(new ParseError("Expected string literal import path after \'import\'", pathTok.Span));
2423
2538
  }
2539
+ break;
2424
2540
  }
2425
- case 4:
2541
+ case 42: {
2426
2542
  throw new ParseException(new ParseError("\'module\' declarations are not supported in scripts", TokenStream__Peek(stream).Span));
2427
- case 5:
2428
- return parseTypeDecl();
2429
- case 6:
2430
- return parseLetStmt(false);
2543
+ break;
2544
+ }
2545
+ case 45: {
2546
+ statement = parseTypeDecl(backendImport_1);
2547
+ break;
2548
+ }
2549
+ case 10: {
2550
+ statement = ((backendImport_1 == null) ? parseLetStmt(false) : parseBackendImport(backendImport_1));
2551
+ break;
2552
+ }
2431
2553
  default:
2432
- return new Stmt(/* SExpr */ 5, [parseExpr()]);
2554
+ if (hasAttributes) {
2555
+ throw new ParseException(new ParseError("Attributes must be followed by a top-level declaration", TokenStream__Peek(stream).Span));
2556
+ }
2557
+ else {
2558
+ statement = (new Stmt(/* SExpr */ 7, [parseExpr()]));
2559
+ }
2560
+ }
2561
+ if (structuredAttributes.length === 0) {
2562
+ return statement;
2563
+ }
2564
+ else {
2565
+ return new Stmt(/* SAttributed */ 6, [toList(structuredAttributes), statement, Ast_spanOfStmt(statement)]);
2433
2566
  }
2434
2567
  };
2435
2568
  const program = [];
2436
2569
  TokenStream__SkipNewlines(stream);
2437
2570
  while (!TokenStream__get_AtEnd(stream)) {
2438
- const matchValue_58 = TokenStream__Peek(stream).Kind;
2439
- switch (matchValue_58.tag) {
2571
+ const matchValue_64 = TokenStream__Peek(stream).Kind;
2572
+ switch (matchValue_64.tag) {
2440
2573
  case 0: {
2441
2574
  TokenStream__Next(stream);
2442
2575
  break;
@@ -2455,6 +2588,10 @@ export function parseProgramWithSourceName(sourceName, src) {
2455
2588
  return toList(program);
2456
2589
  }
2457
2590
 
2591
+ export function parseProgramWithSourceName(sourceName, src) {
2592
+ return parseProgramWithSourceNameAndOrigin(sourceName, 1, 1, src);
2593
+ }
2594
+
2458
2595
  export function parseProgram(src) {
2459
2596
  return parseProgramWithSourceName(undefined, src);
2460
2597
  }