@malloydata/malloy 0.0.55-dev230707013046 → 0.0.55-dev230707183945

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.
@@ -160,12 +160,13 @@ import { IndexFieldsContext } from "./MalloyParser";
160
160
  import { IndexStatementContext } from "./MalloyParser";
161
161
  import { SampleStatementContext } from "./MalloyParser";
162
162
  import { TimezoneStatementContext } from "./MalloyParser";
163
- import { TimezoneNameContext } from "./MalloyParser";
164
163
  import { QueryAnnotationContext } from "./MalloyParser";
165
164
  import { SampleSpecContext } from "./MalloyParser";
166
165
  import { AggregateContext } from "./MalloyParser";
167
166
  import { MalloyTypeContext } from "./MalloyParser";
168
167
  import { CompareOpContext } from "./MalloyParser";
168
+ import { ShortStringContext } from "./MalloyParser";
169
+ import { NumericLiteralContext } from "./MalloyParser";
169
170
  import { LiteralContext } from "./MalloyParser";
170
171
  import { DateLiteralContext } from "./MalloyParser";
171
172
  import { TablePathContext } from "./MalloyParser";
@@ -187,11 +188,6 @@ import { FieldPathContext } from "./MalloyParser";
187
188
  import { JoinNameContext } from "./MalloyParser";
188
189
  import { FieldNameContext } from "./MalloyParser";
189
190
  import { JustExprContext } from "./MalloyParser";
190
- import { JsonContext } from "./MalloyParser";
191
- import { JsonValueContext } from "./MalloyParser";
192
- import { JsonObjectContext } from "./MalloyParser";
193
- import { JsonPropertyContext } from "./MalloyParser";
194
- import { JsonArrayContext } from "./MalloyParser";
195
191
  import { SqlExploreNameRefContext } from "./MalloyParser";
196
192
  import { NameSQLBlockContext } from "./MalloyParser";
197
193
  import { ConnectionNameContext } from "./MalloyParser";
