Skip to content
Snippets Groups Projects
Unverified Commit d79096cc authored by Tom Robinson's avatar Tom Robinson
Browse files

Disable metrics and cleanup parser error messages

parent f0a1c078
No related branches found
No related tags found
No related merge requests found
...@@ -142,14 +142,18 @@ class ExpressionsParser extends Parser { ...@@ -142,14 +142,18 @@ class ExpressionsParser extends Parser {
$.RULE("atomicExpression", (outsideAggregation) => { $.RULE("atomicExpression", (outsideAggregation) => {
return $.OR([ return $.OR([
// aggregations and metrics are not allowed inside other aggregations // aggregations are not allowed inside other aggregations
{GATE: () => outsideAggregation, ALT: () => $.SUBRULE($.aggregationExpression, [false]) }, {GATE: () => outsideAggregation, ALT: () => $.SUBRULE($.aggregationExpression, [false]) },
{GATE: () => outsideAggregation, ALT: () => $.SUBRULE($.metricExpression) },
// NOTE: DISABLE METRICS
// {GATE: () => outsideAggregation, ALT: () => $.SUBRULE($.metricExpression) },
// fields are not allowed outside aggregations // fields are not allowed outside aggregations
{GATE: () => !outsideAggregation, ALT: () => $.SUBRULE($.fieldExpression) }, {GATE: () => !outsideAggregation, ALT: () => $.SUBRULE($.fieldExpression) },
{ALT: () => $.SUBRULE($.parenthesisExpression, [outsideAggregation]) }, {ALT: () => $.SUBRULE($.parenthesisExpression, [outsideAggregation]) },
{ALT: () => $.SUBRULE($.numberLiteral) } {ALT: () => $.SUBRULE($.numberLiteral) }
]); ], (outsideAggregation ? "aggregation" : "field name") + ", number, or expression");
}); });
$.RULE("parenthesisExpression", (outsideAggregation) => { $.RULE("parenthesisExpression", (outsideAggregation) => {
...@@ -301,6 +305,14 @@ function run(Parser, source, options) { ...@@ -301,6 +305,14 @@ function run(Parser, source, options) {
const parser = new Parser(ExpressionsLexer.tokenize(source).tokens, options); const parser = new Parser(ExpressionsLexer.tokenize(source).tokens, options);
const expression = parser[startRule](); const expression = parser[startRule]();
if (parser.errors.length > 0) { if (parser.errors.length > 0) {
for (const error of parser.errors) {
// clean up error messages
error.message = error.message && error.message
.replace(/^Expecting:?\s+/, "Expected ")
.replace(/--> (.*?) <--/g, "$1")
.replace(/(\n|\s)*but found:?/, " but found ")
.replace(/\s*but found\s+''$/, "");
}
throw parser.errors; throw parser.errors;
} }
return expression; return expression;
...@@ -417,13 +429,14 @@ export function suggest(source, { ...@@ -417,13 +429,14 @@ export function suggest(source, {
postfixTrim: (arity > 0 ? /^\w+(\(\)?|$)/ : /^\w+\s*/) postfixTrim: (arity > 0 ? /^\w+(\(\)?|$)/ : /^\w+\s*/)
}; };
})); }));
finalSuggestions.push(...tableMetadata.metrics.map(metric => ({ // NOTE: DISABLE METRICS
type: "metrics", // finalSuggestions.push(...tableMetadata.metrics.map(metric => ({
name: metric.name, // type: "metrics",
text: formatMetricName(metric), // name: metric.name,
prefixTrim: /\w+$/, // text: formatMetricName(metric),
postfixTrim: /^\w+\s*/ // prefixTrim: /\w+$/,
}))) // postfixTrim: /^\w+\s*/
// })))
} }
} else if (nextTokenType === NumberLiteral) { } else if (nextTokenType === NumberLiteral) {
// skip number literal // skip number literal
......
...@@ -49,8 +49,13 @@ export const NumberLiteral = extendToken("NumberLiteral", /-?(0|[1-9]\d*)(\.\d+) ...@@ -49,8 +49,13 @@ export const NumberLiteral = extendToken("NumberLiteral", /-?(0|[1-9]\d*)(\.\d+)
export const StringLiteral = extendToken("StringLiteral", /"(?:[^\\"]+|\\(?:[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/); export const StringLiteral = extendToken("StringLiteral", /"(?:[^\\"]+|\\(?:[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/);
export const Comma = extendToken('Comma', /,/); export const Comma = extendToken('Comma', /,/);
Comma.LABEL = "comma";
export const LParen = extendToken('LParen', /\(/); export const LParen = extendToken('LParen', /\(/);
LParen.LABEL = "opening parenthesis";
export const RParen = extendToken('RParen', /\)/); export const RParen = extendToken('RParen', /\)/);
RParen.LABEL = "closing parenthesis";
export const WhiteSpace = extendToken("WhiteSpace", /\s+/); export const WhiteSpace = extendToken("WhiteSpace", /\s+/);
WhiteSpace.GROUP = Lexer.SKIPPED; WhiteSpace.GROUP = Lexer.SKIPPED;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment