@malloydata/malloy 0.0.157 → 0.0.158-dev240805161224

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 (67) hide show
  1. package/dist/lang/ast/expressions/constant-expression.d.ts +28 -0
  2. package/dist/lang/ast/expressions/{constant-sub-expression.js → constant-expression.js} +6 -5
  3. package/dist/lang/ast/expressions/expr-func.js +29 -11
  4. package/dist/lang/ast/expressions/expr-id-reference.d.ts +0 -1
  5. package/dist/lang/ast/expressions/expr-id-reference.js +0 -24
  6. package/dist/lang/ast/field-space/dynamic-space.d.ts +4 -1
  7. package/dist/lang/ast/field-space/dynamic-space.js +22 -11
  8. package/dist/lang/ast/field-space/index-field-space.js +3 -0
  9. package/dist/lang/ast/field-space/join-space-field.d.ts +3 -1
  10. package/dist/lang/ast/field-space/join-space-field.js +3 -2
  11. package/dist/lang/ast/field-space/parameter-space.d.ts +18 -0
  12. package/dist/lang/ast/field-space/parameter-space.js +67 -0
  13. package/dist/lang/ast/field-space/query-spaces.js +3 -0
  14. package/dist/lang/ast/field-space/reference-field.js +13 -4
  15. package/dist/lang/ast/field-space/refined-space.d.ts +2 -1
  16. package/dist/lang/ast/field-space/refined-space.js +12 -1
  17. package/dist/lang/ast/field-space/static-space.js +3 -5
  18. package/dist/lang/ast/index.d.ts +1 -0
  19. package/dist/lang/ast/index.js +1 -0
  20. package/dist/lang/ast/parameters/argument.d.ts +14 -0
  21. package/dist/lang/ast/parameters/argument.js +20 -0
  22. package/dist/lang/ast/parameters/has-parameter.d.ts +3 -5
  23. package/dist/lang/ast/parameters/has-parameter.js +24 -13
  24. package/dist/lang/ast/query-elements/query-arrow.js +7 -7
  25. package/dist/lang/ast/query-elements/query-head-struct.d.ts +6 -4
  26. package/dist/lang/ast/query-elements/query-head-struct.js +6 -5
  27. package/dist/lang/ast/query-elements/query-raw.js +7 -7
  28. package/dist/lang/ast/query-elements/query-reference.js +2 -2
  29. package/dist/lang/ast/query-items/field-references.d.ts +4 -0
  30. package/dist/lang/ast/query-items/field-references.js +12 -1
  31. package/dist/lang/ast/source-elements/named-source.d.ts +15 -12
  32. package/dist/lang/ast/source-elements/named-source.js +91 -60
  33. package/dist/lang/ast/source-elements/query-source.d.ts +4 -1
  34. package/dist/lang/ast/source-elements/query-source.js +9 -3
  35. package/dist/lang/ast/source-elements/refined-source.d.ts +3 -2
  36. package/dist/lang/ast/source-elements/refined-source.js +12 -7
  37. package/dist/lang/ast/source-elements/source.d.ts +6 -4
  38. package/dist/lang/ast/source-elements/source.js +19 -16
  39. package/dist/lang/ast/source-elements/sql-source.d.ts +2 -2
  40. package/dist/lang/ast/source-elements/sql-source.js +4 -3
  41. package/dist/lang/ast/source-properties/joins.d.ts +5 -4
  42. package/dist/lang/ast/source-properties/joins.js +7 -7
  43. package/dist/lang/ast/source-query-elements/sq-reference.d.ts +3 -1
  44. package/dist/lang/ast/source-query-elements/sq-reference.js +9 -2
  45. package/dist/lang/ast/statements/define-source.d.ts +4 -2
  46. package/dist/lang/ast/statements/define-source.js +28 -14
  47. package/dist/lang/ast/struct-utils.js +3 -2
  48. package/dist/lang/ast/types/expression-def.js +2 -0
  49. package/dist/lang/lib/Malloy/MalloyParser.d.ts +169 -101
  50. package/dist/lang/lib/Malloy/MalloyParser.js +2105 -1600
  51. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +64 -9
  52. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +40 -5
  53. package/dist/lang/malloy-to-ast.d.ts +5 -1
  54. package/dist/lang/malloy-to-ast.js +51 -10
  55. package/dist/lang/test/expressions.spec.js +21 -1
  56. package/dist/lang/test/field-symbols.spec.js +0 -2
  57. package/dist/lang/test/locations.spec.js +3 -0
  58. package/dist/lang/test/parameters.spec.d.ts +1 -0
  59. package/dist/lang/test/parameters.spec.js +578 -0
  60. package/dist/model/malloy_query.d.ts +8 -5
  61. package/dist/model/malloy_query.js +68 -37
  62. package/dist/model/malloy_types.d.ts +12 -14
  63. package/dist/model/malloy_types.js +22 -10
  64. package/package.json +1 -1
  65. package/dist/lang/ast/expressions/constant-sub-expression.d.ts +0 -16
  66. package/dist/lang/ast/parameters/constant-parameter.d.ts +0 -8
  67. package/dist/lang/ast/parameters/constant-parameter.js +0 -54
