@aster-cloud/aster-lang-ts 0.0.29 → 0.0.31

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.
Files changed (43) hide show
  1. package/dist/scripts/aster.js +0 -0
  2. package/dist/scripts/emit-core.js +0 -0
  3. package/dist/src/cli/policy-converter.js +0 -0
  4. package/dist/src/config/lexicons/en-US.d.ts.map +1 -1
  5. package/dist/src/config/lexicons/en-US.js +2 -0
  6. package/dist/src/config/lexicons/en-US.js.map +1 -1
  7. package/dist/src/config/lexicons/types.d.ts +4 -0
  8. package/dist/src/config/lexicons/types.d.ts.map +1 -1
  9. package/dist/src/config/lexicons/types.js.map +1 -1
  10. package/dist/src/frontend/canonicalizer.d.ts.map +1 -1
  11. package/dist/src/frontend/canonicalizer.js +12 -1
  12. package/dist/src/frontend/canonicalizer.js.map +1 -1
  13. package/dist/src/frontend/keyword-translator.d.ts.map +1 -1
  14. package/dist/src/frontend/keyword-translator.js +50 -14
  15. package/dist/src/frontend/keyword-translator.js.map +1 -1
  16. package/dist/src/frontend/transformers.d.ts +28 -0
  17. package/dist/src/frontend/transformers.d.ts.map +1 -0
  18. package/dist/src/frontend/transformers.js +86 -0
  19. package/dist/src/frontend/transformers.js.map +1 -0
  20. package/dist/src/lsp/server.js +0 -0
  21. package/dist/src/parser/expr-stmt-parser.d.ts.map +1 -1
  22. package/dist/src/parser/expr-stmt-parser.js +23 -20
  23. package/dist/src/parser/expr-stmt-parser.js.map +1 -1
  24. package/dist/src/parser/field-variant-parser.d.ts.map +1 -1
  25. package/dist/src/parser/field-variant-parser.js +3 -4
  26. package/dist/src/parser/field-variant-parser.js.map +1 -1
  27. package/dist/test/integration/lsp/lsp-diagnostics.test.js +3 -3
  28. package/dist/test/integration/lsp/lsp-diagnostics.test.js.map +1 -1
  29. package/dist/test/integration/lsp/lsp-navigation.test.js +6 -6
  30. package/dist/test/integration/pipeline/pipeline.test.js +13 -13
  31. package/dist/test/unit/async/async-discipline.test.js +72 -72
  32. package/dist/test/unit/async/async-schedule.test.js +12 -12
  33. package/dist/test/unit/keyword-translator.test.js +2 -2
  34. package/dist/test/unit/keyword-translator.test.js.map +1 -1
  35. package/dist/test/unit/lowering/lowering.test.js +6 -6
  36. package/dist/test/unit/parser/parser.test.js +81 -63
  37. package/dist/test/unit/parser/parser.test.js.map +1 -1
  38. package/dist/test/unit/provenance-integration.test.js +6 -6
  39. package/dist/test/unit/typecheck/async-discipline-extended.test.js +4 -4
  40. package/dist/test/unit/typecheck/type-inference.test.js +11 -11
  41. package/dist/test/unit/typecheck/typecheck-advanced.test.js +6 -6
  42. package/dist/test/unit/validator.test.js +4 -4
  43. package/package.json +43 -45
@@ -35,7 +35,7 @@ Rule ping, produce Text:
35
35
  const module = parseSource(`
36
36
  Module test.parser.data_decl.
37
37
 
38
- Define User has id: Text, name: Text, age: Int.
38
+ Define User has id as Text, name as Text, age as Int.
39
39
  `);
40
40
  const data = findDecl(module, 'Data');
41
41
  assert.equal(data.fields.length, 3);
@@ -56,7 +56,7 @@ Define Status as one of Pending, Success, Failure.
56
56
  const module = parseSource(`
57
57
  Module test.parser.func_signature.
58
58
 
59
- Rule format given name: Text and times: Int, produce Text:
59
+ Rule format given name as Text and times as Int, produce Text:
60
60
  Return Text.concat(name, Text.toString(times)).
61
61
  `);
62
62
  const func = findDecl(module, 'Func');