@@ -1960,16 +1956,6 @@ export interface MalloyParserListener extends ParseTreeListener {
1960
1956
  * @param ctx the parse tree
1961
1957
  */
1962
1958
  exitTimezoneStatement?: (ctx: TimezoneStatementContext) => void;
1963
- /**
1964
- * Enter a parse tree produced by `MalloyParser.timezoneName`.
1965
- * @param ctx the parse tree
1966
- */
1967
- enterTimezoneName?: (ctx: TimezoneNameContext) => void;
1968
- /**
1969
- * Exit a parse tree produced by `MalloyParser.timezoneName`.
1970
- * @param ctx the parse tree
1971
- */
1972
- exitTimezoneName?: (ctx: TimezoneNameContext) => void;
1973
1959
  /**
1974
1960
  * Enter a parse tree produced by `MalloyParser.queryAnnotation`.
1975
1961
  * @param ctx the parse tree
@@ -2020,6 +2006,26 @@ export interface MalloyParserListener extends ParseTreeListener {
2020
2006
  * @param ctx the parse tree
2021
2007
  */
2022
2008
  exitCompareOp?: (ctx: CompareOpContext) => void;
2009
+ /**
2010
+ * Enter a parse tree produced by `MalloyParser.shortString`.
2011
+ * @param ctx the parse tree
2012
+ */
2013
+ enterShortString?: (ctx: ShortStringContext) => void;
2014
+ /**
2015
+ * Exit a parse tree produced by `MalloyParser.shortString`.
2016
+ * @param ctx the parse tree
2017
+ */
2018
+ exitShortString?: (ctx: ShortStringContext) => void;
2019
+ /**
2020
+ * Enter a parse tree produced by `MalloyParser.numericLiteral`.
2021
+ * @param ctx the parse tree
2022
+ */
2023
+ enterNumericLiteral?: (ctx: NumericLiteralContext) => void;
2024
+ /**
2025
+ * Exit a parse tree produced by `MalloyParser.numericLiteral`.
2026
+ * @param ctx the parse tree
2027
+ */
2028
+ exitNumericLiteral?: (ctx: NumericLiteralContext) => void;
2023
2029
  /**
2024
2030
  * Enter a parse tree produced by `MalloyParser.literal`.
2025
2031
  * @param ctx the parse tree
@@ -2230,56 +2236,6 @@ export interface MalloyParserListener extends ParseTreeListener {
2230
2236
  * @param ctx the parse tree
2231
2237
  */
2232
2238
  exitJustExpr?: (ctx: JustExprContext) => void;
2233
- /**
2234
- * Enter a parse tree produced by `MalloyParser.json`.
2235
- * @param ctx the parse tree
2236
- */
2237
- enterJson?: (ctx: JsonContext) => void;
2238
- /**
2239
- * Exit a parse tree produced by `MalloyParser.json`.
2240
- * @param ctx the parse tree
2241
- */
2242
- exitJson?: (ctx: JsonContext) => void;
2243
- /**
2244
- * Enter a parse tree produced by `MalloyParser.jsonValue`.
2245
- * @param ctx the parse tree
2246
- */
2247
- enterJsonValue?: (ctx: JsonValueContext) => void;
2248
- /**
2249
- * Exit a parse tree produced by `MalloyParser.jsonValue`.
2250
- * @param ctx the parse tree
2251
- */
2252
- exitJsonValue?: (ctx: JsonValueContext) => void;
2253
- /**
2254
- * Enter a parse tree produced by `MalloyParser.jsonObject`.
2255
- * @param ctx the parse tree
2256
- */
2257
- enterJsonObject?: (ctx: JsonObjectContext) => void;
2258
- /**
2259
- * Exit a parse tree produced by `MalloyParser.jsonObject`.
2260
- * @param ctx the parse tree
2261
- */
2262
- exitJsonObject?: (ctx: JsonObjectContext) => void;
2263
- /**
2264
- * Enter a parse tree produced by `MalloyParser.jsonProperty`.
2265
- * @param ctx the parse tree
2266
- */
2267
- enterJsonProperty?: (ctx: JsonPropertyContext) => void;
2268
- /**
2269
- * Exit a parse tree produced by `MalloyParser.jsonProperty`.
2270
- * @param ctx the parse tree
2271
- */
2272
- exitJsonProperty?: (ctx: JsonPropertyContext) => void;
2273
- /**
2274
- * Enter a parse tree produced by `MalloyParser.jsonArray`.
2275
- * @param ctx the parse tree
2276
- */
2277
- enterJsonArray?: (ctx: JsonArrayContext) => void;
2278
- /**
2279
- * Exit a parse tree produced by `MalloyParser.jsonArray`.
2280
- * @param ctx the parse tree
2281
- */
2282
- exitJsonArray?: (ctx: JsonArrayContext) => void;
2283
2239
  /**
2284
2240
  * Enter a parse tree produced by `MalloyParser.sqlExploreNameRef`.
2285
2241
  * @param ctx the parse tree
@@ -160,12 +160,13 @@ import { IndexFieldsContext } from "./MalloyParser";
160
160
  import { IndexStatementContext } from "./MalloyParser";
161
161
  import { SampleStatementContext } from "./MalloyParser";
162
162
  import { TimezoneStatementContext } from "./MalloyParser";
163
- import { TimezoneNameContext } from "./MalloyParser";
164
163
  import { QueryAnnotationContext } from "./MalloyParser";
165
164
  import { SampleSpecContext } from "./MalloyParser";
166
165
  import { AggregateContext } from "./MalloyParser";
167
166
  import { MalloyTypeContext } from "./MalloyParser";
168
167
  import { CompareOpContext } from "./MalloyParser";
168
+ import { ShortStringContext } from "./MalloyParser";
169
+ import { NumericLiteralContext } from "./MalloyParser";
169
170
  import { LiteralContext } from "./MalloyParser";
170
171
  import { DateLiteralContext } from "./MalloyParser";
171
172
  import { TablePathContext } from "./MalloyParser";
@@ -187,11 +188,6 @@ import { FieldPathContext } from "./MalloyParser";
187
188
  import { JoinNameContext } from "./MalloyParser";
188
189
  import { FieldNameContext } from "./MalloyParser";
189
190
  import { JustExprContext } from "./MalloyParser";
190
- import { JsonContext } from "./MalloyParser";
191
- import { JsonValueContext } from "./MalloyParser";
192
- import { JsonObjectContext } from "./MalloyParser";
193
- import { JsonPropertyContext } from "./MalloyParser";
194
- import { JsonArrayContext } from "./MalloyParser";
195
191
  import { SqlExploreNameRefContext } from "./MalloyParser";
196
192
  import { NameSQLBlockContext } from "./MalloyParser";
197
193
  import { ConnectionNameContext } from "./MalloyParser";
@@ -1244,12 +1240,6 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1244
1240
  * @return the visitor result
1245
1241
  */
1246
1242
  visitTimezoneStatement?: (ctx: TimezoneStatementContext) => Result;
1247
- /**
1248
- * Visit a parse tree produced by `MalloyParser.timezoneName`.
1249
- * @param ctx the parse tree
1250
- * @return the visitor result
1251
- */
1252
- visitTimezoneName?: (ctx: TimezoneNameContext) => Result;
1253
1243
  /**
1254
1244
  * Visit a parse tree produced by `MalloyParser.queryAnnotation`.
1255
1245
  * @param ctx the parse tree
@@ -1280,6 +1270,18 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1280
1270
  * @return the visitor result
1281
1271
  */
1282
1272
  visitCompareOp?: (ctx: CompareOpContext) => Result;
1273
+ /**
1274
+ * Visit a parse tree produced by `MalloyParser.shortString`.
1275
+ * @param ctx the parse tree
1276
+ * @return the visitor result
1277
+ */
1278
+ visitShortString?: (ctx: ShortStringContext) => Result;
1279
+ /**
1280
+ * Visit a parse tree produced by `MalloyParser.numericLiteral`.
1281
+ * @param ctx the parse tree
1282
+ * @return the visitor result
1283
+ */
1284
+ visitNumericLiteral?: (ctx: NumericLiteralContext) => Result;
1283
1285
  /**
1284
1286
  * Visit a parse tree produced by `MalloyParser.literal`.
1285
1287
  * @param ctx the parse tree
@@ -1406,36 +1408,6 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
1406
1408
  * @return the visitor result
1407
1409
  */
1408
1410
  visitJustExpr?: (ctx: JustExprContext) => Result;
1409
- /**
1410
- * Visit a parse tree produced by `MalloyParser.json`.
1411
- * @param ctx the parse tree
1412
- * @return the visitor result
1413
- */
1414
- visitJson?: (ctx: JsonContext) => Result;
1415
- /**
1416
- * Visit a parse tree produced by `MalloyParser.jsonValue`.
1417
- * @param ctx the parse tree
1418
- * @return the visitor result
1419
- */
1420
- visitJsonValue?: (ctx: JsonValueContext) => Result;
1421
- /**
1422
- * Visit a parse tree produced by `MalloyParser.jsonObject`.
1423
- * @param ctx the parse tree
1424
- * @return the visitor result
1425
- */
1426
- visitJsonObject?: (ctx: JsonObjectContext) => Result;
1427
- /**
1428
- * Visit a parse tree produced by `MalloyParser.jsonProperty`.
1429
- * @param ctx the parse tree
1430
- * @return the visitor result
1431
- */
1432
- visitJsonProperty?: (ctx: JsonPropertyContext) => Result;
1433
- /**
1434
- * Visit a parse tree produced by `MalloyParser.jsonArray`.
1435
- * @param ctx the parse tree
1436
- * @return the visitor result
1437
- */
1438
- visitJsonArray?: (ctx: JsonArrayContext) => Result;
1439
1411
  /**
1440
1412
  * Visit a parse tree produced by `MalloyParser.sqlExploreNameRef`.
1441
1413
  * @param ctx the parse tree
@@ -12,6 +12,9 @@ declare class IgnoredElement extends ast.MalloyElement {
12
12
  malloySrc: string;
13
13
  constructor(src: string);
14
14
  }
15
+ declare type ContainsID = ParserRuleContext & {
16
+ id: () => parse.IdContext;
17
+ };
15
18
  /**
16
19
  * ANTLR visitor pattern parse tree traversal. Generates a Malloy
17
20
  * AST from an ANTLR parse tree.
@@ -39,12 +42,8 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
39
42
  protected contextError(cx: ParserRuleContext, msg: string, sev?: LogSeverity): void;
40
43
  protected only<T extends ast.MalloyElement>(els: ast.MalloyElement[], isGood: (el: ast.MalloyElement) => T | false, desc: string): T[];
41
44
  protected getNumber(term: ParseTree): number;
42
- protected optionalString(fromTerm: ParseTree | undefined): string | undefined;
43
- protected getIdText(fromTerm: ParseTree): string;
44
- protected getFieldName(cx: ParserRuleContext): ast.FieldName;
45
- protected getModelEntryName(cx: ParserRuleContext): ast.ModelEntryReference;
46
- protected stripQuotes(s: string): string;
47
- protected optionalText(idCx: ParseTree | undefined): string | undefined;
45
+ protected getFieldName(cx: ContainsID): ast.FieldName;
46
+ protected getModelEntryName(cx: ContainsID): ast.ModelEntryReference;
48
47
  defaultResult(): ast.MalloyElement;
49
48
  protected astAt<MT extends ast.MalloyElement>(el: MT, cx: ParserRuleContext): MT;
50
49
  protected getSourceCode(cx: ParserRuleContext): string;
@@ -50,6 +50,7 @@ const AbstractParseTreeVisitor_1 = require("antlr4ts/tree/AbstractParseTreeVisit
50
50
  const ast = __importStar(require("./ast"));
51
51
  const Interval_1 = require("antlr4ts/misc/Interval");
52
52
  const ast_1 = require("./ast");
53
+ const string_parser_1 = require("./string-parser");
53
54
  const ENABLE_M4_WARNINGS = false;
54
55
  class IgnoredElement extends ast.MalloyElement {
55
56
  constructor(src) {
@@ -70,6 +71,52 @@ function getIsNotes(cx) {
70
71
  const before = getNotes(cx._beforeIs);
71
72
  return before.concat(getNotes(cx._afterIs));
72
73
  }
74
+ /**
75
+ * Take the text of a matched string, including the matching quote
76
+ * characters, and return the actual contents of the string after
77
+ * \ processing.
78
+ * @param cx Any parse context which contains a string
79
+ * @returns Decocded string
80
+ */
81
+ function getShortString(cx) {
82
+ var _a, _b;
83
+ const scx = cx.shortString();
84
+ const str = ((_a = scx.DQ_STRING()) === null || _a === void 0 ? void 0 : _a.text) || ((_b = scx.SQ_STRING()) === null || _b === void 0 ? void 0 : _b.text);
85
+ if (str) {
86
+ return (0, string_parser_1.parseString)(str, str[0]);
87
+ }
88
+ // shortString: DQ_STRING | SQ_STRING; So this will never happen
89
+ return '';
90
+ }
91
+ function getOptionalString(cx) {
92
+ function containsString(cx) {
93
+ return 'shortString' in cx;
94
+ }
95
+ if (containsString(cx) && cx.shortString()) {
96
+ return getShortString(cx);
97
+ }
98
+ }
99
+ /**
100
+ * An identifier is either a sequence of id characters or a `quoted`
101
+ * This parses either to simply the resulting text.
102
+ * @param cx A context which has an identifier
103
+ * @returns The indenftifier text
104
+ */
105
+ function getId(cx) {
106
+ const quoted = cx.id().BQ_STRING();
107
+ if (quoted) {
108
+ return (0, string_parser_1.parseString)(quoted.text, '`');
109
+ }
110
+ return cx.id().text;
111
+ }
112
+ function getOptionalId(cx) {
113
+ function containsID(cx) {
114
+ return 'id' in cx;
115
+ }
116
+ if (containsID(cx) && cx.id()) {
117
+ return getId(cx);
118
+ }
119
+ }
73
120
  /**
74
121
  * ANTLR visitor pattern parse tree traversal. Generates a Malloy
75
122
  * AST from an ANTLR parse tree.
@@ -128,34 +175,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
128
175
  getNumber(term) {
129
176
  return Number.parseInt(term.text);
130
177
  }
131
- optionalString(fromTerm) {
132
- if (fromTerm) {
133
- return this.stripQuotes(fromTerm.text);
134
- }
135
- return undefined;
136
- }
137
- getIdText(fromTerm) {
138
- return this.stripQuotes(fromTerm.text);
139
- }
140
178
  getFieldName(cx) {
141
- return this.astAt(new ast.FieldName(this.getIdText(cx)), cx);
179
+ return this.astAt(new ast.FieldName(getId(cx)), cx);
142
180
  }
143
181
  getModelEntryName(cx) {
144
- return this.astAt(new ast.ModelEntryReference(this.getIdText(cx)), cx);
145
- }
146
- stripQuotes(s) {
147
- if (s[0] === '`' || s[0] === "'" || s[0] === '"') {
148
- if (s[0] === s[s.length - 1]) {
149
- return s.slice(1, -1);
150
- }
151
- }
152
- return s;
153
- }
154
- optionalText(idCx) {
155
- if (idCx) {
156
- return this.getIdText(idCx);
157
- }
158
- return undefined;
182
+ return this.astAt(new ast.ModelEntryReference(getId(cx)), cx);
159
183
  }
160
184
  defaultResult() {
161
185
  return new ast.Unimplemented();
@@ -242,7 +266,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
242
266
  return defList;
243
267
  }
244
268
  visitSourceDefinition(pcx) {
245
- const exploreDef = new ast.DefineSource(this.getIdText(pcx.sourceNameDef()), this.visitExplore(pcx.explore()), true, []);
269
+ const exploreDef = new ast.DefineSource(getId(pcx.sourceNameDef()), this.visitExplore(pcx.explore()), true, []);
246
270
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
247
271
  exploreDef.extendNote({ notes });
248
272
  return this.astAt(exploreDef, pcx);
@@ -265,7 +289,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
265
289
  return propList;
266
290
  }
267
291
  visitTableFunction(pcx) {
268
- const tableURI = this.stripQuotes(pcx.tableURI().text);
292
+ const tableURI = getShortString(pcx.tableURI());
269
293
  const el = this.astAt(new ast.TableFunctionSource(tableURI), pcx);
270
294
  if (ENABLE_M4_WARNINGS) {
271
295
  this.astError(el, "`table('connection_name:table_path')` is deprecated; use `connection_name.table('table_path')`", 'warn');
@@ -275,7 +299,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
275
299
  visitTableMethod(pcx) {
276
300
  const connId = pcx.connectionId();
277
301
  const connectionName = this.astAt(this.getModelEntryName(connId), connId);
278
- const tablePath = this.stripQuotes(pcx.tablePath().text);
302
+ const tablePath = getShortString(pcx.tablePath());
279
303
  return this.astAt(new ast.TableMethodSource(connectionName, tablePath), pcx);
280
304
  }
281
305
  visitTableSource(pcx) {
@@ -294,7 +318,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
294
318
  const connectionName = this.astAt(this.getModelEntryName(connId), connId);
295
319
  const sqlStr = new ast.SQLString();
296
320
  const selCx = pcx.sqlString();
297
- this.makeSqlString(selCx, sqlStr);
321
+ if (selCx) {
322
+ this.makeSqlString(selCx, sqlStr);
323
+ }
324
+ const shortSelect = getOptionalString(pcx);
325
+ if (shortSelect) {
326
+ sqlStr.push(shortSelect);
327
+ }
298
328
  const expr = new ast.SQLSource(connectionName, sqlStr);
299
329
  return this.astAt(expr, pcx);
300
330
  }
@@ -398,7 +428,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
398
428
  }
399
429
  getFieldDef(pcx, makeFieldDef) {
400
430
  const defCx = pcx.fieldExpr();
401
- const fieldName = this.getIdText(pcx.fieldNameDef());
431
+ const fieldName = getId(pcx.fieldNameDef());
402
432
  const valExpr = this.getFieldExpr(defCx);
403
433
  const def = new makeFieldDef(valExpr, fieldName, this.getSourceCode(defCx));
404
434
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
@@ -444,9 +474,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
444
474
  return result;
445
475
  }
446
476
  visitExploreRenameDef(pcx) {
447
- const newName = pcx.fieldName(0).id();
448
- const oldName = pcx.fieldName(1).id();
449
- const rename = new ast.RenameField(this.getIdText(newName), this.getFieldName(oldName));
477
+ const newName = pcx.fieldName(0);
478
+ const oldName = pcx.fieldName(1);
479
+ const rename = new ast.RenameField(getId(newName), this.getFieldName(oldName));
450
480
  return this.astAt(rename, pcx);
451
481
  }
452
482
  visitDefExploreRename(pcx) {
@@ -502,8 +532,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
502
532
  return this.visitTimezoneStatement(cx.timezoneStatement());
503
533
  }
504
534
  visitTimezoneStatement(cx) {
505
- const tz = cx.timezoneName();
506
- const timezoneStatement = this.astAt(new ast.TimezoneStatement(this.stripQuotes(tz.STRING_LITERAL().text)), tz);
535
+ const timezoneStatement = this.astAt(new ast.TimezoneStatement(getShortString(cx)), cx.shortString());
507
536
  if (!timezoneStatement.isValid) {
508
537
  this.astError(timezoneStatement, `Invalid timezone: ${timezoneStatement.tz}`);
509
538
  }
@@ -662,8 +691,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
662
691
  return this.astAt(top, pcx);
663
692
  }
664
693
  visitSourceID(pcx) {
665
- const name = this.getModelEntryName(pcx.id());
666
- return this.astAt(new ast.NamedSource(name), pcx);
694
+ return this.astAt(new ast.NamedSource(getId(pcx)), pcx);
667
695
  }
668
696
  buildPipelineFromName(pipe, pipeCx) {
669
697
  const firstCx = pipeCx.firstSegment();
@@ -710,7 +738,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
710
738
  return queryDefs;
711
739
  }
712
740
  visitTopLevelQueryDef(pcx) {
713
- const queryName = this.getIdText(pcx.queryName());
741
+ const queryName = getId(pcx.queryName());
714
742
  const queryExpr = this.visit(pcx.query());
715
743
  if (ast.isQueryElement(queryExpr)) {
716
744
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
@@ -774,7 +802,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
774
802
  return nestRef;
775
803
  }
776
804
  visitNestDef(pcx) {
777
- const name = this.getIdText(pcx.queryName());
805
+ const name = getId(pcx.queryName());
778
806
  const nestDef = new ast.NestDefinition(name);
779
807
  this.buildPipelineFromName(nestDef, pcx.pipelineFromName());
780
808
  nestDef.extendNote({
@@ -783,7 +811,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
783
811
  return this.astAt(nestDef, pcx);
784
812
  }
785
813
  visitExploreQueryDef(pcx) {
786
- const name = this.getIdText(pcx.exploreQueryNameDef());
814
+ const name = getId(pcx.exploreQueryNameDef());
787
815
  const queryDef = new ast.TurtleDecl(name);
788
816
  const notes = getNotes(pcx).concat(getIsNotes(pcx.isDefine()));
789
817
  queryDef.extendNote({ notes });
@@ -837,29 +865,17 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
837
865
  return fieldExpr;
838
866
  }
839
867
  visitExprString(pcx) {
840
- return new ast.ExprString(pcx.STRING_LITERAL().text);
868
+ return new ast.ExprString(getShortString(pcx));
841
869
  }
842
870
  visitExprRegex(pcx) {
843
871
  const malloyRegex = pcx.HACKY_REGEX().text;
844
- return new ast.ExprRegEx(this.stripQuotes(malloyRegex.slice(1)));
872
+ return new ast.ExprRegEx(malloyRegex.slice(2, -1));
845
873
  }
846
874
  visitExprNow(_pcx) {
847
875
  return new ast.ExprNow();
848
876
  }
849
877
  visitExprNumber(pcx) {
850
- var _a, _b;
851
- const number = ((_a = pcx.INTEGER_LITERAL()) === null || _a === void 0 ? void 0 : _a.text) || ((_b = pcx.NUMERIC_LITERAL()) === null || _b === void 0 ? void 0 : _b.text);
852
- /*
853
- * I "know" one of these is true because grammar, but Typescript
854
- * rightly points out that grammvisitExprFieldPathar can change in unexpected ways
855
- */
856
- if (number) {
857
- return new ast.ExprNumber(number);
858
- }
859
- else {
860
- this.contextError(pcx, `'${pcx.text}' is not a number`);
861
- return new ast.ExprNumber('42');
862
- }
878
+ return new ast.ExprNumber(pcx.text);
863
879
  }
