@malloydata/malloy 0.0.54 → 0.0.55-dev230707164317

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,44 @@ 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 containsID(cx) {
92
+ return 'id' in cx;
93
+ }
94
+ /**
95
+ * An identifier is either a sequence of id characters or a `quoted`
96
+ * This parses either to simply the resulting text.
97
+ * @param cx A context which has an identifier
98
+ * @returns The indenftifier text
99
+ */
100
+ function getId(cx) {
101
+ const quoted = cx.id().BQ_STRING();
102
+ if (quoted) {
103
+ return (0, string_parser_1.parseString)(quoted.text, '`');
104
+ }
105
+ return cx.id().text;
106
+ }
107
+ function getOptionalId(cx) {
108
+ if (containsID(cx) && cx.id()) {
109
+ return getId(cx);
110
+ }
111
+ }
73
112
  /**
74
113
  * ANTLR visitor pattern parse tree traversal. Generates a Malloy
75
114
  * AST from an ANTLR parse tree.
@@ -128,34 +167,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
128
167
  getNumber(term) {
129
168
  return Number.parseInt(term.text);
130
169
  }
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
170
  getFieldName(cx) {
141
- return this.astAt(new ast.FieldName(this.getIdText(cx)), cx);
171
+ return this.astAt(new ast.FieldName(getId(cx)), cx);
142
172
  }
143
173
  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;
174
+ return this.astAt(new ast.ModelEntryReference(getId(cx)), cx);
159
175
  }
160
176
  defaultResult() {
161
177
  return new ast.Unimplemented();
@@ -242,7 +258,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
242
258
  return defList;
243
259
  }
244
260
  visitSourceDefinition(pcx) {
245
- const exploreDef = new ast.DefineSource(this.getIdText(pcx.sourceNameDef()), this.visitExplore(pcx.explore()), true, []);
261
+ const exploreDef = new ast.DefineSource(getId(pcx.sourceNameDef()), this.visitExplore(pcx.explore()), true, []);
246
262
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
247
263
  exploreDef.extendNote({ notes });
248
264
  return this.astAt(exploreDef, pcx);
@@ -265,7 +281,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
265
281
  return propList;
266
282
  }
267
283
  visitTableFunction(pcx) {
268
- const tableURI = this.stripQuotes(pcx.tableURI().text);
284
+ const tableURI = getShortString(pcx.tableURI());
269
285
  const el = this.astAt(new ast.TableFunctionSource(tableURI), pcx);
270
286
  if (ENABLE_M4_WARNINGS) {
271
287
  this.astError(el, "`table('connection_name:table_path')` is deprecated; use `connection_name.table('table_path')`", 'warn');
@@ -275,7 +291,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
275
291
  visitTableMethod(pcx) {
276
292
  const connId = pcx.connectionId();
277
293
  const connectionName = this.astAt(this.getModelEntryName(connId), connId);
278
- const tablePath = this.stripQuotes(pcx.tablePath().text);
294
+ const tablePath = getShortString(pcx.tablePath());
279
295
  return this.astAt(new ast.TableMethodSource(connectionName, tablePath), pcx);
280
296
  }
281
297
  visitTableSource(pcx) {
@@ -398,7 +414,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
398
414
  }
399
415
  getFieldDef(pcx, makeFieldDef) {
400
416
  const defCx = pcx.fieldExpr();
401
- const fieldName = this.getIdText(pcx.fieldNameDef());
417
+ const fieldName = getId(pcx.fieldNameDef());
402
418
  const valExpr = this.getFieldExpr(defCx);
403
419
  const def = new makeFieldDef(valExpr, fieldName, this.getSourceCode(defCx));
404
420
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
@@ -444,9 +460,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
444
460
  return result;
445
461
  }
446
462
  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));
463
+ const newName = pcx.fieldName(0);
464
+ const oldName = pcx.fieldName(1);
465
+ const rename = new ast.RenameField(getId(newName), this.getFieldName(oldName));
450
466
  return this.astAt(rename, pcx);
451
467
  }
452
468
  visitDefExploreRename(pcx) {
@@ -502,8 +518,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
502
518
  return this.visitTimezoneStatement(cx.timezoneStatement());
503
519
  }
504
520
  visitTimezoneStatement(cx) {
505
- const tz = cx.timezoneName();
506
- const timezoneStatement = this.astAt(new ast.TimezoneStatement(this.stripQuotes(tz.STRING_LITERAL().text)), tz);
521
+ const timezoneStatement = this.astAt(new ast.TimezoneStatement(getShortString(cx)), cx.shortString());
507
522
  if (!timezoneStatement.isValid) {
508
523
  this.astError(timezoneStatement, `Invalid timezone: ${timezoneStatement.tz}`);
509
524
  }
@@ -662,8 +677,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
662
677
  return this.astAt(top, pcx);
663
678
  }
664
679
  visitSourceID(pcx) {
665
- const name = this.getModelEntryName(pcx.id());
666
- return this.astAt(new ast.NamedSource(name), pcx);
680
+ return this.astAt(new ast.NamedSource(getId(pcx)), pcx);
667
681
  }
668
682
  buildPipelineFromName(pipe, pipeCx) {
669
683
  const firstCx = pipeCx.firstSegment();
@@ -710,7 +724,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
710
724
  return queryDefs;
711
725
  }
712
726
  visitTopLevelQueryDef(pcx) {
713
- const queryName = this.getIdText(pcx.queryName());
727
+ const queryName = getId(pcx.queryName());
714
728
  const queryExpr = this.visit(pcx.query());
715
729
  if (ast.isQueryElement(queryExpr)) {
716
730
  const notes = getNotes(pcx.tags()).concat(getIsNotes(pcx.isDefine()));
@@ -774,7 +788,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
774
788
  return nestRef;
775
789
  }
776
790
  visitNestDef(pcx) {
777
- const name = this.getIdText(pcx.queryName());
791
+ const name = getId(pcx.queryName());
778
792
  const nestDef = new ast.NestDefinition(name);
779
793
  this.buildPipelineFromName(nestDef, pcx.pipelineFromName());
780
794
  nestDef.extendNote({
@@ -783,7 +797,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
783
797
  return this.astAt(nestDef, pcx);
784
798
  }
785
799
  visitExploreQueryDef(pcx) {
786
- const name = this.getIdText(pcx.exploreQueryNameDef());
800
+ const name = getId(pcx.exploreQueryNameDef());
787
801
  const queryDef = new ast.TurtleDecl(name);
788
802
  const notes = getNotes(pcx).concat(getIsNotes(pcx.isDefine()));
789
803
  queryDef.extendNote({ notes });
@@ -837,29 +851,17 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
837
851
  return fieldExpr;
838
852
  }
839
853
  visitExprString(pcx) {
840
- return new ast.ExprString(pcx.STRING_LITERAL().text);
854
+ return new ast.ExprString(getShortString(pcx));
841
855
  }
842
856
  visitExprRegex(pcx) {
843
857
  const malloyRegex = pcx.HACKY_REGEX().text;
844
- return new ast.ExprRegEx(this.stripQuotes(malloyRegex.slice(1)));
858
+ return new ast.ExprRegEx(malloyRegex.slice(2, -1));
845
859
  }
846
860
  visitExprNow(_pcx) {
847
861
  return new ast.ExprNow();
848
862
  }
849
863
  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
- }
864
+ return new ast.ExprNumber(pcx.text);
863
865
  }
864
866
  visitExprFieldPath(pcx) {
865
867
  const idRef = new ast.ExprIdReference(this.getFieldPath(pcx.fieldPath(), ast.ExpressionFieldReference));
@@ -896,7 +898,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
896
898
  }
897
899
  visitExprUngroup(pcx) {
898
900
  const flist = pcx.fieldName().map(fcx => this.getFieldName(fcx));
899
- const kw = this.getIdText(pcx.ungroup()).toLocaleLowerCase();
901
+ const kw = pcx.ungroup().text.toLowerCase();
900
902
  return this.astAt(new ast.ExprUngroup(kw === 'all' ? kw : 'exclude', this.getFieldExpr(pcx.fieldExpr()), flist), pcx);
901
903
  }
902
904
  visitExprAggregate(pcx) {
@@ -986,8 +988,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
986
988
  visitExprAggFunc(pcx) {
987
989
  const argsCx = pcx.argumentList();
988
990
  const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
989
- const idCx = pcx.id();
990
- const fn = this.getIdText(idCx);
991
+ const fn = getId(pcx);
991
992
  const pathCx = pcx.fieldPath();
992
993
  const path = pathCx
993
994
  ? this.getFieldPath(pathCx, ast.ExpressionFieldReference)
@@ -999,7 +1000,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
999
1000
  return this.astAt(new ast.ExprFunc(fn, args, false, undefined, source), pcx);
1000
1001
  }
1001
1002
  visitExprFunc(pcx) {
1002
- var _a;
1003
+ var _a, _b;
1003
1004
  const argsCx = pcx.argumentList();
1004
1005
  const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
1005
1006
  const isRaw = pcx.EXCLAM() !== undefined;
@@ -1014,17 +1015,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1014
1015
  rawType = undefined;
1015
1016
  }
1016
1017
  }
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');
1018
+ let fn = getOptionalId(pcx) || ((_b = pcx.timeframe()) === null || _b === void 0 ? void 0 : _b.text);
1019
+ if (fn === undefined) {
1020
+ this.contextError(pcx, 'Function name error');
1028
1021
  fn = 'FUNCTION_NAME_ERROR';
1029
1022
  }
1030
1023
  if (ast.ExprTimeExtract.extractor(fn)) {
@@ -1089,7 +1082,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1089
1082
  return this.parseTime(pcx, ast.LiteralYear.parse);
1090
1083
  }
1091
1084
  visitImportStatement(pcx) {
1092
- const url = this.stripQuotes(pcx.importURL().text);
1085
+ const url = getShortString(pcx.importURL());
1093
1086
  return this.astAt(new ast.ImportStatement(url, this.parse.subTranslator.sourceURL), pcx);
1094
1087
  }
1095
1088
  visitJustExpr(pcx) {
@@ -1108,7 +1101,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
1108
1101
  this.contextError(nmCx, 'Cannot redefine connection');
1109
1102
  }
1110
1103
  else {
1111
- connectionName = this.getIdText(nmCx);
1104
+ connectionName = getShortString(nmCx);
1112
1105
  }
1113
1106
  }
1114
1107
  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;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.parseString = void 0;
26
+ var ParseState;
27
+ (function (ParseState) {
28
+ ParseState[ParseState["Normal"] = 0] = "Normal";
29
+ ParseState[ParseState["ReverseVirgule"] = 1] = "ReverseVirgule";
30
+ ParseState[ParseState["Unicode"] = 2] = "Unicode";
31
+ })(ParseState || (ParseState = {}));
32
+ /**
33
+ * Parses the interior of a string, doing all \ substitutions. In most cases
34
+ * a lexical analyzer has already recognized this as a string. As a convenience,
35
+ * strip off the quoting outer chartacters if asked, then parse the interior of
36
+ * the string. The intention is to be compatible with JSON strings, in terms
37
+ * of which \X substitutions are processed.
38
+ * @param str is the string to parse
39
+ * @param surround is the quoting character, default means quotes already stripped
40
+ * @returns a string with the \ processing completed
41
+ */
42
+ function parseString(str, surround = '') {
43
+ let inner = str.slice(surround.length);
44
+ let state = ParseState.Normal;
45
+ if (surround.length) {
46
+ inner = inner.slice(0, -surround.length);
47
+ }
48
+ let out = '';
49
+ let unicode = '';
50
+ for (const c of inner) {
51
+ switch (state) {
52
+ case ParseState.Normal: {
53
+ if (c === '\\') {
54
+ state = ParseState.ReverseVirgule;
55
+ }
56
+ else {
57
+ out += c;
58
+ }
59
+ break;
60
+ }
61
+ case ParseState.ReverseVirgule: {
62
+ let outc = c;
63
+ if (c === 'u') {
64
+ state = ParseState.Unicode;
65
+ unicode = '';
66
+ continue;
67
+ }
68
+ if (c === 'b') {
69
+ outc = '\b';
70
+ }
71
+ else if (c === 'f') {
72
+ outc = '\f';
73
+ }
74
+ else if (c === 'n') {
75
+ outc = '\n';
76
+ }
77
+ else if (c === 'r') {
78
+ outc = '\r';
79
+ }
80
+ else if (c === 't') {
81
+ outc = '\t';
82
+ }
83
+ out += outc;
84
+ state = ParseState.Normal;
85
+ break;
86
+ }
87
+ case ParseState.Unicode: {
88
+ if ('ABCDEFabcdef0123456789'.includes(c)) {
89
+ unicode += c;
90
+ if (unicode.length === 4) {
91
+ out += String.fromCharCode(parseInt(unicode, 16));
92
+ state = ParseState.Normal;
93
+ }
94
+ }
95
+ else {
96
+ // Don't think we ever get here ...
97
+ state = ParseState.Normal;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ exports.parseString = parseString;
105
+ //# sourceMappingURL=string-parser.js.map