@@ -69,7 +69,7 @@ Rule format given name: Text and times: Int, produce Text:
69
69
  const module = parseSource(`
70
70
  Module test.parser.return_stmt.
71
71
 
72
- Rule identity given value: Text, produce Text:
72
+ Rule identity given value as Text, produce Text:
73
73
  Return value.
74
74
  `);
75
75
  const func = findDecl(module, 'Func');
@@ -81,7 +81,7 @@ Rule identity given value: Text, produce Text:
81
81
  const module = parseSource(`
82
82
  Module test.parser.let_stmt.
83
83
 
84
- Rule greet given name: Text, produce Text:
84
+ Rule greet given name as Text, produce Text:
85
85
  Let trimmed be Text.trim(name).
86
86
  Return Text.concat("Hi, ", trimmed).
87
87
  `);
@@ -95,10 +95,10 @@ Rule greet given name: Text, produce Text:
95
95
  const module = parseSource(`
96
96
  Module test.parser.if_stmt.
97
97
 
98
- Rule classify given score: Int, produce Text:
99
- If score at least 800:
98
+ Rule classify given score as Int, produce Text:
99
+ If score at least 800
100
100
  Return "Top".
101
- Otherwise:
101
+ Otherwise
102
102
  Return "Regular".
103
103
  `);
104
104
  const func = findDecl(module, 'Func');
@@ -112,9 +112,9 @@ Rule classify given score: Int, produce Text:
112
112
  const module = parseSource(`
113
113
  Module test.parser.match_stmt.
114
114
 
115
- Define User has id: Text, name: Text.
115
+ Define User has id as Text, name as Text.
116
116
 
117
- Rule welcome given user: User?, produce Text:
117
+ Rule welcome given user as User?, produce Text:
118
118
  Match user:
119
119
  When null, Return "Guest".
120
120
  When User(id, name), Return Text.concat("Hi ", name).
@@ -147,7 +147,7 @@ Rule fetch, produce Text:
147
147
  assert.throws(() => parseSource(`
148
148
  Module test.parser.error.
149
149
 
150
- Define Broken has x: Int
150
+ Define Broken has x as Int
151
151
  `), /expected '.'/i);
152
152
  });
153
153
  describe('边界场景', () => {
@@ -186,7 +186,7 @@ Module test.parser.effects_basic.
186
186
 
187
187
  Rule audit, produce Int. It performs [].
188
188
 
189
- Rule compute given value: Int, produce Int. It performs io and cpu.
189
+ Rule compute given value as Int, produce Int. It performs io and cpu.
190
190
  `);
191
191
  const audit = findFunc(module, 'audit');
192
192
  assert.deepEqual(audit.effects, []);
@@ -223,10 +223,10 @@ Rule fetch, produce Text. It performs io with Http and Sql:
223
223
  Module test.parser.constraints.
224
224
 
225
225
  Define User has
226
- id: Text required,
227
- age: Int between 0 and 120 matching "^[0-9]+$".
226
+ id as Text required,
227
+ age as Int between 0 and 120 matching "^[0-9]+$".
228
228
 
229
- Rule validate given input: Text required, produce Bool:
229
+ Rule validate given input as Text required, produce Bool:
230
230
  Return true.
231
231
  `);
232
232
  const data = findDecl(module, 'Data');
@@ -322,7 +322,7 @@ Rule determineInterestRateBps given creditScore between 300 and 850, produce:
322
322
  assert.throws(() => parseSource(`
323
323
  Module test.parser.error.missing_separator.
324
324
 
325
- Rule broken given first: Int second: Int, produce Int:
325
+ Rule broken given first as Int second as Int, produce Int:
326
326
  Return first.
327
327
  `), error => {
328
328
  assert.match(String(error), /Expected 'produce' and return type/i);
@@ -333,7 +333,7 @@ Rule broken given first: Int second: Int, produce Int:
333
333
  assert.throws(() => parseSource(`
334
334
  Module test.parser.error.parentheses.
335
335
 