864
880
  visitExprFieldPath(pcx) {
865
881
  const idRef = new ast.ExprIdReference(this.getFieldPath(pcx.fieldPath(), ast.ExpressionFieldReference));
@@ -896,7 +912,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
896
912
  }
897
913
  visitExprUngroup(pcx) {
898
914
  const flist = pcx.fieldName().map(fcx => this.getFieldName(fcx));
899
- const kw = this.getIdText(pcx.ungroup()).toLocaleLowerCase();
915
+ const kw = pcx.ungroup().text.toLowerCase();
900
916
  return this.astAt(new ast.ExprUngroup(kw === 'all' ? kw : 'exclude', this.getFieldExpr(pcx.fieldExpr()), flist), pcx);
901
917
  }
902
918
  visitExprAggregate(pcx) {
@@ -986,8 +1002,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
986
1002
  visitExprAggFunc(pcx) {
987
1003
  const argsCx = pcx.argumentList();
988
1004
  const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
989
- const idCx = pcx.id();
990
- const fn = this.getIdText(idCx);
1005
+ const fn = getId(pcx);
991
1006
  const pathCx = pcx.fieldPath();
992
1007
  const path = pathCx
993
1008
  ? this.getFieldPath(pathCx, ast.ExpressionFieldReference)
@@ -999,7 +1014,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
999
1014
  return this.astAt(new ast.ExprFunc(fn, args, false, undefined, source), pcx);
1000
1015
  }
1001
1016
  visitExprFunc(pcx) {
1002
- var _a;
1017
+ var _a, _b;
1003
1018
  const argsCx = pcx.argumentList();
1004
1019
  const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
1005
1020
  const isRaw = pcx.EXCLAM() !== undefined;
@@ -1014,17 +1029,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1014
1029
  rawType = undefined;
1015
1030
  }
1016
1031
  }
