@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
|
@@ -33,6 +33,7 @@ exports.ArrayLiteral = void 0;
|
|
|
33
33
|
const expr_value_1 = require("../types/expr-value");
|
|
34
34
|
const expression_def_1 = require("../types/expression-def");
|
|
35
35
|
const TDU = __importStar(require("../typedesc-utils"));
|
|
36
|
+
const expr_record_literal_1 = require("./expr-record-literal");
|
|
36
37
|
class ArrayLiteral extends expression_def_1.ExpressionDef {
|
|
37
38
|
constructor(elements) {
|
|
38
39
|
super();
|
|
@@ -46,7 +47,9 @@ class ArrayLiteral extends expression_def_1.ExpressionDef {
|
|
|
46
47
|
let firstValue = undefined;
|
|
47
48
|
if (this.elements.length > 0) {
|
|
48
49
|
for (const nextElement of this.elements) {
|
|
49
|
-
const v = nextElement.
|
|
50
|
+
const v = firstValue && nextElement instanceof expr_record_literal_1.RecordLiteral
|
|
51
|
+
? nextElement.getNextElement(fs, firstValue)
|
|
52
|
+
: nextElement.getExpression(fs);
|
|
50
53
|
fromValues.push(v);
|
|
51
54
|
if (v.type === 'error') {
|
|
52
55
|
continue;
|
|
@@ -2,15 +2,24 @@ import { ExprValue } from '../types/expr-value';
|
|
|
2
2
|
import { ExpressionDef } from '../types/expression-def';
|
|
3
3
|
import { FieldSpace } from '../types/field-space';
|
|
4
4
|
import { MalloyElement } from '../types/malloy-element';
|
|
5
|
+
import { ExprIdReference } from './expr-id-reference';
|
|
6
|
+
export type ElementDetails = {
|
|
7
|
+
path: ExprIdReference;
|
|
8
|
+
} | {
|
|
9
|
+
key?: string;
|
|
10
|
+
value: ExpressionDef;
|
|
11
|
+
};
|
|
5
12
|
export declare class RecordElement extends MalloyElement {
|
|
6
|
-
readonly key: string;
|
|
7
|
-
readonly value: ExpressionDef;
|
|
8
13
|
elementType: string;
|
|
9
|
-
|
|
14
|
+
value: ExpressionDef;
|
|
15
|
+
key?: string;
|
|
16
|
+
constructor(val: ElementDetails);
|
|
10
17
|
}
|
|
11
18
|
export declare class RecordLiteral extends ExpressionDef {
|
|
12
19
|
readonly pairs: RecordElement[];
|
|
13
20
|
elementType: string;
|
|
14
21
|
constructor(pairs: RecordElement[]);
|
|
15
22
|
getExpression(fs: FieldSpace): ExprValue;
|
|
23
|
+
getRecord(fs: FieldSpace, kidNames: string[]): ExprValue;
|
|
24
|
+
getNextElement(fs: FieldSpace, headValue: ExprValue): ExprValue;
|
|
16
25
|
}
|
|
@@ -36,12 +36,22 @@ const expression_def_1 = require("../types/expression-def");
|
|
|
36
36
|
const malloy_element_1 = require("../types/malloy-element");
|
|
37
37
|
const TDU = __importStar(require("../typedesc-utils"));
|
|
38
38
|
class RecordElement extends malloy_element_1.MalloyElement {
|
|
39
|
-
constructor(
|
|
39
|
+
constructor(val) {
|
|
40
40
|
super();
|
|
41
|
-
this.key = key;
|
|
42
|
-
this.value = value;
|
|
43
41
|
this.elementType = 'record element';
|
|
44
|
-
|
|
42
|
+
if ('value' in val) {
|
|
43
|
+
this.value = val.value;
|
|
44
|
+
this.has({ value: val.value });
|
|
45
|
+
if (val.key) {
|
|
46
|
+
this.key = val.key;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.has({ path: val.path });
|
|
51
|
+
this.value = val.path;
|
|
52
|
+
const parts = val.path.fieldReference.path;
|
|
53
|
+
this.key = parts[parts.length - 1];
|
|
54
|
+
}
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
exports.RecordElement = RecordElement;
|
|
@@ -53,6 +63,10 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
|
|
|
53
63
|
this.has({ pairs });
|
|
54
64
|
}
|
|
55
65
|
getExpression(fs) {
|
|
66
|
+
return this.getRecord(fs, []);
|
|
67
|
+
}
|
|
68
|
+
getRecord(fs, kidNames) {
|
|
69
|
+
var _a;
|
|
56
70
|
const recLit = {
|
|
57
71
|
node: 'recordLiteral',
|
|
58
72
|
kids: {},
|
|
@@ -62,15 +76,22 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
|
|
|
62
76
|
},
|
|
63
77
|
};
|
|
64
78
|
const dependents = [];
|
|
79
|
+
let kidIndex = 0;
|
|
65
80
|
for (const el of this.pairs) {
|
|
81
|
+
const key = (_a = el.key) !== null && _a !== void 0 ? _a : kidNames[kidIndex];
|
|
82
|
+
kidIndex += 1;
|
|
83
|
+
if (key === undefined) {
|
|
84
|
+
el.logError('record-literal-needs-keys', 'Anonymous record element not legal here');
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
66
87
|
const xVal = el.value.getExpression(fs);
|
|
67
88
|
if (model_1.TD.isAtomic(xVal)) {
|
|
68
89
|
dependents.push(xVal);
|
|
69
|
-
recLit.kids[
|
|
70
|
-
recLit.typeDef.fields.push((0, model_1.mkFieldDef)(TDU.atomicDef(xVal),
|
|
90
|
+
recLit.kids[key] = xVal.value;
|
|
91
|
+
recLit.typeDef.fields.push((0, model_1.mkFieldDef)(TDU.atomicDef(xVal), key));
|
|
71
92
|
}
|
|
72
93
|
else {
|
|
73
|
-
|
|
94
|
+
el.value.logError('illegal-record-property-type', `Record property '${el.key} is type '${xVal.type}', which is not a legal property value type`);
|
|
74
95
|
}
|
|
75
96
|
}
|
|
76
97
|
return (0, expr_value_1.computedExprValue)({
|
|
@@ -79,6 +100,13 @@ class RecordLiteral extends expression_def_1.ExpressionDef {
|
|
|
79
100
|
from: dependents,
|
|
80
101
|
});
|
|
81
102
|
}
|
|
103
|
+
getNextElement(fs, headValue) {
|
|
104
|
+
const recLit = headValue.value;
|
|
105
|
+
if (recLit.node === 'recordLiteral') {
|
|
106
|
+
return this.getRecord(fs, Object.keys(recLit.kids));
|
|
107
|
+
}
|
|
108
|
+
return this.getRecord(fs, []);
|
|
109
|
+
}
|
|
82
110
|
}
|
|
83
111
|
exports.RecordLiteral = RecordLiteral;
|
|
84
112
|
//# sourceMappingURL=expr-record-literal.js.map
|
|
@@ -2603,9 +2603,9 @@ export declare class RecordRefContext extends RecordElementContext {
|
|
|
2603
2603
|
accept<Result>(visitor: MalloyParserVisitor<Result>): Result;
|
|
2604
2604
|
}
|
|
2605
2605
|
export declare class RecordExprContext extends RecordElementContext {
|
|
2606
|
-
recordKey(): RecordKeyContext;
|
|
2607
|
-
IS(): TerminalNode;
|
|
2608
2606
|
fieldExpr(): FieldExprContext;
|
|
2607
|
+
recordKey(): RecordKeyContext | undefined;
|
|
2608
|
+
IS(): TerminalNode | undefined;
|
|
2609
2609
|
constructor(ctx: RecordElementContext);
|
|
2610
2610
|
enterRule(listener: MalloyParserListener): void;
|
|
2611
2611
|
exitRule(listener: MalloyParserListener): void;
|