tplm-lang 0.3.0 → 0.3.1
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.
|
@@ -322,6 +322,9 @@ class TPLParser extends CstParser {
|
|
|
322
322
|
this.SUBRULE(this.whereExpression);
|
|
323
323
|
});
|
|
324
324
|
// Simplified WHERE expression - captures tokens until ROWS
|
|
325
|
+
// Must accept all tokens that can appear in Malloy filter expressions,
|
|
326
|
+
// including @ for date literals (@2025-01-01), minus for negative numbers
|
|
327
|
+
// and date components, colon for timestamps, and comma for IN lists.
|
|
325
328
|
whereExpression = this.RULE('whereExpression', () => {
|
|
326
329
|
this.AT_LEAST_ONE(() => {
|
|
327
330
|
this.OR([
|
|
@@ -336,6 +339,10 @@ class TPLParser extends CstParser {
|
|
|
336
339
|
{ ALT: () => this.CONSUME(Dot) },
|
|
337
340
|
{ ALT: () => this.CONSUME(LParen) },
|
|
338
341
|
{ ALT: () => this.CONSUME(RParen) },
|
|
342
|
+
{ ALT: () => this.CONSUME(At) }, // Malloy date literals: @2025-01-01
|
|
343
|
+
{ ALT: () => this.CONSUME(Minus) }, // Negative numbers, date separators
|
|
344
|
+
{ ALT: () => this.CONSUME(Colon) }, // Timestamp separators: 10:30:00
|
|
345
|
+
{ ALT: () => this.CONSUME(CommaPunct) }, // IN lists, multiple conditions
|
|
339
346
|
]);
|
|
340
347
|
});
|
|
341
348
|
});
|
|
@@ -939,7 +946,9 @@ class TPLToAstVisitor extends BaseTPLVisitor {
|
|
|
939
946
|
return this.visit(ctx.whereExpression[0]);
|
|
940
947
|
}
|
|
941
948
|
whereExpression(ctx) {
|
|
942
|
-
// Reconstruct the WHERE expression from tokens
|
|
949
|
+
// Reconstruct the WHERE expression from tokens, preserving original spacing.
|
|
950
|
+
// This is important for date literals like @2025-01-01 where tokens (@, 2025, -, 01)
|
|
951
|
+
// must not have spaces inserted between them.
|
|
943
952
|
const allTokens = [];
|
|
944
953
|
for (const key of Object.keys(ctx)) {
|
|
945
954
|
const tokens = ctx[key];
|
|
@@ -947,9 +956,17 @@ class TPLToAstVisitor extends BaseTPLVisitor {
|
|
|
947
956
|
allTokens.push(...tokens);
|
|
948
957
|
}
|
|
949
958
|
}
|
|
950
|
-
// Sort by position
|
|
959
|
+
// Sort by position in the original input
|
|
951
960
|
allTokens.sort((a, b) => a.startOffset - b.startOffset);
|
|
952
|
-
|
|
961
|
+
// Rebuild using original offsets to preserve spacing
|
|
962
|
+
if (allTokens.length === 0)
|
|
963
|
+
return '';
|
|
964
|
+
let result = allTokens[0].image;
|
|
965
|
+
for (let i = 1; i < allTokens.length; i++) {
|
|
966
|
+
const gap = allTokens[i].startOffset - (allTokens[i - 1].startOffset + allTokens[i - 1].image.length);
|
|
967
|
+
result += (gap > 0 ? ' '.repeat(gap) : '') + allTokens[i].image;
|
|
968
|
+
}
|
|
969
|
+
return result;
|
|
953
970
|
}
|
|
954
971
|
axis(ctx) {
|
|
955
972
|
const groups = ctx.groups.map((g) => this.visit(g));
|