1017
- const idCx = pcx.id();
1018
- const dCx = pcx.timeframe();
1019
- let fn;
1020
- if (idCx) {
1021
- fn = this.getIdText(idCx);
1022
- }
1023
- else if (dCx) {
1024
- fn = dCx.text;
1025
- }
1026
- else {
1027
- this.contextError(pcx, 'Funciton name error');
1032
+ let fn = getOptionalId(pcx) || ((_b = pcx.timeframe()) === null || _b === void 0 ? void 0 : _b.text);
1033
+ if (fn === undefined) {
1034
+ this.contextError(pcx, 'Function name error');
1028
1035
  fn = 'FUNCTION_NAME_ERROR';
1029
1036
  }
1030
1037
  if (ast.ExprTimeExtract.extractor(fn)) {
@@ -1089,7 +1096,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1089
1096
  return this.parseTime(pcx, ast.LiteralYear.parse);
1090
1097
  }
1091
1098
  visitImportStatement(pcx) {
1092
- const url = this.stripQuotes(pcx.importURL().text);
1099
+ const url = getShortString(pcx.importURL());
1093
1100
  return this.astAt(new ast.ImportStatement(url, this.parse.subTranslator.sourceURL), pcx);
1094
1101
  }
1095
1102
  visitJustExpr(pcx) {
@@ -1108,7 +1115,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1108
1115
  this.contextError(nmCx, 'Cannot redefine connection');
1109
1116
  }
1110
1117
  else {
1111
- connectionName = this.getIdText(nmCx);
1118
+ connectionName = getShortString(nmCx);
1112
1119
  }
1113
1120
  }