336
- Rule fail given value: Text, produce Text:
336
+ Rule fail given value as Text, produce Text:
337
337
  Return (value.
338
338
  `), error => {
339
339
  assert.ok(String(error).includes("Expected ')' after expression"), '诊断信息应该指出括号缺失');
@@ -346,7 +346,7 @@ Rule fail given value: Text, produce Text:
346
346
  const module = parseSource(`
347
347
  Module test.parser.func_type_params.single.
348
348
 
349
- Rule wrap of T given value: T, produce List of T:
349
+ Rule wrap of T given value as T, produce List of T:
350
350
  Return List.build(value).
351
351
  `);
352
352
  const func = findFunc(module, 'wrap');
@@ -368,7 +368,7 @@ Rule wrap of T given value: T, produce List of T:
368
368
  const module = parseSource(`
369
369
  Module test.parser.func_type_params.multi.
370
370
 
371
- Rule pair of Left and Right given left: Left and right: Right, produce Result of Left or Right:
371
+ Rule pair of Left and Right given left as Left and right as Right, produce Result of Left or Right:
372
372
  Return Result.ok(left).
373
373
  `);
374
374
  const func = findFunc(module, 'pair');
@@ -396,7 +396,7 @@ Rule pair of Left and Right given left: Left and right: Right, produce Result of
396
396
  const module = parseSource(`
397
397
  Module test.parser.func_type_params.mixed.
398
398
 
399
- Rule compose of Input, Middle and Output given first: Input, second: Middle, produce Output:
399
+ Rule compose of Input, Middle and Output given first as Input, second as Middle, produce Output:
400
400
  Return second.
401
401
  `);
402
402
  const func = findFunc(module, 'compose');
@@ -413,7 +413,7 @@ Rule compose of Input, Middle and Output given first: Input, second: Middle, pro
413
413
  const module = parseSource(`
414
414
  Module test.parser.func_type_params.complex.
415
415
 
416
- Rule pipeline of Source and Target given items: List of Source, produce Result of Map Source to Target or Text:
416
+ Rule pipeline of Source and Target given items as List of Source, produce Result of Map Source to Target or Text:
417
417
  Return Result.err("empty").
418
418
  `);
419
419
  const func = findFunc(module, 'pipeline');
@@ -449,9 +449,9 @@ Rule pipeline of Source and Target given items: List of Source, produce Result o
449
449
  Module test.parser.params.multiline_with.
450
450
 
451
451
  Rule summarize given
452
- first: Text,
453
- second: Text,
454
- third: Text, produce Text:
452
+ first as Text,
453
+ second as Text,
454
+ third as Text, produce Text:
455
455
  Return Text.concat(first, second).
456
456
  `);
457
457
  const func = findFunc(module, 'summarize');
@@ -463,8 +463,8 @@ Rule summarize given
463
463
  Module test.parser.params.multiline_effect.
464
464
 
465
465
  Rule compute given
466
- value: Int,
467
- factor: Int, produce Int. It performs cpu:
466
+ value as Int,
467
+ factor as Int, produce Int. It performs cpu:
468
468
  Return value times factor.
469
469
  `);
470
470
  const func = findFunc(module, 'compute');
@@ -477,8 +477,8 @@ Rule compute given
477
477
  Module test.parser.params.multiline_constraints.
478
478
 
479
479
  Rule filter given
480
- query: Text required,
481
- limit: Int, produce List of Text:
480
+ query as Text required,
481
+ limit as Int, produce List of Text:
482
482
  Return List.empty().
483
483
  `);
484
484
  const func = findFunc(module, 'filter');
@@ -497,8 +497,8 @@ Rule filter given
497
497
  const module = parseSource(`
498
498
  Module test.parser.let.lambda.basic.
499
499
 
500
- Rule operate given value: Int, produce Int:
501
- Let increment be function with input: Int, produce Int:
500
+ Rule operate given value as Int, produce Int:
501
+ Let increment be function with input as Int, produce Int:
502
502
  Return input plus 1.
503
503
  Return increment(value).
504
504
  `);
@@ -519,7 +519,7 @@ Rule operate given value: Int, produce Int:
519
519
  Module test.parser.let.lambda.article.
520
520
 
521
521
  Rule demo, produce Int:
522
- Let noop be a function with value: Int, produce Int:
522
+ Let noop be a function with value as Int, produce Int:
523
523
  Return value.
