@malloydata/malloy 0.0.362 → 0.0.363

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 (45) hide show
  1. package/dist/api/core.js +21 -3
  2. package/dist/api/foundation/compile.js +20 -0
  3. package/dist/api/foundation/runtime.d.ts +16 -4
  4. package/dist/api/foundation/runtime.js +22 -4
  5. package/dist/api/foundation/types.d.ts +3 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/lang/ast/index.d.ts +5 -0
  8. package/dist/lang/ast/index.js +5 -0
  9. package/dist/lang/ast/source-elements/named-source.js +4 -0
  10. package/dist/lang/ast/source-elements/typed-source.d.ts +23 -0
  11. package/dist/lang/ast/source-elements/typed-source.js +133 -0
  12. package/dist/lang/ast/source-elements/virtual-source.d.ts +10 -0
  13. package/dist/lang/ast/source-elements/virtual-source.js +47 -0
  14. package/dist/lang/ast/source-properties/user-type-shape.d.ts +29 -0
  15. package/dist/lang/ast/source-properties/user-type-shape.js +100 -0
  16. package/dist/lang/ast/source-query-elements/sq-reference.js +1 -1
  17. package/dist/lang/ast/source-query-elements/sq-typed-source.d.ts +18 -0
  18. package/dist/lang/ast/source-query-elements/sq-typed-source.js +39 -0
  19. package/dist/lang/ast/statements/define-user-type.d.ts +28 -0
  20. package/dist/lang/ast/statements/define-user-type.js +82 -0
  21. package/dist/lang/ast/types/malloy-element.js +14 -6
  22. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +146 -144
  23. package/dist/lang/lib/Malloy/MalloyLexer.js +1408 -1391
  24. package/dist/lang/lib/Malloy/MalloyParser.d.ts +491 -307
  25. package/dist/lang/lib/Malloy/MalloyParser.js +7907 -6680
  26. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +186 -0
  27. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +117 -0
  28. package/dist/lang/malloy-to-ast.d.ts +17 -0
  29. package/dist/lang/malloy-to-ast.js +118 -0
  30. package/dist/lang/parse-log.d.ts +12 -1
  31. package/dist/lang/parse-malloy.d.ts +6 -1
  32. package/dist/lang/parse-malloy.js +17 -1
  33. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +4 -0
  34. package/dist/lang/parse-tree-walkers/find-external-references.js +10 -0
  35. package/dist/lang/test/test-translator.d.ts +2 -1
  36. package/dist/lang/test/test-translator.js +10 -0
  37. package/dist/lang/translate-response.d.ts +6 -1
  38. package/dist/lang/translate-response.js +3 -1
  39. package/dist/model/malloy_types.d.ts +23 -2
  40. package/dist/model/malloy_types.js +12 -2
  41. package/dist/model/query_model_impl.js +3 -0
  42. package/dist/model/query_query.js +11 -3
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +1 -1
  45. package/package.json +4 -4
@@ -74,6 +74,9 @@ import { DefExploreAnnotationContext } from "./MalloyParser";
74
74
  import { DefIgnoreModel_stubContext } from "./MalloyParser";
75
75
  import { JoinWithContext } from "./MalloyParser";
76
76
  import { JoinOnContext } from "./MalloyParser";
77
+ import { UserTypeRefContext } from "./MalloyParser";
78
+ import { UserTypeInlineContext } from "./MalloyParser";
79
+ import { UserTypeExtendContext } from "./MalloyParser";
77
80
  import { SQIDContext } from "./MalloyParser";
78
81
  import { SQParensContext } from "./MalloyParser";
79
82
  import { SQComposeContext } from "./MalloyParser";
@@ -81,11 +84,21 @@ import { SQRefinedQueryContext } from "./MalloyParser";
81
84
  import { SQArrowContext } from "./MalloyParser";
82
85
  import { SQExtendedSourceContext } from "./MalloyParser";
83
86
  import { SQIncludeContext } from "./MalloyParser";
87
+ import { SQTypedSourceContext } from "./MalloyParser";
84
88
  import { SQTableContext } from "./MalloyParser";
89
+ import { SQVirtualContext } from "./MalloyParser";
85
90
  import { SQSQLContext } from "./MalloyParser";
86
91
  import { MalloyDocumentContext } from "./MalloyParser";
87
92
  import { MalloyStatementContext } from "./MalloyParser";
88
93
  import { DefineSourceStatementContext } from "./MalloyParser";
94
+ import { DefineUserTypeStatementContext } from "./MalloyParser";
95
+ import { UserTypePropertyListContext } from "./MalloyParser";
96
+ import { UserTypeDefinitionContext } from "./MalloyParser";
97
+ import { UserTypeNameDefContext } from "./MalloyParser";
98
+ import { UserTypeExprContext } from "./MalloyParser";
99
+ import { UserTypeShapeContext } from "./MalloyParser";
100
+ import { UserTypeFieldContext } from "./MalloyParser";
101
+ import { UserTypeFieldTypeContext } from "./MalloyParser";
89
102
  import { DefineQueryContext } from "./MalloyParser";