1114
1121
  const selCx = blockEnt.sqlString();
@@ -210,8 +210,8 @@ function passForHighlights(tokens) {
210
210
  case MalloyParser_1.MalloyParser.FROM_SQL:
211
211
  register(token, exports.HighlightType.Call.FromSQL);
212
212
  break;
213
- case MalloyParser_1.MalloyParser.STRING_LITERAL:
214
- case MalloyParser_1.MalloyParser.JSON_STRING:
213
+ case MalloyParser_1.MalloyParser.SQ_STRING:
214
+ case MalloyParser_1.MalloyParser.DQ_STRING:
215
215
  register(token, exports.HighlightType.Literal.String);
216
216
  break;
217
217
  case MalloyParser_1.MalloyParser.NUMERIC_LITERAL:
@@ -298,7 +298,7 @@ function passForHighlights(tokens) {
298
298
  register(token, exports.HighlightType.Call.Aggregate);
299
299
  break;
300
300
  case MalloyParser_1.MalloyParser.IDENTIFIER:
301
- case MalloyParser_1.MalloyParser.OBJECT_NAME_LITERAL:
301
+ case MalloyParser_1.MalloyParser.BQ_STRING:
302
302
  register(token, exports.HighlightType.Identifier);
303
303
  break;
304
304
  case MalloyParser_1.MalloyParser.STRING:
@@ -56,7 +56,7 @@ class FindExternalReferences {
56
56
  this.registerTableReference(connectionName, tablePath, reference);
57
57
  }
58
58
  enterImportURL(pcx) {
59
- const url = JSON.parse(pcx.JSON_STRING().text);
59
+ const url = JSON.parse(pcx.shortString().text);
60
60
  if (!this.needImports[url]) {
61
61
  this.needImports[url] = this.trans.rangeFromContext(pcx);
62
62
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Parses the interior of a string, doing all \ substitutions. In most cases
3
+ * a lexical analyzer has already recognized this as a string. As a convenience,
4
+ * strip off the quoting outer chartacters if asked, then parse the interior of
5
+ * the string. The intention is to be compatible with JSON strings, in terms
6
+ * of which \X substitutions are processed.
7
+ * @param str is the string to parse
8
+ * @param surround is the quoting character, default means quotes already stripped
9
+ * @returns a string with the \ processing completed
10
+ */
11
+ export declare function parseString(str: string, surround?: string): string;