524
524
  Return noop(0).
525
525
  `);
@@ -537,7 +537,7 @@ Rule demo, produce Int:
537
537
  Module test.parser.let.lambda.body.
538
538
 
539
539
  Rule compose, produce Int:
540
- Let combine be function with left: Int and right: Int, produce Int:
540
+ Let combine be function with left as Int and right as Int, produce Int:
541
541
  Let sum be left plus right.
542
542
  Return sum.
543
543
  Return combine(1, 2).
@@ -561,7 +561,7 @@ Rule compose, produce Int:
561
561
  const module = parseSource(`
562
562
  Module test.parser.set.basic.
563
563
 
564
- Rule update given value: Int, produce Int:
564
+ Rule update given value as Int, produce Int:
565
565
  Let total be 0.
566
566
  Set total to total plus value.
567
567
  Return total.
@@ -625,6 +625,24 @@ Rule broken, produce Int:
625
625
  return true;
626
626
  });
627
627
  });
628
+ test('Set 语句不应被 canonicalizer 转换为 Let(回归测试)', () => {
629
+ // 确保 set-to transformer 不会将 "Set x to y" 语句错误地转换为 "Let x be y"
630
+ const module = parseSource(`
631
+ Module test.parser.set.not_transformed.
632
+
633
+ Rule accumulate, produce Int:
634
+ Let sum be 0.
635
+ Set sum to sum plus 1.
636
+ Set sum to sum plus 2.
637
+ Return sum.
638
+ `);
639
+ const func = findFunc(module, 'accumulate');
640
+ const statements = func.body?.statements ?? [];
641
+ const setStmts = statements.filter(stmt => stmt.kind === 'Set');
642
+ assert.equal(setStmts.length, 2, '应保留 2 个 Set 语句,不被转换为 Let');
643
+ const letStmts = statements.filter(stmt => stmt.kind === 'Let');
644
+ assert.equal(letStmts.length, 1, '应只有 1 个原始 Let 语句');
645
+ });
628
646
  });