@@ -106,8 +106,10 @@ import { QueryNameContext } from "./MalloyParser";
106
106
  import { SourcePropertyListContext } from "./MalloyParser";
107
107
  import { SourceDefinitionContext } from "./MalloyParser";
108
108
  import { SqExploreContext } from "./MalloyParser";
109
+ import { SourceParametersContext } from "./MalloyParser";
110
+ import { SourceParameterContext } from "./MalloyParser";
111
+ import { ParameterNameDefContext } from "./MalloyParser";
109
112
  import { SourceNameDefContext } from "./MalloyParser";
110
- import { SourceIDContext } from "./MalloyParser";
111
113
  import { ExplorePropertiesContext } from "./MalloyParser";
112
114
  import { ExploreStatementContext } from "./MalloyParser";
113
115
  import { DefMeasuresContext } from "./MalloyParser";
@@ -122,6 +124,9 @@ import { DeclareStatementContext } from "./MalloyParser";
122
124
  import { JoinStatementContext } from "./MalloyParser";
123
125
  import { QueryExtendContext } from "./MalloyParser";
124
126
  import { ModEitherContext } from "./MalloyParser";
127
+ import { SourceArgumentsContext } from "./MalloyParser";
128
+ import { ArgumentIdContext } from "./MalloyParser";
129
+ import { SourceArgumentContext } from "./MalloyParser";
125
130
  import { SqExprContext } from "./MalloyParser";
126
131
  import { SegExprContext } from "./MalloyParser";
127
132
  import { VExprContext } from "./MalloyParser";
