@malloydata/malloy 0.0.222 → 0.0.223-dev241213043533
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.
- package/dist/lang/ast/expressions/expr-array-literal.js +4 -1
- package/dist/lang/ast/expressions/expr-record-literal.d.ts +12 -3
- package/dist/lang/ast/expressions/expr-record-literal.js +35 -7
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +2 -2
- package/dist/lang/lib/Malloy/MalloyParser.js +653 -645
- package/dist/lang/malloy-to-ast.js +7 -12
- package/dist/lang/parse-log.d.ts +1 -0
- package/dist/lang/test/literals.spec.js +14 -0
- package/dist/lang/test/parse-expects.js +11 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1446,22 +1446,17 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1446
1446
|
return this.astAt(new ast.ExperimentalExperiment('compilerTestExperimentTranslate'), pcx);
|
|
1447
1447
|
}
|
|
1448
1448
|
visitRecordRef(pcx) {
|
|
1449
|
-
const
|
|
1450
|
-
|
|
1451
|
-
if (tailEl) {
|
|
1452
|
-
const elementKey = (0, parse_utils_1.getId)(tailEl);
|
|
1453
|
-
const idRef = new ast.ExprIdReference(this.getFieldPath(pathCx, ast.ExpressionFieldReference));
|
|
1454
|
-
return new ast.RecordElement(elementKey, idRef);
|
|
1455
|
-
}
|
|
1456
|
-
throw this.internalError(pathCx, 'IMPOSSIBLY A PATH CONTAINED ZERO ELEMENTS');
|
|
1449
|
+
const idRef = new ast.ExprIdReference(this.getFieldPath(pcx.fieldPath(), ast.ExpressionFieldReference));
|
|
1450
|
+
return this.astAt(new ast.RecordElement({ path: idRef }), pcx);
|
|
1457
1451
|
}
|
|
1458
1452
|
visitRecordExpr(pcx) {
|
|
1459
|
-
const
|
|
1460
|
-
const
|
|
1461
|
-
|
|
1453
|
+
const value = this.getFieldExpr(pcx.fieldExpr());
|
|
1454
|
+
const keyCx = pcx.recordKey();
|
|
1455
|
+
const recInit = keyCx ? { key: (0, parse_utils_1.getId)(keyCx), value } : { value };
|
|
1456
|
+
return this.astAt(new ast.RecordElement(recInit), pcx);
|
|
1462
1457
|
}
|
|
1463
1458
|
visitExprLiteralRecord(pcx) {
|
|
1464
|
-
const els = this.only(pcx.recordElement().map(elCx => this.astAt(this.visit(elCx), elCx)), visited => visited instanceof ast.RecordElement && visited, 'a
|
|
1459
|
+
const els = this.only(pcx.recordElement().map(elCx => this.astAt(this.visit(elCx), elCx)), visited => visited instanceof ast.RecordElement && visited, 'a legal record property description');
|
|
1465
1460
|
return new ast.RecordLiteral(els);
|
|
1466
1461
|
}
|
|
1467
1462
|
visitExprArrayLiteral(pcx) {
|
package/dist/lang/parse-log.d.ts
CHANGED
|
@@ -324,6 +324,7 @@ type MessageParameterTypes = {
|
|
|
324
324
|
'sql-is-not-null': string;
|
|
325
325
|
'sql-is-null': string;
|
|
326
326
|
'illegal-record-property-type': string;
|
|
327
|
+
'record-literal-needs-keys': string;
|
|
327
328
|
'not-yet-implemented': string;
|
|
328
329
|
'sql-case': string;
|
|
329
330
|
'case-then-type-does-not-match': {
|
|
@@ -271,5 +271,19 @@ describe('literals', () => {
|
|
|
271
271
|
});
|
|
272
272
|
test('a string containing a tab', () => expect((0, test_translator_1.expr) `'\t'`).toParse());
|
|
273
273
|
});
|
|
274
|
+
describe('compound literals', () => {
|
|
275
|
+
test('simple record literal', () => {
|
|
276
|
+
expect('{answer is 42}').compilesTo('{answer:42}');
|
|
277
|
+
});
|
|
278
|
+
test('record literal with path', () => {
|
|
279
|
+
expect('{aninline.column}').compilesTo('{column:aninline.column}');
|
|
280
|
+
});
|
|
281
|
+
test('array of records with same schema', () => {
|
|
282
|
+
expect('[{name is "one", val is 1},{name is "two", val is 2}]').compilesTo('[{name:"one", val:1}, {name:"two", val:2}]');
|
|
283
|
+
});
|
|
284
|
+
test('array of records with head schema', () => {
|
|
285
|
+
expect('[{name is "one", val is 1},{"two", 2}]').compilesTo('[{name:"one", val:1}, {name:"two", val:2}]');
|
|
286
|
+
});
|
|
287
|
+
});
|
|
274
288
|
});
|
|
275
289
|
//# sourceMappingURL=literals.spec.js.map
|
|
@@ -148,6 +148,17 @@ function eToStr(e, symbols) {
|
|
|
148
148
|
return `"${e.literal}"`;
|
|
149
149
|
case 'timeLiteral':
|
|
150
150
|
return `@${e.literal}`;
|
|
151
|
+
case 'recordLiteral': {
|
|
152
|
+
const parts = [];
|
|
153
|
+
for (const [name, val] of Object.entries(e.kids)) {
|
|
154
|
+
parts.push(`${name}:${subExpr(val)}`);
|
|
155
|
+
}
|
|
156
|
+
return `{${parts.join(', ')}}`;
|
|
157
|
+
}
|
|
158
|
+
case 'arrayLiteral': {
|
|
159
|
+
const parts = e.kids.values.map(k => subExpr(k));
|
|
160
|
+
return `[${parts.join(', ')}]`;
|
|
161
|
+
}
|
|
151
162
|
case 'regexpLiteral':
|
|
152
163
|
return `/${e.literal}/`;
|
|
153
164
|
case 'trunc':
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.223";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.223';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|