629
647
  describe('Return 效果采集', () => {
630
648
  test('应该收集 Return 语句后的效果说明', () => {
@@ -672,10 +690,10 @@ Rule compute, produce Int. It performs cpu:
672
690
  const module = parseSource(`
673
691
  Module test.parser.if.not.basic.
674
692
 
675
- Rule guard given flag: Bool, produce Text:
676
- If not flag:
693
+ Rule guard given flag as Bool, produce Text:
694
+ If not flag
677
695
  Return "blocked".
678
- Otherwise:
696
+ Otherwise
679
697
  Return "ok".
680
698
  `);
681
699
  const func = findFunc(module, 'guard');
@@ -698,10 +716,10 @@ Rule guard given flag: Bool, produce Text:
698
716
  const module = parseSource(`
699
717
  Module test.parser.if.not.complex.
700
718
 
701
- Rule score given value: Int, produce Text:
702
- If not (value at least 600):
719
+ Rule score given value as Int, produce Text:
720
+ If not (value at least 600)
703
721
  Return "retry".
704
- Otherwise:
722
+ Otherwise
705
723
  Return "pass".
706
724
  `);
707
725
  const func = findFunc(module, 'score');
@@ -727,7 +745,7 @@ Rule score given value: Int, produce Text:
727
745
  const module = parseSource(`
728
746
  Module test.parser.types.maybe.
729
747
 
730
- Rule handle given token: Text?, produce Bool:
748
+ Rule handle given token as Text?, produce Bool:
731
749
  Return true.
732
750
  `);
733
751
  const func = findFunc(module, 'handle');
@@ -746,7 +764,7 @@ Rule handle given token: Text?, produce Bool:
746
764
  const module = parseSource(`
747
765
  Module test.parser.types.option.
748
766
 
749
- Rule parse given payload: Option of Text?, produce Bool:
767
+ Rule parse given payload as Option of Text?, produce Bool:
750
768
  Return true.
751
769
  `);
752
770
  const func = findFunc(module, 'parse');
@@ -769,7 +787,7 @@ Rule parse given payload: Option of Text?, produce Bool:
769
787
  const module = parseSource(`
770
788
  Module test.parser.types.result.
771
789
 
772
- Rule convert given input: Result of Int or Text, produce Int:
790
+ Rule convert given input as Result of Int or Text, produce Int:
773
791
  Return 0.
774
792
  `);
775
793
  const func = findFunc(module, 'convert');
@@ -790,7 +808,7 @@ Rule convert given input: Result of Int or Text, produce Int:
790
808
  const module = parseSource(`
791
809
  Module test.parser.types.list_map.
792
810
 
793
- Rule collect given rows: List of Map Text to Int, produce Int:
811
+ Rule collect given rows as List of Map Text to Int, produce Int:
794
812
  Return 0.
795
813
  `);
796
814
  const func = findFunc(module, 'collect');
@@ -815,7 +833,7 @@ Rule collect given rows: List of Map Text to Int, produce Int:
815
833
  const module = parseSource(`
816
834
  Module test.parser.types.type_app_single.
817
835
 
818
- Rule adapt given response: Text, produce Promise of Text:
836
+ Rule adapt given response as Text, produce Promise of Text:
819
837
  Return Promise.success(response).
820
838
  `);
821
839
  const func = findFunc(module, 'adapt');
@@ -832,7 +850,7 @@ Rule adapt given response: Text, produce Promise of Text:
832
850
  const module = parseSource(`
833
851
  Module test.parser.types.list_nested.
834
852
 
835
- Rule flatten given input: List of List of Int, produce List of Int:
853
+ Rule flatten given input as List of List of Int, produce List of Int:
836
854
  Return input.
837
855
  `);
838
856
  const func = findFunc(module, 'flatten');
@@ -855,7 +873,7 @@ Rule flatten given input: List of List of Int, produce List of Int:
855
873
  const module = parseSource(`
856
874
  Module test.parser.types.pii.
857
875
 
858
- Rule secure given field: @pii(L2, email) Text, produce Text:
876
+ Rule secure given field as @pii(L2, email) Text, produce Text:
859
877
  Return field.
860
878
  `);
861
879
  const func = findFunc(module, 'secure');
@@ -876,7 +894,7 @@ Rule secure given field: @pii(L2, email) Text, produce Text:
876
894
  const module = parseSource(`
877
895
  Module test.parser.types.map_result.
878
896
 
879
- Rule inspect given entry: Map Text to Result of Int or Text, produce Bool:
897
+ Rule inspect given entry as Map Text to Result of Int or Text, produce Bool:
880
898
  Return true.
881
899
  `);
882
900
  const func = findFunc(module, 'inspect');
@@ -901,7 +919,7 @@ Rule inspect given entry: Map Text to Result of Int or Text, produce Bool:
901
919
  const module = parseSource(`
902
920
  Module test.parser.types.result_option.
903
921
 
904
- Rule decide given payload: Result of Option of Text or List of Text, produce Bool:
922
+ Rule decide given payload as Result of Option of Text or List of Text, produce Bool:
905
923
  Return true.
906
924
  `);
907
925
  const func = findFunc(module, 'decide');
@@ -930,7 +948,7 @@ Rule decide given payload: Result of Option of Text or List of Text, produce Boo
930
948
  const module = parseSource(`
931
949
  Module test.parser.types.type_app_multi.
932
950
 
933
- Rule choose given picker: Text, produce Either of Text and Int:
951
+ Rule choose given picker as Text, produce Either of Text and Int:
934
952
  Return Either.left(picker).
935
953
  `);
936
954
  const func = findFunc(module, 'choose');
@@ -951,10 +969,10 @@ Rule choose given picker: Text, produce Either of Text and Int:
951
969
  const module = parseSource(`
952
970
  Module test.parser.type_scope.explicit.
953
971
 
954
- Rule first of T given value: T, produce T:
972
+ Rule first of T given value as T, produce T:
955
973
  Return value.
956
974
 
957
- Rule second given value: T, produce T:
975
+ Rule second given value as T, produce T:
958
976
  Return value.
959
977
  `);
960
978
  const firstFunc = findFunc(module, 'first');
@@ -973,9 +991,9 @@ Rule second given value: T, produce T:
973
991
  const module = parseSource(`
974
992
  Module test.parser.type_scope.declared.
975
993
 
976
- Define User has id: Text.
994
+ Define User has id as Text.
977
995
 
978
- Rule fetch given id: User, produce User:
996
+ Rule fetch given id as User, produce User:
979
997
  Return User.new(id).
980
998
  `);
981
999
  const func = findFunc(module, 'fetch');
@@ -992,10 +1010,10 @@ Rule fetch given id: User, produce User:
992
1010
  const module = parseSource(`
993
1011
  Module test.parser.type_scope.independent.
994
1012
 
995
- Rule box given value: Alpha, produce Alpha:
1013
+ Rule box given value as Alpha, produce Alpha:
996
1014
  Return value.
997
1015
 
998
- Rule unwrap given value: Beta, produce Beta:
1016
+ Rule unwrap given value as Beta, produce Beta:
999
1017
  Return value.
1000
1018
  `);
1001
1019
  const box = findFunc(module, 'box');
@@ -1129,7 +1147,7 @@ Rule log, produce Text:
1129
1147
  const module = parseSource(`
1130
1148
  Module test.parser.misc.match_name.
1131
1149
 
1132
- Rule unwrap given option: Option of Text, produce Text:
1150
+ Rule unwrap given option as Option of Text, produce Text:
1133
1151
  Match option:
1134
1152
  When value, Return value.
1135
1153
  When null, Return "none".
@@ -1175,7 +1193,7 @@ Rule spawn, produce Text:
1175
1193
  const source = `
1176
1194
  Module test.parser.lexicon.en.
1177
1195
 
1178
- Rule greet given name: Text, produce Text:
1196
+ Rule greet given name as Text, produce Text:
1179
1197
  Return Text.concat("Hello, ", name).
1180
1198
  `;
1181
1199
  const canonical = canonicalize(source, EN_US);
@@ -1190,7 +1208,7 @@ Rule greet given name: Text, produce Text:
1190
1208
  const zhSource = `
1191
1209
  模块 测试。
1192
1210
 
1193
- 规则 identity 包含 value:整数,产出:
1211
+ 规则 identity 包含 value 作为 整数,产出:
1194
1212
  返回 value。
1195
1213
  `;
1196
1214
  const canonical = canonicalize(zhSource, ZH_CN);
@@ -1207,7 +1225,7 @@ Rule greet given name: Text, produce Text:
1207
1225
  const zhSource = `
1208
1226
  模块 测试。
1209
1227
 
1210
- 定义 User 包含 age:整数。
1228
+ 定义 User 包含 age 作为 整数。
1211
1229
  `;
1212
1230
  const canonical = canonicalize(zhSource, ZH_CN);
1213
1231
  const tokens = lex(canonical, ZH_CN);
@@ -1225,10 +1243,10 @@ Rule greet given name: Text, produce Text:
1225
1243
  const zhSource = `
1226
1244
  模块 测试。
1227
1245
 
1228
- 规则 check 包含 x:整数,产出:
1229
- 如果 x 大于 0
1246
+ 规则 check 包含 x 作为 整数,产出:
1247
+ 如果 x 大于 0
1230
1248
  返回 1。
1231
- 否则:
1249
+ 否则
1232
1250
  返回 0。
1233
1251
  `;
1234
1252
  const canonical = canonicalize(zhSource, ZH_CN);
@@ -1247,7 +1265,7 @@ Rule greet given name: Text, produce Text:
1247
1265
  const zhSource = `
1248
1266
  模块 测试。
1249
1267
 
1250
- 规则 describe 包含 status:整数,产出:
1268
+ 规则 describe 包含 status 作为 整数,产出:
1251
1269
  若 status:
1252
1270
  为 1,返回 「成功」。
1253
1271
  为 0,返回 「失败」。
@@ -1268,7 +1286,7 @@ Rule greet given name: Text, produce Text:
1268
1286
  const zhSource = `
1269
1287
  模块 测试。
1270
1288
 
1271
- 规则 calc 包含 x:整数,产出:
1289
+ 规则 calc 包含 x 作为 整数,产出:
1272
1290
  令 result 为 x 加 1。
1273
1291
  返回 result。
1274
1292
  `;