@@ -1434,25 +1439,45 @@ export interface MalloyParserListener extends ParseTreeListener {
1434
1439
  */
1435
1440
  exitSqExplore?: (ctx: SqExploreContext) => void;
1436
1441
  /**
1437
- * Enter a parse tree produced by `MalloyParser.sourceNameDef`.
1442
+ * Enter a parse tree produced by `MalloyParser.sourceParameters`.
1438
1443
  * @param ctx the parse tree
1439
1444
  */
1440
- enterSourceNameDef?: (ctx: SourceNameDefContext) => void;
1445
+ enterSourceParameters?: (ctx: SourceParametersContext) => void;
1441
1446
  /**
1442
- * Exit a parse tree produced by `MalloyParser.sourceNameDef`.
1447
+ * Exit a parse tree produced by `MalloyParser.sourceParameters`.
1443
1448
  * @param ctx the parse tree
1444
1449
  */
1445
- exitSourceNameDef?: (ctx: SourceNameDefContext) => void;
1450
+ exitSourceParameters?: (ctx: SourceParametersContext) => void;
1451
+ /**
1452
+ * Enter a parse tree produced by `MalloyParser.sourceParameter`.
1453
+ * @param ctx the parse tree
1454
+ */
1455
+ enterSourceParameter?: (ctx: SourceParameterContext) => void;
1456
+ /**
1457
+ * Exit a parse tree produced by `MalloyParser.sourceParameter`.
1458
+ * @param ctx the parse tree
1459
+ */
1460
+ exitSourceParameter?: (ctx: SourceParameterContext) => void;
1446
1461
  /**
1447
- * Enter a parse tree produced by `MalloyParser.sourceID`.
1462
+ * Enter a parse tree produced by `MalloyParser.parameterNameDef`.
1448
1463
  * @param ctx the parse tree
1449
1464
  */
1450
- enterSourceID?: (ctx: SourceIDContext) => void;
1465
+ enterParameterNameDef?: (ctx: ParameterNameDefContext) => void;
1451
1466
  /**
1452
- * Exit a parse tree produced by `MalloyParser.sourceID`.
1467
+ * Exit a parse tree produced by `MalloyParser.parameterNameDef`.
1468
+ * @param ctx the parse tree
1469
+ */
1470
+ exitParameterNameDef?: (ctx: ParameterNameDefContext) => void;
1471
+ /**
1472
+ * Enter a parse tree produced by `MalloyParser.sourceNameDef`.
1473
+ * @param ctx the parse tree
1474
+ */
1475
+ enterSourceNameDef?: (ctx: SourceNameDefContext) => void;
1476
+ /**
1477
+ * Exit a parse tree produced by `MalloyParser.sourceNameDef`.
1453
1478
  * @param ctx the parse tree
1454
1479
  */
1455
- exitSourceID?: (ctx: SourceIDContext) => void;
1480
+ exitSourceNameDef?: (ctx: SourceNameDefContext) => void;
1456
1481
  /**
1457
1482
  * Enter a parse tree produced by `MalloyParser.exploreProperties`.
1458
1483
  * @param ctx the parse tree
@@ -1593,6 +1618,36 @@ export interface MalloyParserListener extends ParseTreeListener {
1593
1618
  * @param ctx the parse tree
1594
1619
  */
1595
1620
  exitModEither?: (ctx: ModEitherContext) => void;
1621
+ /**
1622
+ * Enter a parse tree produced by `MalloyParser.sourceArguments`.
1623
+ * @param ctx the parse tree
1624
+ */
1625
+ enterSourceArguments?: (ctx: SourceArgumentsContext) => void;
1626
+ /**
1627
+ * Exit a parse tree produced by `MalloyParser.sourceArguments`.
1628
+ * @param ctx the parse tree
1629
+ */
1630
+ exitSourceArguments?: (ctx: SourceArgumentsContext) => void;
1631
+ /**
1632
+ * Enter a parse tree produced by `MalloyParser.argumentId`.
1633
+ * @param ctx the parse tree
1634
+ */
1635
+ enterArgumentId?: (ctx: ArgumentIdContext) => void;
1636
+ /**
1637
+ * Exit a parse tree produced by `MalloyParser.argumentId`.
1638
+ * @param ctx the parse tree
1639
+ */
1640
+ exitArgumentId?: (ctx: ArgumentIdContext) => void;
1641
+ /**
1642
+ * Enter a parse tree produced by `MalloyParser.sourceArgument`.
1643
+ * @param ctx the parse tree
1644
+ */
1645
+ enterSourceArgument?: (ctx: SourceArgumentContext) => void;
1646
+ /**
1647
+ * Exit a parse tree produced by `MalloyParser.sourceArgument`.
1648
+ * @param ctx the parse tree
1649
+ */
1650
+ exitSourceArgument?: (ctx: SourceArgumentContext) => void;
1596
1651
  /**
1597
1652
  * Enter a parse tree produced by `MalloyParser.sqExpr`.
1598
1653
  * @param ctx the parse tree
@@ -106,8 +106,10 @@ import { QueryNameContext } from "./MalloyParser";
106
106
  import { SourcePropertyListContext } from "./MalloyParser";
107
107
  import { SourceDefinitionContext } from "./MalloyParser";
108
108
  import { SqExploreContext } from "./MalloyParser";
109
+ import { SourceParametersContext } from "./MalloyParser";
110
+ import { SourceParameterContext } from "./MalloyParser";
111
+ import { ParameterNameDefContext } from "./MalloyParser";
109
112
  import { SourceNameDefContext } from "./MalloyParser";
110
- import { SourceIDContext } from "./MalloyParser";
111
113
  import { ExplorePropertiesContext } from "./MalloyParser";
112
114
  import { ExploreStatementContext } from "./MalloyParser";
113
115
  import { DefMeasuresContext } from "./MalloyParser";
@@ -122,6 +124,9 @@ import { DeclareStatementContext } from "./MalloyParser";
122
124
  import { JoinStatementContext } from "./MalloyParser";
123
125
  import { QueryExtendContext } from "./MalloyParser";
124
126
  import { ModEitherContext } from "./MalloyParser";
127
+ import { SourceArgumentsContext } from "./MalloyParser";
128
+ import { ArgumentIdContext } from "./MalloyParser";
129
+ import { SourceArgumentContext } from "./MalloyParser";
125
130
  import { SqExprContext } from "./MalloyParser";
126
131
  import { SegExprContext } from "./MalloyParser";
127
132
  import { VExprContext } from "./MalloyParser";
@@ -932,17 +937,29 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
932
937
  */
933
938
  visitSqExplore?: (ctx: SqExploreContext) => Result;
934
939
  /**
935
- * Visit a parse tree produced by `MalloyParser.sourceNameDef`.
940
+ * Visit a parse tree produced by `MalloyParser.sourceParameters`.
936
941
  * @param ctx the parse tree
937
942
  * @return the visitor result
938
943
  */
939
- visitSourceNameDef?: (ctx: SourceNameDefContext) => Result;
944
+ visitSourceParameters?: (ctx: SourceParametersContext) => Result;
945
+ /**
946
+ * Visit a parse tree produced by `MalloyParser.sourceParameter`.
947
+ * @param ctx the parse tree
948
+ * @return the visitor result
949
+ */
950
+ visitSourceParameter?: (ctx: SourceParameterContext) => Result;
940
951
  /**
941
- * Visit a parse tree produced by `MalloyParser.sourceID`.
952
+ * Visit a parse tree produced by `MalloyParser.parameterNameDef`.
942
953
  * @param ctx the parse tree
943
954
  * @return the visitor result
944
955
  */
945
- visitSourceID?: (ctx: SourceIDContext) => Result;
956
+ visitParameterNameDef?: (ctx: ParameterNameDefContext) => Result;
957
+ /**
958
+ * Visit a parse tree produced by `MalloyParser.sourceNameDef`.
959
+ * @param ctx the parse tree
960
+ * @return the visitor result
961
+ */
962
+ visitSourceNameDef?: (ctx: SourceNameDefContext) => Result;
946
963
  /**
947
964
  * Visit a parse tree produced by `MalloyParser.exploreProperties`.
948
965
  * @param ctx the parse tree
@@ -1027,6 +1044,24 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1027
1044
  * @return the visitor result
1028
1045
  */
1029
1046
  visitModEither?: (ctx: ModEitherContext) => Result;
1047
+ /**
1048
+ * Visit a parse tree produced by `MalloyParser.sourceArguments`.
1049
+ * @param ctx the parse tree
1050
+ * @return the visitor result
1051
+ */
1052
+ visitSourceArguments?: (ctx: SourceArgumentsContext) => Result;
1053
+ /**
1054
+ * Visit a parse tree produced by `MalloyParser.argumentId`.
1055
+ * @param ctx the parse tree
1056
+ * @return the visitor result
1057
+ */
1058
+ visitArgumentId?: (ctx: ArgumentIdContext) => Result;
1059
+ /**
1060
+ * Visit a parse tree produced by `MalloyParser.sourceArgument`.
1061
+ * @param ctx the parse tree
1062
+ * @return the visitor result
1063
+ */
1064
+ visitSourceArgument?: (ctx: SourceArgumentContext) => Result;
1030
1065
  /**
1031
1066
  * Visit a parse tree produced by `MalloyParser.sqExpr`.
1032
1067
  * @param ctx the parse tree
@@ -79,6 +79,8 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
79
79
  protected getIsNotes(cx: parse.IsDefineContext): Note[];
80
80
  visitMalloyDocument(pcx: parse.MalloyDocumentContext): ast.Document;
81
81
  visitDefineSourceStatement(pcx: parse.DefineSourceStatementContext): ast.DefineSourceList;
82
+ getSourceParameter(pcx: parse.SourceParameterContext): ast.HasParameter;
83
+ getSourceParameters(pcx: parse.SourceParametersContext | undefined): ast.HasParameter[];
82
84
  visitSourceDefinition(pcx: parse.SourceDefinitionContext): ast.DefineSource;
83
85
  protected getSourceExtensions(extensions: parse.ExplorePropertiesContext): ast.SourceDesc;
84
86
  visitExploreProperties(pcx: parse.ExplorePropertiesContext): ast.SourceDesc;
@@ -136,7 +138,6 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
136
138
  visitOrderBySpec(pcx: parse.OrderBySpecContext): ast.OrderBy;
137
139
  visitOrdering(pcx: parse.OrderingContext): ast.Ordering;
138
140
  visitTopStatement(pcx: parse.TopStatementContext): ast.Top;
139
- visitSourceID(pcx: parse.SourceIDContext): ast.NamedSource;
140
141
  visitTopLevelQueryDefs(pcx: parse.TopLevelQueryDefsContext): ast.DefineQueryList;
141
142
  visitTopLevelQueryDef(pcx: parse.TopLevelQueryDefContext): ast.DefineQuery;
142
143
  visitAnonymousQuery(pcx: parse.AnonymousQueryContext): ast.AnonymousQuery;
@@ -174,6 +175,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
174
175
  visitExprApply(pcx: parse.ExprApplyContext): ast.Apply;
175
176
  visitExprRange(pcx: parse.ExprRangeContext): ast.Range;
176
177
  visitExprCast(pcx: parse.ExprCastContext): ast.ExpressionDef;
178
+ getMalloyType(pcx: parse.MalloyTypeContext): CastType;
177
179
  getMalloyOrSQLType(pcx: parse.MalloyOrSQLTypeContext): CastType | {
178
180
  raw: string;
179
181
  };
@@ -201,6 +203,8 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
201
203
  visitIgnoredObjectAnnotations(pcx: parse.IgnoredObjectAnnotationsContext): IgnoredElement;
202
204
  visitIgnoredModelAnnotations(pcx: parse.IgnoredModelAnnotationsContext): IgnoredElement;
203
205
  visitDefExploreAnnotation(pcx: parse.DefExploreAnnotationContext): ast.ObjectAnnotation;
206
+ getSQArgument(pcx: parse.SourceArgumentContext): ast.Argument;
207
+ getSQArguments(pcx: parse.SourceArgumentsContext | undefined): ast.Argument[] | undefined;
204
208
  visitSQID(pcx: parse.SQIDContext): ast.SQReference;
205
209
  protected getSqExpr(cx: parse.SqExprContext): ast.SourceQueryElement;
206
210
  visitSQExtendedSource(pcx: parse.SQExtendedSourceContext): ast.SQExtend;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  /*
3
3
  * Copyright 2023 Google LLC
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
5
  *
5
6
  * Permission is hereby granted, free of charge, to any person obtaining
6
7
  * a copy of this software and associated documentation files
@@ -54,6 +55,7 @@ const ast_1 = require("./ast");
54
55
  const parse_utils_1 = require("./parse-utils");
55
56
  const malloy_types_1 = require("../model/malloy_types");
56
57
  const tags_1 = require("../tags");
58
+ const constant_expression_1 = require("./ast/expressions/constant-expression");
57
59
  class ErrorNode extends ast.SourceQueryElement {
58
60
  constructor() {
59
61
  super(...arguments);
@@ -282,9 +284,29 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
282
284
  defList.extendNote({ blockNotes });
283
285
  return defList;
284
286
  }
287
+ getSourceParameter(pcx) {
288
+ const defaultCx = pcx.fieldExpr();
289
+ const defaultValue = defaultCx
290
+ ? this.astAt(new constant_expression_1.ConstantExpression(this.getFieldExpr(defaultCx)), defaultCx)
291
+ : undefined;
292
+ const typeCx = pcx.malloyType();
293
+ const type = typeCx ? this.getMalloyType(typeCx) : undefined;
294
+ return this.astAt(new ast.HasParameter({
295
+ name: (0, parse_utils_1.getId)(pcx.parameterNameDef()),
296
+ type,
297
+ default: defaultValue,
298
+ }), pcx);
299
+ }
300
+ getSourceParameters(pcx) {
301
+ if (pcx === undefined)
302
+ return [];
303
+ this.inExperiment('parameters', pcx);
304
+ return pcx.sourceParameter().map(param => this.getSourceParameter(param));
305
+ }
285
306
  visitSourceDefinition(pcx) {
286
307
  const exploreExpr = this.visit(pcx.sqExplore());
287
- const exploreDef = new ast.DefineSource((0, parse_utils_1.getId)(pcx.sourceNameDef()), exploreExpr instanceof ast.SourceQueryElement ? exploreExpr : undefined, true, []);
308
+ const params = this.getSourceParameters(pcx.sourceParameters());
309
+ const exploreDef = new ast.DefineSource((0, parse_utils_1.getId)(pcx.sourceNameDef()), exploreExpr instanceof ast.SourceQueryElement ? exploreExpr : undefined, true, params);
288
310
  const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
289
311
  exploreDef.extendNote({ notes });
290
312
  return this.astAt(exploreDef, pcx);
@@ -740,9 +762,6 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
740
762
  }
741
763
  return this.astAt(top, pcx);
742
764
  }
743
- visitSourceID(pcx) {
744
- return this.astAt(new ast.NamedSource((0, parse_utils_1.getId)(pcx)), pcx);
745
- }
746
765
  visitTopLevelQueryDefs(pcx) {
747
766
  const stmts = pcx
748
767
  .topLevelQueryDef()
@@ -1023,14 +1042,17 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1023
1042
  const type = this.getMalloyOrSQLType(pcx.malloyOrSQLType());
1024
1043
  return new ast.ExprCast(this.getFieldExpr(pcx.fieldExpr()), type);
1025
1044
  }
1045
+ getMalloyType(pcx) {
1046
+ const type = pcx.text;
1047
+ if ((0, malloy_types_1.isCastType)(type)) {
1048
+ return type;
1049
+ }
1050
+ throw this.internalError(pcx, `unknown type '${type}'`);
1051
+ }
1026
1052
  getMalloyOrSQLType(pcx) {
1027
1053
  const mtcx = pcx.malloyType();
1028
1054
  if (mtcx) {
1029
- const type = mtcx.text;
1030
- if ((0, malloy_types_1.isCastType)(type)) {
1031
- return type;
1032
- }
1033
- throw this.internalError(pcx, `unknown type '${type}'`);
1055
+ return this.getMalloyType(mtcx);
1034
1056
  }
1035
1057
  const rtcx = pcx.string();
1036
1058
  if (rtcx) {
@@ -1198,9 +1220,28 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1198
1220
  const allNotes = this.getNotes(pcx);
1199
1221
  return new ast.ObjectAnnotation(allNotes);
1200
1222
  }
1223
+ getSQArgument(pcx) {
1224
+ const id = pcx.argumentId();
1225
+ const ref = id
1226
+ ? this.astAt(new ast.PartitionByFieldReference([
1227
+ this.astAt(new ast.FieldName((0, parse_utils_1.idToStr)(id.id())), id),
1228
+ ]), id)
1229
+ : undefined;
1230
+ return this.astAt(new ast.Argument({
1231
+ id: ref,
1232
+ value: this.getFieldExpr(pcx.fieldExpr()),
1233
+ }), pcx);
1234
+ }
1235
+ getSQArguments(pcx) {
1236
+ if (pcx === undefined)
1237
+ return undefined;
1238
+ this.inExperiment('parameters', pcx);
1239
+ return pcx.sourceArgument().map(arg => this.getSQArgument(arg));
1240
+ }
1201
1241
  visitSQID(pcx) {
1202
1242
  const ref = this.getModelEntryName(pcx);
1203
- return this.astAt(new ast.SQReference(ref), pcx.id());
1243
+ const args = this.getSQArguments(pcx.sourceArguments());
1244
+ return this.astAt(new ast.SQReference(ref, args), pcx.id());
1204
1245
  }
1205
1246
  getSqExpr(cx) {
1206
1247
  const result = this.visit(cx);
@@ -899,7 +899,27 @@ describe('sql native fields in schema', () => {
899
899
  });
900
900
  describe('sql functions', () => {
901
901
  test('can aggregate a sql_ function', () => {
902
- expect((0, test_translator_1.expr) `sum(sql_number("\${a} * 2"))`).toTranslate();
902
+ expect(`
903
+ ##! experimental.sql_functions
904
+ run: a -> {
905
+ aggregate: x is sum(sql_number("\${ai} * 2"))
906
+ }
907
+ `).toTranslate();
908
+ });
909
+ test('error when interpolating field that does not exist', () => {
910
+ expect(`
911
+ ##! experimental.sql_functions
912
+ run: a -> {
913
+ group_by: x is sql_number("\${asdfasdf} * 2")
914
+ }
915
+ `).translationToFailWith("Invalid interpolation: 'asdfasdf' is not defined");
916
+ });
917
+ test('error when using sql_ function without experiment', () => {
918
+ expect(`
919
+ run: a -> {
920
+ group_by: x is sql_number("\${asdfasdf} * 2")
921
+ }
922
+ `).translationToFailWith('Cannot use sql_function `sql_number`; use `sql_functions` experiment to enable this behavior');
903
923
  });
904
924
  });
905
925
  describe('cast', () => {
@@ -183,13 +183,11 @@ describe('structdef comprehension', () => {
183
183
  name: 'cReqStr',
184
184
  type: 'string',
185
185
  value: null,
186
- constant: false,
187
186
  },
188
187
  cOptStr: {
189
188
  name: 'cOptStr',
190
189
  type: 'string',
191
190
  value: ['value'],
192
- constant: false,
193
191
  },
194
192
  };
195
193
  const space = new static_space_1.StaticSpace(struct);
@@ -37,6 +37,9 @@ describe('source locations', () => {
37
37
  expect(m).toParse();
38
38
  expect((0, test_translator_1.getExplore)(m.modelDef, 'na').location).toMatchObject(source.locations[0]);
39
39
  });
40
+ // TODO make parameters have locations, and make references to them work
41
+ // with existing jump-to-definition system
42
+ test.todo('location of parameter');
40
43
  test('location of defined dimension', () => {
41
44
  const source = (0, test_translator_1.markSource) `source: na is a extend { dimension: ${'x is 1'} }`;
42
45
  const m = new test_translator_1.TestTranslator(source.code);
@@ -0,0 +1 @@
1
+ import './parse-expects';