90
103
  import { TopLevelAnonQueryDefContext } from "./MalloyParser";
91
104
  import { AnnotationContext } from "./MalloyParser";
@@ -110,6 +123,7 @@ import { RefineOperatorContext } from "./MalloyParser";
110
123
  import { TurtleNameContext } from "./MalloyParser";
111
124
  import { SqlSourceContext } from "./MalloyParser";
112
125
  import { ExploreTableContext } from "./MalloyParser";
126
+ import { VirtualSourceContext } from "./MalloyParser";
113
127
  import { ConnectionIdContext } from "./MalloyParser";
114
128
  import { QueryPropertiesContext } from "./MalloyParser";
115
129
  import { QueryNameContext } from "./MalloyParser";
@@ -141,6 +155,8 @@ import { SourceArgumentsContext } from "./MalloyParser";
141
155
  import { ArgumentIdContext } from "./MalloyParser";
142
156
  import { SourceArgumentContext } from "./MalloyParser";
143
157
  import { SqExprContext } from "./MalloyParser";
158
+ import { SourceTypeConstraintsContext } from "./MalloyParser";
159
+ import { UserTypeNameContext } from "./MalloyParser";
144
160
  import { IncludeBlockContext } from "./MalloyParser";
145
161
  import { IncludeItemContext } from "./MalloyParser";
146
162
  import { OrphanedAnnotationContext } from "./MalloyParser";
@@ -1154,6 +1170,42 @@ export interface MalloyParserListener extends ParseTreeListener {
1154
1170
  * @param ctx the parse tree
1155
1171
  */
1156
1172
  exitJoinOn?: (ctx: JoinOnContext) => void;
1173
+ /**
1174
+ * Enter a parse tree produced by the `userTypeRef`
1175
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1176
+ * @param ctx the parse tree
1177
+ */
1178
+ enterUserTypeRef?: (ctx: UserTypeRefContext) => void;
1179
+ /**
1180
+ * Exit a parse tree produced by the `userTypeRef`
1181
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1182
+ * @param ctx the parse tree
1183
+ */
1184
+ exitUserTypeRef?: (ctx: UserTypeRefContext) => void;
1185
+ /**
1186
+ * Enter a parse tree produced by the `userTypeInline`
1187
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1188
+ * @param ctx the parse tree
1189
+ */
1190
+ enterUserTypeInline?: (ctx: UserTypeInlineContext) => void;
1191
+ /**
1192
+ * Exit a parse tree produced by the `userTypeInline`
1193
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1194
+ * @param ctx the parse tree
1195
+ */
1196
+ exitUserTypeInline?: (ctx: UserTypeInlineContext) => void;
1197
+ /**
1198
+ * Enter a parse tree produced by the `userTypeExtend`
1199
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1200
+ * @param ctx the parse tree
1201
+ */
1202
+ enterUserTypeExtend?: (ctx: UserTypeExtendContext) => void;
1203
+ /**
1204
+ * Exit a parse tree produced by the `userTypeExtend`
1205
+ * labeled alternative in `MalloyParser.userTypeExpr`.
1206
+ * @param ctx the parse tree
1207
+ */
1208
+ exitUserTypeExtend?: (ctx: UserTypeExtendContext) => void;
1157
1209
  /**
1158
1210
  * Enter a parse tree produced by the `SQID`
1159
1211
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -1238,6 +1290,18 @@ export interface MalloyParserListener extends ParseTreeListener {
1238
1290
  * @param ctx the parse tree
1239
1291
  */
1240
1292
  exitSQInclude?: (ctx: SQIncludeContext) => void;
1293
+ /**
1294
+ * Enter a parse tree produced by the `SQTypedSource`
1295
+ * labeled alternative in `MalloyParser.sqExpr`.
1296
+ * @param ctx the parse tree
1297
+ */
1298
+ enterSQTypedSource?: (ctx: SQTypedSourceContext) => void;
1299
+ /**
1300
+ * Exit a parse tree produced by the `SQTypedSource`
1301
+ * labeled alternative in `MalloyParser.sqExpr`.
1302
+ * @param ctx the parse tree
1303
+ */
1304
+ exitSQTypedSource?: (ctx: SQTypedSourceContext) => void;
1241
1305
  /**
1242
1306
  * Enter a parse tree produced by the `SQTable`
1243
1307
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -1250,6 +1314,18 @@ export interface MalloyParserListener extends ParseTreeListener {
1250
1314
  * @param ctx the parse tree
1251
1315
  */
1252
1316
  exitSQTable?: (ctx: SQTableContext) => void;
1317
+ /**
1318
+ * Enter a parse tree produced by the `SQVirtual`
1319
+ * labeled alternative in `MalloyParser.sqExpr`.
1320
+ * @param ctx the parse tree
1321
+ */
1322
+ enterSQVirtual?: (ctx: SQVirtualContext) => void;
1323
+ /**
1324
+ * Exit a parse tree produced by the `SQVirtual`
1325
+ * labeled alternative in `MalloyParser.sqExpr`.
1326
+ * @param ctx the parse tree
1327
+ */
1328
+ exitSQVirtual?: (ctx: SQVirtualContext) => void;
1253
1329
  /**
1254
1330
  * Enter a parse tree produced by the `SQSQL`
1255
1331
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -1292,6 +1368,86 @@ export interface MalloyParserListener extends ParseTreeListener {
1292
1368
  * @param ctx the parse tree
1293
1369
  */
1294
1370
  exitDefineSourceStatement?: (ctx: DefineSourceStatementContext) => void;
1371
+ /**
1372
+ * Enter a parse tree produced by `MalloyParser.defineUserTypeStatement`.
1373
+ * @param ctx the parse tree
1374
+ */
1375
+ enterDefineUserTypeStatement?: (ctx: DefineUserTypeStatementContext) => void;
1376
+ /**
1377
+ * Exit a parse tree produced by `MalloyParser.defineUserTypeStatement`.
1378
+ * @param ctx the parse tree
1379
+ */
1380
+ exitDefineUserTypeStatement?: (ctx: DefineUserTypeStatementContext) => void;
1381
+ /**
1382
+ * Enter a parse tree produced by `MalloyParser.userTypePropertyList`.
1383
+ * @param ctx the parse tree
1384
+ */
1385
+ enterUserTypePropertyList?: (ctx: UserTypePropertyListContext) => void;
1386
+ /**
1387
+ * Exit a parse tree produced by `MalloyParser.userTypePropertyList`.
1388
+ * @param ctx the parse tree
1389
+ */
1390
+ exitUserTypePropertyList?: (ctx: UserTypePropertyListContext) => void;
1391
+ /**
1392
+ * Enter a parse tree produced by `MalloyParser.userTypeDefinition`.
1393
+ * @param ctx the parse tree
1394
+ */
1395
+ enterUserTypeDefinition?: (ctx: UserTypeDefinitionContext) => void;
1396
+ /**
1397
+ * Exit a parse tree produced by `MalloyParser.userTypeDefinition`.
1398
+ * @param ctx the parse tree
1399
+ */
1400
+ exitUserTypeDefinition?: (ctx: UserTypeDefinitionContext) => void;
1401
+ /**
1402
+ * Enter a parse tree produced by `MalloyParser.userTypeNameDef`.
1403
+ * @param ctx the parse tree
1404
+ */
1405
+ enterUserTypeNameDef?: (ctx: UserTypeNameDefContext) => void;
1406
+ /**
1407
+ * Exit a parse tree produced by `MalloyParser.userTypeNameDef`.
1408
+ * @param ctx the parse tree
1409
+ */
1410
+ exitUserTypeNameDef?: (ctx: UserTypeNameDefContext) => void;
1411
+ /**
1412
+ * Enter a parse tree produced by `MalloyParser.userTypeExpr`.
1413
+ * @param ctx the parse tree
1414
+ */
1415
+ enterUserTypeExpr?: (ctx: UserTypeExprContext) => void;
1416
+ /**
1417
+ * Exit a parse tree produced by `MalloyParser.userTypeExpr`.
1418
+ * @param ctx the parse tree
1419
+ */
1420
+ exitUserTypeExpr?: (ctx: UserTypeExprContext) => void;
1421
+ /**
1422
+ * Enter a parse tree produced by `MalloyParser.userTypeShape`.
1423
+ * @param ctx the parse tree
1424
+ */
1425
+ enterUserTypeShape?: (ctx: UserTypeShapeContext) => void;
1426
+ /**
1427
+ * Exit a parse tree produced by `MalloyParser.userTypeShape`.
1428
+ * @param ctx the parse tree
1429
+ */
1430
+ exitUserTypeShape?: (ctx: UserTypeShapeContext) => void;
1431
+ /**
1432
+ * Enter a parse tree produced by `MalloyParser.userTypeField`.
1433
+ * @param ctx the parse tree
1434
+ */
1435
+ enterUserTypeField?: (ctx: UserTypeFieldContext) => void;
1436
+ /**
1437
+ * Exit a parse tree produced by `MalloyParser.userTypeField`.
1438
+ * @param ctx the parse tree
1439
+ */
1440
+ exitUserTypeField?: (ctx: UserTypeFieldContext) => void;
1441
+ /**
1442
+ * Enter a parse tree produced by `MalloyParser.userTypeFieldType`.
1443
+ * @param ctx the parse tree
1444
+ */
1445
+ enterUserTypeFieldType?: (ctx: UserTypeFieldTypeContext) => void;
1446
+ /**
1447
+ * Exit a parse tree produced by `MalloyParser.userTypeFieldType`.
1448
+ * @param ctx the parse tree
1449
+ */
1450
+ exitUserTypeFieldType?: (ctx: UserTypeFieldTypeContext) => void;
1295
1451
  /**
1296
1452
  * Enter a parse tree produced by `MalloyParser.defineQuery`.
1297
1453
  * @param ctx the parse tree
@@ -1532,6 +1688,16 @@ export interface MalloyParserListener extends ParseTreeListener {
1532
1688
  * @param ctx the parse tree
1533
1689
  */
1534
1690
  exitExploreTable?: (ctx: ExploreTableContext) => void;
1691
+ /**
1692
+ * Enter a parse tree produced by `MalloyParser.virtualSource`.
1693
+ * @param ctx the parse tree
1694
+ */
1695
+ enterVirtualSource?: (ctx: VirtualSourceContext) => void;
1696
+ /**
1697
+ * Exit a parse tree produced by `MalloyParser.virtualSource`.
1698
+ * @param ctx the parse tree
1699
+ */
1700
+ exitVirtualSource?: (ctx: VirtualSourceContext) => void;
1535
1701
  /**
1536
1702
  * Enter a parse tree produced by `MalloyParser.connectionId`.
1537
1703
  * @param ctx the parse tree
@@ -1842,6 +2008,26 @@ export interface MalloyParserListener extends ParseTreeListener {
1842
2008
  * @param ctx the parse tree
1843
2009
  */
1844
2010
  exitSqExpr?: (ctx: SqExprContext) => void;
2011
+ /**
2012
+ * Enter a parse tree produced by `MalloyParser.sourceTypeConstraints`.
2013
+ * @param ctx the parse tree
2014
+ */
2015
+ enterSourceTypeConstraints?: (ctx: SourceTypeConstraintsContext) => void;
2016
+ /**
2017
+ * Exit a parse tree produced by `MalloyParser.sourceTypeConstraints`.
2018
+ * @param ctx the parse tree
2019
+ */
2020
+ exitSourceTypeConstraints?: (ctx: SourceTypeConstraintsContext) => void;
2021
+ /**
2022
+ * Enter a parse tree produced by `MalloyParser.userTypeName`.
2023
+ * @param ctx the parse tree
2024
+ */
2025
+ enterUserTypeName?: (ctx: UserTypeNameContext) => void;
2026
+ /**
2027
+ * Exit a parse tree produced by `MalloyParser.userTypeName`.
2028
+ * @param ctx the parse tree
2029
+ */
2030
+ exitUserTypeName?: (ctx: UserTypeNameContext) => void;
1845
2031
  /**
1846
2032
  * Enter a parse tree produced by `MalloyParser.includeBlock`.
1847
2033
  * @param ctx the parse tree
@@ -74,6 +74,9 @@ import { DefExploreAnnotationContext } from "./MalloyParser";
74
74
  import { DefIgnoreModel_stubContext } from "./MalloyParser";
75
75
  import { JoinWithContext } from "./MalloyParser";
76
76
  import { JoinOnContext } from "./MalloyParser";
77
+ import { UserTypeRefContext } from "./MalloyParser";
78
+ import { UserTypeInlineContext } from "./MalloyParser";
79
+ import { UserTypeExtendContext } from "./MalloyParser";
77
80
  import { SQIDContext } from "./MalloyParser";
78
81
  import { SQParensContext } from "./MalloyParser";
79
82
  import { SQComposeContext } from "./MalloyParser";
@@ -81,11 +84,21 @@ import { SQRefinedQueryContext } from "./MalloyParser";
81
84
  import { SQArrowContext } from "./MalloyParser";
82
85
  import { SQExtendedSourceContext } from "./MalloyParser";
83
86
  import { SQIncludeContext } from "./MalloyParser";
87
+ import { SQTypedSourceContext } from "./MalloyParser";
84
88
  import { SQTableContext } from "./MalloyParser";
89
+ import { SQVirtualContext } from "./MalloyParser";
85
90
  import { SQSQLContext } from "./MalloyParser";
86
91
  import { MalloyDocumentContext } from "./MalloyParser";
87
92
  import { MalloyStatementContext } from "./MalloyParser";
88
93
  import { DefineSourceStatementContext } from "./MalloyParser";
94
+ import { DefineUserTypeStatementContext } from "./MalloyParser";
95
+ import { UserTypePropertyListContext } from "./MalloyParser";
96
+ import { UserTypeDefinitionContext } from "./MalloyParser";
97
+ import { UserTypeNameDefContext } from "./MalloyParser";
98
+ import { UserTypeExprContext } from "./MalloyParser";
99
+ import { UserTypeShapeContext } from "./MalloyParser";
100
+ import { UserTypeFieldContext } from "./MalloyParser";
101
+ import { UserTypeFieldTypeContext } from "./MalloyParser";
89
102
  import { DefineQueryContext } from "./MalloyParser";
90
103
  import { TopLevelAnonQueryDefContext } from "./MalloyParser";
91
104
  import { AnnotationContext } from "./MalloyParser";
@@ -110,6 +123,7 @@ import { RefineOperatorContext } from "./MalloyParser";
110
123
  import { TurtleNameContext } from "./MalloyParser";
111
124
  import { SqlSourceContext } from "./MalloyParser";
112
125
  import { ExploreTableContext } from "./MalloyParser";
126
+ import { VirtualSourceContext } from "./MalloyParser";
113
127
  import { ConnectionIdContext } from "./MalloyParser";
114
128
  import { QueryPropertiesContext } from "./MalloyParser";
115
129
  import { QueryNameContext } from "./MalloyParser";
@@ -141,6 +155,8 @@ import { SourceArgumentsContext } from "./MalloyParser";
141
155
  import { ArgumentIdContext } from "./MalloyParser";
142
156
  import { SourceArgumentContext } from "./MalloyParser";
143
157
  import { SqExprContext } from "./MalloyParser";
158
+ import { SourceTypeConstraintsContext } from "./MalloyParser";
159
+ import { UserTypeNameContext } from "./MalloyParser";
144
160
  import { IncludeBlockContext } from "./MalloyParser";
145
161
  import { IncludeItemContext } from "./MalloyParser";
146
162
  import { OrphanedAnnotationContext } from "./MalloyParser";
@@ -782,6 +798,27 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
782
798
  * @return the visitor result
783
799
  */
784
800
  visitJoinOn?: (ctx: JoinOnContext) => Result;
801
+ /**
802
+ * Visit a parse tree produced by the `userTypeRef`
803
+ * labeled alternative in `MalloyParser.userTypeExpr`.
804
+ * @param ctx the parse tree
805
+ * @return the visitor result
806
+ */
807
+ visitUserTypeRef?: (ctx: UserTypeRefContext) => Result;
808
+ /**
809
+ * Visit a parse tree produced by the `userTypeInline`
810
+ * labeled alternative in `MalloyParser.userTypeExpr`.
811
+ * @param ctx the parse tree
812
+ * @return the visitor result
813
+ */
814
+ visitUserTypeInline?: (ctx: UserTypeInlineContext) => Result;
815
+ /**
816
+ * Visit a parse tree produced by the `userTypeExtend`
817
+ * labeled alternative in `MalloyParser.userTypeExpr`.
818
+ * @param ctx the parse tree
819
+ * @return the visitor result
820
+ */
821
+ visitUserTypeExtend?: (ctx: UserTypeExtendContext) => Result;
785
822
  /**
786
823
  * Visit a parse tree produced by the `SQID`
787
824
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -831,6 +868,13 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
831
868
  * @return the visitor result
832
869
  */
833
870
  visitSQInclude?: (ctx: SQIncludeContext) => Result;
871
+ /**
872
+ * Visit a parse tree produced by the `SQTypedSource`
873
+ * labeled alternative in `MalloyParser.sqExpr`.
874
+ * @param ctx the parse tree
875
+ * @return the visitor result
876
+ */
877
+ visitSQTypedSource?: (ctx: SQTypedSourceContext) => Result;
834
878
  /**
835
879
  * Visit a parse tree produced by the `SQTable`
836
880
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -838,6 +882,13 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
838
882
  * @return the visitor result
839
883
  */
840
884
  visitSQTable?: (ctx: SQTableContext) => Result;
885
+ /**
886
+ * Visit a parse tree produced by the `SQVirtual`
887
+ * labeled alternative in `MalloyParser.sqExpr`.
888
+ * @param ctx the parse tree
889
+ * @return the visitor result
890
+ */
891
+ visitSQVirtual?: (ctx: SQVirtualContext) => Result;
841
892
  /**
842
893
  * Visit a parse tree produced by the `SQSQL`
843
894
  * labeled alternative in `MalloyParser.sqExpr`.
@@ -863,6 +914,54 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
863
914
  * @return the visitor result
864
915
  */
865
916
  visitDefineSourceStatement?: (ctx: DefineSourceStatementContext) => Result;
917
+ /**
918
+ * Visit a parse tree produced by `MalloyParser.defineUserTypeStatement`.
919
+ * @param ctx the parse tree
920
+ * @return the visitor result
921
+ */
922
+ visitDefineUserTypeStatement?: (ctx: DefineUserTypeStatementContext) => Result;
923
+ /**
924
+ * Visit a parse tree produced by `MalloyParser.userTypePropertyList`.
925
+ * @param ctx the parse tree
926
+ * @return the visitor result
927
+ */
928
+ visitUserTypePropertyList?: (ctx: UserTypePropertyListContext) => Result;
929
+ /**
930
+ * Visit a parse tree produced by `MalloyParser.userTypeDefinition`.
931
+ * @param ctx the parse tree
932
+ * @return the visitor result
933
+ */
934
+ visitUserTypeDefinition?: (ctx: UserTypeDefinitionContext) => Result;
935
+ /**
936
+ * Visit a parse tree produced by `MalloyParser.userTypeNameDef`.
937
+ * @param ctx the parse tree
938
+ * @return the visitor result
939
+ */
940
+ visitUserTypeNameDef?: (ctx: UserTypeNameDefContext) => Result;
941
+ /**
942
+ * Visit a parse tree produced by `MalloyParser.userTypeExpr`.
943
+ * @param ctx the parse tree
944
+ * @return the visitor result
945
+ */
946
+ visitUserTypeExpr?: (ctx: UserTypeExprContext) => Result;
947
+ /**
948
+ * Visit a parse tree produced by `MalloyParser.userTypeShape`.
949
+ * @param ctx the parse tree
950
+ * @return the visitor result
951
+ */
952
+ visitUserTypeShape?: (ctx: UserTypeShapeContext) => Result;
953
+ /**
954
+ * Visit a parse tree produced by `MalloyParser.userTypeField`.
955
+ * @param ctx the parse tree
956
+ * @return the visitor result
957
+ */
958
+ visitUserTypeField?: (ctx: UserTypeFieldContext) => Result;
959
+ /**
960
+ * Visit a parse tree produced by `MalloyParser.userTypeFieldType`.
961
+ * @param ctx the parse tree
962
+ * @return the visitor result
963
+ */
964
+ visitUserTypeFieldType?: (ctx: UserTypeFieldTypeContext) => Result;
866
965
  /**
867
966
  * Visit a parse tree produced by `MalloyParser.defineQuery`.
868
967
  * @param ctx the parse tree
@@ -1007,6 +1106,12 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1007
1106
  * @return the visitor result
1008
1107
  */
1009
1108
  visitExploreTable?: (ctx: ExploreTableContext) => Result;
1109
+ /**
1110
+ * Visit a parse tree produced by `MalloyParser.virtualSource`.
1111
+ * @param ctx the parse tree
1112
+ * @return the visitor result
1113
+ */
1114
+ visitVirtualSource?: (ctx: VirtualSourceContext) => Result;
1010
1115
  /**
1011
1116
  * Visit a parse tree produced by `MalloyParser.connectionId`.
1012
1117
  * @param ctx the parse tree
@@ -1193,6 +1298,18 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1193
1298
  * @return the visitor result
1194
1299
  */
1195
1300
  visitSqExpr?: (ctx: SqExprContext) => Result;
1301
+ /**
1302
+ * Visit a parse tree produced by `MalloyParser.sourceTypeConstraints`.
1303
+ * @param ctx the parse tree
1304
+ * @return the visitor result
1305
+ */
1306
+ visitSourceTypeConstraints?: (ctx: SourceTypeConstraintsContext) => Result;
1307
+ /**
1308
+ * Visit a parse tree produced by `MalloyParser.userTypeName`.
1309
+ * @param ctx the parse tree
1310
+ * @return the visitor result
1311
+ */
1312
+ visitUserTypeName?: (ctx: UserTypeNameContext) => Result;
1196
1313
  /**
1197
1314
  * Visit a parse tree produced by `MalloyParser.includeBlock`.
1198
1315
  * @param ctx the parse tree
@@ -20,6 +20,11 @@ declare class IgnoredElement extends ast.MalloyElement {
20
20
  malloySrc: string;
21
21
  constructor(src: string);
22
22
  }
23
+ interface IndirectUserType {
24
+ namedUserType: string;
25
+ arrayDepth: number;
26
+ }
27
+ type UserTypeFieldTypeResult = AtomicTypeDef | IndirectUserType;
23
28
  type HasAnnotations = ParserRuleContext & {
24
29
  annotation: () => parse.AnnotationContext[];
25
30
  };
@@ -84,12 +89,22 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
84
89
  protected getIsNotes(cx: parse.IsDefineContext): Note[];
85
90
  visitMalloyDocument(pcx: parse.MalloyDocumentContext): ast.Document;
86
91
  visitDefineSourceStatement(pcx: parse.DefineSourceStatementContext): ast.DefineSourceList;
92
+ visitDefineUserTypeStatement(pcx: parse.DefineUserTypeStatementContext): ast.DefineUserTypeList;
93
+ visitUserTypeDefinition(pcx: parse.UserTypeDefinitionContext): ast.DefineUserType;
94
+ getUserTypeShapeExpr(cx: parse.UserTypeExprContext): ast.UserTypeShape;
95
+ visitUserTypeRef(pcx: parse.UserTypeRefContext): ast.ExtendedUserTypeShape;
96
+ visitUserTypeInline(pcx: parse.UserTypeInlineContext): ast.UserTypeShape;
97
+ visitUserTypeExtend(pcx: parse.UserTypeExtendContext): ast.ExtendedUserTypeShape;
98
+ getUserTypeShape(pcx: parse.UserTypeShapeContext): ast.UserTypeShape;
99
+ getUserTypeField(pcx: parse.UserTypeFieldContext): ast.UserTypeMember;
100
+ getUserTypeFieldType(pcx: parse.UserTypeFieldTypeContext): UserTypeFieldTypeResult;
87
101
  getSourceParameter(pcx: parse.SourceParameterContext): ast.HasParameter | null;
88
102
  getSourceParameters(pcx: parse.SourceParametersContext | undefined): ast.HasParameter[];
89
103
  visitSourceDefinition(pcx: parse.SourceDefinitionContext): ast.DefineSource;
90
104
  protected getSourceExtensions(extensions: parse.ExplorePropertiesContext): ast.SourceDesc;
91
105
  visitExploreProperties(pcx: parse.ExplorePropertiesContext): ast.SourceDesc;
92
106
  visitExploreTable(pcx: parse.ExploreTableContext): ast.TableSource;
107
+ visitVirtualSource(pcx: parse.VirtualSourceContext): ast.VirtualTableSource;
93
108
  visitSqlSource(pcx: parse.SqlSourceContext): ast.SQLSource;
94
109
  visitDefJoinMany(pcx: parse.DefJoinManyContext): ast.JoinStatement;
95
110
  visitDefJoinOne(pcx: parse.DefJoinOneContext): ast.JoinStatement;
@@ -221,6 +236,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
221
236
  visitSQID(pcx: parse.SQIDContext): ast.SQReference;
222
237
  protected getSqExpr(cx: parse.SqExprContext): ast.SourceQueryElement;
223
238
  visitSQExtendedSource(pcx: parse.SQExtendedSourceContext): ast.SQExtend;
239
+ visitSQTypedSource(pcx: parse.SQTypedSourceContext): ast.SQTypedSource;
224
240
  getIncludeItems(pcx: parse.IncludeBlockContext): ast.IncludeItem[];
225
241
  getIncludeItem(pcx: parse.IncludeItemContext): ast.IncludeItem | undefined;
226
242
  getIncludeList(pcx: parse.IncludeListContext): ast.IncludeListItem[];
@@ -238,6 +254,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
238
254
  visitVArrow(pcx: parse.VArrowContext): ast.ViewArrow;
239
255
  visitSQRefinedQuery(pcx: parse.SQRefinedQueryContext): ast.SQRefine;
240
256
  visitSQTable(pcx: parse.SQTableContext): ErrorNode | ast.SQSource;
257
+ visitSQVirtual(pcx: parse.SQVirtualContext): ast.SQSource;
241
258
  visitSQSQL(pcx: parse.SQSQLContext): ast.SQSource;
242
259
  visitExperimentalStatementForTesting(pcx: parse.ExperimentalStatementForTestingContext): ast.ExperimentalExperiment;
243
260
  visitRecordRef(pcx: parse.RecordRefContext): ast.RecordElement;
@@ -82,6 +82,9 @@ class IgnoredElement extends ast.MalloyElement {
82
82
  this.malloySrc = src;
83
83
  }
84
84
  }
85
+ function isIndirectUserType(t) {
86
+ return 'namedUserType' in t;
87
+ }
85
88
  const DEFAULT_COMPILER_FLAGS = [];
86
89
  /**
87
90
  * ANTLR visitor pattern parse tree traversal. Generates a Malloy
@@ -283,6 +286,100 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
283
286
  defList.extendNote({ blockNotes });
284
287
  return defList;
285
288
  }
289
+ visitDefineUserTypeStatement(pcx) {
290
+ this.inExperiment('virtual_source', pcx);
291
+ const defsCx = pcx.userTypePropertyList().userTypeDefinition();
292
+ const defs = defsCx.map(dcx => this.visitUserTypeDefinition(dcx));
293
+ const blockNotes = this.getNotes(pcx.tags());
294
+ const defList = new ast.DefineUserTypeList(defs);
295
+ defList.extendNote({ blockNotes });
296
+ return defList;
297
+ }
298
+ visitUserTypeDefinition(pcx) {
299
+ const shape = this.getUserTypeShapeExpr(pcx.userTypeExpr());
300
+ const def = new ast.DefineUserType((0, parse_utils_1.getId)(pcx.userTypeNameDef()), shape, true);
301
+ const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
302
+ def.extendNote({ notes });
303
+ return this.astAt(def, pcx);
304
+ }
305
+ getUserTypeShapeExpr(cx) {
306
+ const result = this.visit(cx);
307
+ if (result instanceof ast.UserTypeShape) {
308
+ return result;
309
+ }
310
+ throw this.internalError(cx, 'Expected a user type shape');
311
+ }
312
+ visitUserTypeRef(pcx) {
313
+ const name = (0, parse_utils_1.idToStr)(pcx.userTypeName().id());
314
+ return this.astAt(new ast.ExtendedUserTypeShape([], name), pcx);
315
+ }
316
+ visitUserTypeInline(pcx) {
317
+ return this.getUserTypeShape(pcx.userTypeShape());
318
+ }
319
+ visitUserTypeExtend(pcx) {
320
+ const baseName = (0, parse_utils_1.idToStr)(pcx.userTypeName().id());
321
+ const members = pcx
322
+ .userTypeShape()
323
+ .userTypeField()
324
+ .map(f => this.getUserTypeField(f));
325
+ return this.astAt(new ast.ExtendedUserTypeShape(members, baseName), pcx);
326
+ }
327
+ getUserTypeShape(pcx) {
328
+ const members = pcx.userTypeField().map(f => this.getUserTypeField(f));
329
+ return this.astAt(new ast.UserTypeShape(members), pcx);
330
+ }
331
+ getUserTypeField(pcx) {
332
+ const name = (0, parse_utils_1.getId)(pcx);
333
+ const typeResult = this.getUserTypeFieldType(pcx.userTypeFieldType());
334
+ let member;
335
+ if (isIndirectUserType(typeResult)) {
336
+ member = new ast.UserTypeMemberIndirect(name, typeResult.namedUserType, typeResult.arrayDepth);
337
+ }
338
+ else {
339
+ member = new ast.UserTypeMemberDef(name, typeResult);
340
+ }
341
+ const notes = this.getNotes(pcx.tags());
342
+ member.extendNote({ notes });
343
+ return this.astAt(member, pcx);
344
+ }
345
+ getUserTypeFieldType(pcx) {
346
+ const basicCx = pcx.malloyBasicType();
347
+ if (basicCx) {
348
+ return this.getBasicMalloyType(basicCx);
349
+ }
350
+ const bodyCx = pcx.userTypeShape();
351
+ if (bodyCx) {
352
+ const fields = bodyCx.userTypeField().map(fieldCx => {
353
+ const name = (0, parse_utils_1.getId)(fieldCx);
354
+ const fieldType = this.getUserTypeFieldType(fieldCx.userTypeFieldType());
355
+ if (isIndirectUserType(fieldType)) {
356
+ this.contextError(fieldCx, 'unexpected-malloy-type', `Named user type reference '${fieldType.namedUserType}' cannot be used as an inline record field type`);
357
+ return (0, malloy_types_1.mkFieldDef)({ type: 'error' }, name);
358
+ }
359
+ return (0, malloy_types_1.mkFieldDef)(fieldType, name);
360
+ });
361
+ return { type: 'record', fields };
362
+ }
363
+ const innerCx = pcx.userTypeFieldType();
364
+ if (innerCx) {
365
+ const inner = this.getUserTypeFieldType(innerCx);
366
+ if (isIndirectUserType(inner)) {
367
+ return { ...inner, arrayDepth: inner.arrayDepth + 1 };
368
+ }
369
+ return (0, malloy_types_1.mkArrayTypeDef)(inner);
370
+ }
371
+ const strCx = pcx.shortString();
372
+ if (strCx) {
373
+ const rawType = (0, parse_utils_1.getShortString)(strCx);
374
+ return { type: 'sql native', rawType };
375
+ }
376
+ const nameCx = pcx.userTypeName();
377
+ if (nameCx) {
378
+ return { namedUserType: (0, parse_utils_1.idToStr)(nameCx.id()), arrayDepth: 0 };
379
+ }
380
+ this.contextError(pcx, 'unexpected-malloy-type', 'Expected a user type field type');
381
+ return { type: 'error' };
382
+ }
286
383
  getSourceParameter(pcx) {
287
384
  const name = (0, parse_utils_1.getId)(pcx.parameterNameDef());
288
385
  let pType;
@@ -346,6 +443,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
346
443
  const tablePath = this.getPlainStringFrom(pcx.tablePath());
347
444
  return this.astAt(new ast.TableMethodSource(connectionName, tablePath), pcx);
348
445
  }
446
+ visitVirtualSource(pcx) {
447
+ this.inExperiment('virtual_source', pcx);
448
+ const connId = pcx.connectionId();
449
+ const connectionName = this.astAt(this.getModelEntryName(connId), connId);
450
+ const virtualName = (0, parse_utils_1.getShortString)(pcx.shortString());
451
+ return this.astAt(new ast.VirtualTableSource(connectionName, virtualName), pcx);
452
+ }
349
453
  visitSqlSource(pcx) {
350
454
  const connId = pcx.connectionId();
351
455
  const connectionName = this.astAt(this.getModelEntryName(connId), connId);
@@ -1391,6 +1495,15 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1391
1495
  const src = new ast.SQExtend(extendSrc, this.getSourceExtensions(pcx.exploreProperties()), includeList);
1392
1496
  return this.astAt(src, pcx);
1393
1497
  }
1498
+ visitSQTypedSource(pcx) {
1499
+ this.inExperiment('virtual_source', pcx);
1500
+ const sqSrc = this.getSqExpr(pcx.sqExpr());
1501
+ const userTypes = pcx
1502
+ .sourceTypeConstraints()
1503
+ .userTypeName()
1504
+ .map(nameCx => this.astAt(this.getModelEntryName(nameCx), nameCx));
1505
+ return this.astAt(new ast.SQTypedSource(sqSrc, userTypes), pcx);
1506
+ }
1394
1507
  getIncludeItems(pcx) {
1395
1508
  this.inExperiment('access_modifiers', pcx);
1396
1509
  return pcx
@@ -1524,6 +1637,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1524
1637
  }
1525
1638
  return new ErrorNode();
1526
1639
  }
1640
+ visitSQVirtual(pcx) {
1641
+ const theVirtual = this.visitVirtualSource(pcx.virtualSource());
1642
+ const sqVirtual = new ast.SQSource(theVirtual);
1643
+ return this.astAt(sqVirtual, pcx);
1644
+ }
1527
1645
  visitSQSQL(pcx) {
1528
1646
  const sqExpr = new ast.SQSource(this.visitSqlSource(pcx.sqlSource()));
1529
1647
  return this.astAt(sqExpr, pcx);