Skip to content

Commit

Permalink
Parser fuzzing: remove previous limitations which do not apply anymore (
Browse files Browse the repository at this point in the history
metabase#19474)

The previous Chevrotain-based parser had a few limitations, which need
to be taken account by the expression generator for the fuzzer. With the
new recursive parser (PR metabase#19335), these limitations are not necessary
anymore:

* leading decimal digit, e.g. `.25`
* nested negatives, e.g. `-- 3`
* nested boolean NOT, e.g. `NOT NOT X`
  • Loading branch information
ariya authored Jan 5, 2022
1 parent 089fa54 commit b989e95
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions frontend/test/metabase/lib/expressions/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function generateExpression(seed, resultType, depth = 13) {
const zero = () => 0;
const one = () => 1;
const integer = () => randomInt(1e6);
const float = () => String(integer()) + "." + String(integer());
const float1 = () => String(integer()) + ".";
const float2 = () => "." + String(integer());
const float3 = () => String(integer()) + "." + String(integer());

const string = () => '"' + characters() + '"';

Expand Down Expand Up @@ -135,7 +137,7 @@ export function generateExpression(seed, resultType, depth = 13) {

const numberLiteral = () => {
const exp = () => randomItem(["", "-", "+"]) + randomInt(1e2);
const number = () => oneOf([zero, one, integer, float])(); // LIMITATION: no dangling decimal point, e.g. "3."
const number = () => oneOf([zero, one, integer, float1, float2, float3])();
const sci = () => number() + randomItem(["e", "E"]) + exp();
return {
type: NODE.Literal,
Expand All @@ -153,12 +155,11 @@ export function generateExpression(seed, resultType, depth = 13) {
};
};

// LIMITATION: no negative on negative, e.g. "--4"
const unaryMinus = () => {
return {
type: NODE.Unary,
op: "-",
child: oneOf([numberLiteral])(),
child: numberExpression(),
};
};

Expand Down Expand Up @@ -233,12 +234,11 @@ export function generateExpression(seed, resultType, depth = 13) {
return node;
};

// LIMITATION: no NOT on NOT, e.g. "NOT NOT [HighlyRated]"
const logicalNot = () => {
return {
type: NODE.Unary,
op: "NOT ",
child: oneOf([field, comparison, logicalGroup])(),
child: booleanExpression(),
};
};

Expand Down

0 comments on commit b989e95

Please sign in to comment.