From a925bebf97886b961fbf65ee0eb71b8f45d548bb Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 27 Aug 2024 10:03:28 +0200 Subject: [PATCH 01/11] fix expenseType AST node --- src/libs/SearchParser/searchParser.js | 182 +++++++++++------------ src/libs/SearchParser/searchParser.peggy | 2 +- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index 6fd61ffa21b9..a5fd865ee9a3 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -187,23 +187,23 @@ function peg$parse(input, options) { var peg$c4 = "<"; var peg$c5 = "date"; var peg$c6 = "amount"; - var peg$c7 = "expenseType"; - var peg$c8 = "merchant"; - var peg$c9 = "description"; - var peg$c10 = "reportID"; - var peg$c11 = "keyword"; - var peg$c12 = "type"; - var peg$c13 = "status"; - var peg$c14 = "sortBy"; - var peg$c15 = "sortOrder"; - var peg$c16 = "in"; - var peg$c17 = "currency"; - var peg$c18 = "tag"; - var peg$c19 = "category"; - var peg$c20 = "to"; - var peg$c21 = "taxRate"; - var peg$c22 = "cardID"; - var peg$c23 = "from"; + var peg$c7 = "merchant"; + var peg$c8 = "description"; + var peg$c9 = "reportID"; + var peg$c10 = "keyword"; + var peg$c11 = "type"; + var peg$c12 = "status"; + var peg$c13 = "sortBy"; + var peg$c14 = "sortOrder"; + var peg$c15 = "in"; + var peg$c16 = "currency"; + var peg$c17 = "tag"; + var peg$c18 = "category"; + var peg$c19 = "to"; + var peg$c20 = "taxRate"; + var peg$c21 = "cardID"; + var peg$c22 = "from"; + var peg$c23 = "expenseType"; var peg$c24 = "\""; var peg$r0 = /^[:=]/; @@ -220,25 +220,25 @@ function peg$parse(input, options) { var peg$e6 = peg$otherExpectation("key"); var peg$e7 = peg$literalExpectation("date", false); var peg$e8 = peg$literalExpectation("amount", false); - var peg$e9 = peg$literalExpectation("expenseType", false); - var peg$e10 = peg$literalExpectation("merchant", false); - var peg$e11 = peg$literalExpectation("description", false); - var peg$e12 = peg$literalExpectation("reportID", false); - var peg$e13 = peg$literalExpectation("keyword", false); - var peg$e14 = peg$otherExpectation("default key"); - var peg$e15 = peg$literalExpectation("type", false); - var peg$e16 = peg$literalExpectation("status", false); - var peg$e17 = peg$literalExpectation("sortBy", false); - var peg$e18 = peg$literalExpectation("sortOrder", false); - var peg$e19 = peg$otherExpectation("multiselect key"); - var peg$e20 = peg$literalExpectation("in", false); - var peg$e21 = peg$literalExpectation("currency", false); - var peg$e22 = peg$literalExpectation("tag", false); - var peg$e23 = peg$literalExpectation("category", false); - var peg$e24 = peg$literalExpectation("to", false); - var peg$e25 = peg$literalExpectation("taxRate", false); - var peg$e26 = peg$literalExpectation("cardID", false); - var peg$e27 = peg$literalExpectation("from", false); + var peg$e9 = peg$literalExpectation("merchant", false); + var peg$e10 = peg$literalExpectation("description", false); + var peg$e11 = peg$literalExpectation("reportID", false); + var peg$e12 = peg$literalExpectation("keyword", false); + var peg$e13 = peg$otherExpectation("default key"); + var peg$e14 = peg$literalExpectation("type", false); + var peg$e15 = peg$literalExpectation("status", false); + var peg$e16 = peg$literalExpectation("sortBy", false); + var peg$e17 = peg$literalExpectation("sortOrder", false); + var peg$e18 = peg$otherExpectation("multiselect key"); + var peg$e19 = peg$literalExpectation("in", false); + var peg$e20 = peg$literalExpectation("currency", false); + var peg$e21 = peg$literalExpectation("tag", false); + var peg$e22 = peg$literalExpectation("category", false); + var peg$e23 = peg$literalExpectation("to", false); + var peg$e24 = peg$literalExpectation("taxRate", false); + var peg$e25 = peg$literalExpectation("cardID", false); + var peg$e26 = peg$literalExpectation("from", false); + var peg$e27 = peg$literalExpectation("expenseType", false); var peg$e28 = peg$otherExpectation("quote"); var peg$e29 = peg$literalExpectation("\"", false); var peg$e30 = peg$classExpectation(["\"", "\r", "\n"], true, false); @@ -785,46 +785,37 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c7) { + if (input.substr(peg$currPos, 8) === peg$c7) { s1 = peg$c7; - peg$currPos += 11; + peg$currPos += 8; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c8) { + if (input.substr(peg$currPos, 11) === peg$c8) { s1 = peg$c8; - peg$currPos += 8; + peg$currPos += 11; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e10); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c9) { + if (input.substr(peg$currPos, 8) === peg$c9) { s1 = peg$c9; - peg$currPos += 11; + peg$currPos += 8; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e11); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c10) { + if (input.substr(peg$currPos, 7) === peg$c10) { s1 = peg$c10; - peg$currPos += 8; + peg$currPos += 7; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e12); } } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c11) { - s1 = peg$c11; - peg$currPos += 7; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } - } - } } } } @@ -850,36 +841,36 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c12) { - s1 = peg$c12; + if (input.substr(peg$currPos, 4) === peg$c11) { + s1 = peg$c11; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c13) { - s1 = peg$c13; + if (input.substr(peg$currPos, 6) === peg$c12) { + s1 = peg$c12; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c14) { - s1 = peg$c14; + if (input.substr(peg$currPos, 6) === peg$c13) { + s1 = peg$c13; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c15) { - s1 = peg$c15; + if (input.substr(peg$currPos, 9) === peg$c14) { + s1 = peg$c14; peg$currPos += 9; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } } } @@ -893,7 +884,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } return s0; @@ -904,68 +895,77 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c16) { - s1 = peg$c16; + if (input.substr(peg$currPos, 2) === peg$c15) { + s1 = peg$c15; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c17) { - s1 = peg$c17; + if (input.substr(peg$currPos, 8) === peg$c16) { + s1 = peg$c16; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c18) { - s1 = peg$c18; + if (input.substr(peg$currPos, 3) === peg$c17) { + s1 = peg$c17; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c19) { - s1 = peg$c19; + if (input.substr(peg$currPos, 8) === peg$c18) { + s1 = peg$c18; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e22); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c20) { - s1 = peg$c20; + if (input.substr(peg$currPos, 2) === peg$c19) { + s1 = peg$c19; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c21) { - s1 = peg$c21; + if (input.substr(peg$currPos, 7) === peg$c20) { + s1 = peg$c20; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c22) { - s1 = peg$c22; + if (input.substr(peg$currPos, 6) === peg$c21) { + s1 = peg$c21; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c23) { - s1 = peg$c23; + if (input.substr(peg$currPos, 4) === peg$c22) { + s1 = peg$c22; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 11) === peg$c23) { + s1 = peg$c23; + peg$currPos += 11; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e27); } + } } } } @@ -983,7 +983,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } return s0; diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index c6ebc286e635..0f055f967a74 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -131,7 +131,6 @@ key "key" = @( "date" / "amount" - / "expenseType" / "merchant" / "description" / "reportID" @@ -150,6 +149,7 @@ multiselectKey "multiselect key" / "taxRate" / "cardID" / "from" + / "expenseType" ) identifier = parts:(quotedString / alphanumeric)+ { return parts.join(""); } From 652ff67ec4b0c271e80dcf7d54a982dd9b04e676 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 28 Aug 2024 10:49:41 +0200 Subject: [PATCH 02/11] add policyID to grammar --- src/libs/SearchParser/searchParser.js | 424 ++++++++++++++--------- src/libs/SearchParser/searchParser.peggy | 31 +- 2 files changed, 272 insertions(+), 183 deletions(-) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index a5fd865ee9a3..daa5480312d2 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -180,73 +180,77 @@ function peg$parse(input, options) { var peg$startRuleFunctions = { query: peg$parsequery }; var peg$startRuleFunction = peg$parsequery; - var peg$c0 = "!="; - var peg$c1 = ">="; - var peg$c2 = ">"; - var peg$c3 = "<="; - var peg$c4 = "<"; - var peg$c5 = "date"; - var peg$c6 = "amount"; - var peg$c7 = "merchant"; - var peg$c8 = "description"; - var peg$c9 = "reportID"; - var peg$c10 = "keyword"; - var peg$c11 = "type"; - var peg$c12 = "status"; - var peg$c13 = "sortBy"; - var peg$c14 = "sortOrder"; - var peg$c15 = "in"; - var peg$c16 = "currency"; - var peg$c17 = "tag"; - var peg$c18 = "category"; - var peg$c19 = "to"; - var peg$c20 = "taxRate"; - var peg$c21 = "cardID"; - var peg$c22 = "from"; - var peg$c23 = "expenseType"; - var peg$c24 = "\""; + var peg$c0 = "policyID"; + var peg$c1 = "!="; + var peg$c2 = ">="; + var peg$c3 = ">"; + var peg$c4 = "<="; + var peg$c5 = "<"; + var peg$c6 = "date"; + var peg$c7 = "amount"; + var peg$c8 = "merchant"; + var peg$c9 = "description"; + var peg$c10 = "reportID"; + var peg$c11 = "keyword"; + var peg$c12 = "type"; + var peg$c13 = "status"; + var peg$c14 = "sortBy"; + var peg$c15 = "sortOrder"; + var peg$c16 = "in"; + var peg$c17 = "currency"; + var peg$c18 = "tag"; + var peg$c19 = "category"; + var peg$c20 = "to"; + var peg$c21 = "taxRate"; + var peg$c22 = "cardID"; + var peg$c23 = "from"; + var peg$c24 = "expenseType"; + var peg$c25 = "\""; var peg$r0 = /^[:=]/; var peg$r1 = /^[^"\r\n]/; var peg$r2 = /^[A-Za-z0-9_@.\/#&+\-\\',;]/; var peg$r3 = /^[ \t\r\n]/; - var peg$e0 = peg$classExpectation([":", "="], false, false); - var peg$e1 = peg$literalExpectation("!=", false); - var peg$e2 = peg$literalExpectation(">=", false); - var peg$e3 = peg$literalExpectation(">", false); - var peg$e4 = peg$literalExpectation("<=", false); - var peg$e5 = peg$literalExpectation("<", false); - var peg$e6 = peg$otherExpectation("key"); - var peg$e7 = peg$literalExpectation("date", false); - var peg$e8 = peg$literalExpectation("amount", false); - var peg$e9 = peg$literalExpectation("merchant", false); - var peg$e10 = peg$literalExpectation("description", false); - var peg$e11 = peg$literalExpectation("reportID", false); - var peg$e12 = peg$literalExpectation("keyword", false); - var peg$e13 = peg$otherExpectation("default key"); - var peg$e14 = peg$literalExpectation("type", false); - var peg$e15 = peg$literalExpectation("status", false); - var peg$e16 = peg$literalExpectation("sortBy", false); - var peg$e17 = peg$literalExpectation("sortOrder", false); - var peg$e18 = peg$otherExpectation("multiselect key"); - var peg$e19 = peg$literalExpectation("in", false); - var peg$e20 = peg$literalExpectation("currency", false); - var peg$e21 = peg$literalExpectation("tag", false); - var peg$e22 = peg$literalExpectation("category", false); - var peg$e23 = peg$literalExpectation("to", false); - var peg$e24 = peg$literalExpectation("taxRate", false); - var peg$e25 = peg$literalExpectation("cardID", false); - var peg$e26 = peg$literalExpectation("from", false); - var peg$e27 = peg$literalExpectation("expenseType", false); - var peg$e28 = peg$otherExpectation("quote"); - var peg$e29 = peg$literalExpectation("\"", false); - var peg$e30 = peg$classExpectation(["\"", "\r", "\n"], true, false); - var peg$e31 = peg$otherExpectation("word"); - var peg$e32 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false); - var peg$e33 = peg$otherExpectation("and"); - var peg$e34 = peg$otherExpectation("whitespace"); - var peg$e35 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); + var peg$e0 = peg$otherExpectation("policyID filter"); + var peg$e1 = peg$literalExpectation("policyID", false); + var peg$e2 = peg$otherExpectation("operator"); + var peg$e3 = peg$classExpectation([":", "="], false, false); + var peg$e4 = peg$literalExpectation("!=", false); + var peg$e5 = peg$literalExpectation(">=", false); + var peg$e6 = peg$literalExpectation(">", false); + var peg$e7 = peg$literalExpectation("<=", false); + var peg$e8 = peg$literalExpectation("<", false); + var peg$e9 = peg$otherExpectation("policyID"); + var peg$e10 = peg$otherExpectation("key"); + var peg$e11 = peg$literalExpectation("date", false); + var peg$e12 = peg$literalExpectation("amount", false); + var peg$e13 = peg$literalExpectation("merchant", false); + var peg$e14 = peg$literalExpectation("description", false); + var peg$e15 = peg$literalExpectation("reportID", false); + var peg$e16 = peg$literalExpectation("keyword", false); + var peg$e17 = peg$otherExpectation("default key"); + var peg$e18 = peg$literalExpectation("type", false); + var peg$e19 = peg$literalExpectation("status", false); + var peg$e20 = peg$literalExpectation("sortBy", false); + var peg$e21 = peg$literalExpectation("sortOrder", false); + var peg$e22 = peg$otherExpectation("multiselect key"); + var peg$e23 = peg$literalExpectation("in", false); + var peg$e24 = peg$literalExpectation("currency", false); + var peg$e25 = peg$literalExpectation("tag", false); + var peg$e26 = peg$literalExpectation("category", false); + var peg$e27 = peg$literalExpectation("to", false); + var peg$e28 = peg$literalExpectation("taxRate", false); + var peg$e29 = peg$literalExpectation("cardID", false); + var peg$e30 = peg$literalExpectation("from", false); + var peg$e31 = peg$literalExpectation("expenseType", false); + var peg$e32 = peg$otherExpectation("quote"); + var peg$e33 = peg$literalExpectation("\"", false); + var peg$e34 = peg$classExpectation(["\"", "\r", "\n"], true, false); + var peg$e35 = peg$otherExpectation("word"); + var peg$e36 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false); + var peg$e37 = peg$otherExpectation("whitespace"); + var peg$e38 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); var peg$f0 = function(filters) { return applyDefaults(filters); }; var peg$f1 = function(head, tail) { @@ -306,16 +310,19 @@ function peg$parse(input, options) { buildFilter(op, field, values[0]) ); }; - var peg$f6 = function() { return "eq"; }; - var peg$f7 = function() { return "neq"; }; - var peg$f8 = function() { return "gte"; }; - var peg$f9 = function() { return "gt"; }; - var peg$f10 = function() { return "lte"; }; - var peg$f11 = function() { return "lt"; }; - var peg$f12 = function(parts) { return parts.join(""); }; - var peg$f13 = function(chars) { return chars.join(""); }; + var peg$f6 = function(op, value) { + updateDefaultValues(key, value.trim()); + }; + var peg$f7 = function() { return "eq"; }; + var peg$f8 = function() { return "neq"; }; + var peg$f9 = function() { return "gte"; }; + var peg$f10 = function() { return "gt"; }; + var peg$f11 = function() { return "lte"; }; + var peg$f12 = function() { return "lt"; }; + var peg$f13 = function(parts) { return parts.join(""); }; var peg$f14 = function(chars) { return chars.join(""); }; - var peg$f15 = function() { return "and"; }; + var peg$f15 = function(chars) { return chars.join(""); }; + var peg$f16 = function() { return "and"; }; var peg$currPos = options.peg$currPos | 0; var peg$savedPos = peg$currPos; var peg$posDetailsCache = [{ line: 1, column: 1 }]; @@ -545,6 +552,9 @@ function peg$parse(input, options) { s1 = peg$parsemultiSelectFilter(); if (s1 === peg$FAILED) { s1 = peg$parsefreeTextFilter(); + if (s1 === peg$FAILED) { + s1 = peg$parsepolicyIDFilter(); + } } } } @@ -669,90 +679,134 @@ function peg$parse(input, options) { return s0; } + function peg$parsepolicyIDFilter() { + var s0, s1, s2, s3, s4, s5, s6; + + peg$silentFails++; + s0 = peg$currPos; + s1 = peg$parse_(); + if (input.substr(peg$currPos, 8) === peg$c0) { + s2 = peg$c0; + peg$currPos += 8; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e1); } + } + if (s2 !== peg$FAILED) { + s3 = peg$parse_(); + s4 = peg$parseoperator(); + if (s4 !== peg$FAILED) { + s5 = peg$parse_(); + s6 = peg$parseidentifier(); + if (s6 !== peg$FAILED) { + peg$savedPos = s0; + s0 = peg$f6(s4, s6); + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e0); } + } + + return s0; + } + function peg$parseoperator() { var s0, s1; + peg$silentFails++; s0 = peg$currPos; s1 = input.charAt(peg$currPos); if (peg$r0.test(s1)) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f6(); + s1 = peg$f7(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c0) { - s1 = peg$c0; + if (input.substr(peg$currPos, 2) === peg$c1) { + s1 = peg$c1; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f7(); + s1 = peg$f8(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c1) { - s1 = peg$c1; + if (input.substr(peg$currPos, 2) === peg$c2) { + s1 = peg$c2; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f8(); + s1 = peg$f9(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c2; + s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f9(); + s1 = peg$f10(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c3) { - s1 = peg$c3; + if (input.substr(peg$currPos, 2) === peg$c4) { + s1 = peg$c4; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f10(); + s1 = peg$f11(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c4; + s1 = peg$c5; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f11(); + s1 = peg$f12(); } s0 = s1; } @@ -760,6 +814,38 @@ function peg$parse(input, options) { } } } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e2); } + } + + return s0; + } + + function peg$parsepolicyIDKey() { + var s0, s1; + + peg$silentFails++; + s0 = peg$currPos; + if (input.substr(peg$currPos, 8) === peg$c0) { + s1 = peg$c0; + peg$currPos += 8; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e1); } + } + if (s1 !== peg$FAILED) { + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + peg$silentFails--; + if (s0 === peg$FAILED) { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e9); } + } return s0; } @@ -769,52 +855,52 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c5) { - s1 = peg$c5; + if (input.substr(peg$currPos, 4) === peg$c6) { + s1 = peg$c6; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e11); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c6) { - s1 = peg$c6; + if (input.substr(peg$currPos, 6) === peg$c7) { + s1 = peg$c7; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c7) { - s1 = peg$c7; + if (input.substr(peg$currPos, 8) === peg$c8) { + s1 = peg$c8; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c8) { - s1 = peg$c8; + if (input.substr(peg$currPos, 11) === peg$c9) { + s1 = peg$c9; peg$currPos += 11; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c9) { - s1 = peg$c9; + if (input.substr(peg$currPos, 8) === peg$c10) { + s1 = peg$c10; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c10) { - s1 = peg$c10; + if (input.substr(peg$currPos, 7) === peg$c11) { + s1 = peg$c11; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } } } @@ -830,7 +916,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e10); } } return s0; @@ -841,36 +927,36 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c11) { - s1 = peg$c11; + if (input.substr(peg$currPos, 4) === peg$c12) { + s1 = peg$c12; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c12) { - s1 = peg$c12; + if (input.substr(peg$currPos, 6) === peg$c13) { + s1 = peg$c13; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c13) { - s1 = peg$c13; + if (input.substr(peg$currPos, 6) === peg$c14) { + s1 = peg$c14; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c14) { - s1 = peg$c14; + if (input.substr(peg$currPos, 9) === peg$c15) { + s1 = peg$c15; peg$currPos += 9; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } } } @@ -884,7 +970,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } return s0; @@ -895,76 +981,76 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c15) { - s1 = peg$c15; + if (input.substr(peg$currPos, 2) === peg$c16) { + s1 = peg$c16; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c16) { - s1 = peg$c16; + if (input.substr(peg$currPos, 8) === peg$c17) { + s1 = peg$c17; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c17) { - s1 = peg$c17; + if (input.substr(peg$currPos, 3) === peg$c18) { + s1 = peg$c18; peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c18) { - s1 = peg$c18; + if (input.substr(peg$currPos, 8) === peg$c19) { + s1 = peg$c19; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c19) { - s1 = peg$c19; + if (input.substr(peg$currPos, 2) === peg$c20) { + s1 = peg$c20; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e27); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c20) { - s1 = peg$c20; + if (input.substr(peg$currPos, 7) === peg$c21) { + s1 = peg$c21; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e28); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c21) { - s1 = peg$c21; + if (input.substr(peg$currPos, 6) === peg$c22) { + s1 = peg$c22; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e29); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c22) { - s1 = peg$c22; + if (input.substr(peg$currPos, 4) === peg$c23) { + s1 = peg$c23; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } + if (peg$silentFails === 0) { peg$fail(peg$e30); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c23) { - s1 = peg$c23; + if (input.substr(peg$currPos, 11) === peg$c24) { + s1 = peg$c24; peg$currPos += 11; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } + if (peg$silentFails === 0) { peg$fail(peg$e31); } } } } @@ -983,7 +1069,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e22); } } return s0; @@ -1011,7 +1097,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f12(s1); + s1 = peg$f13(s1); } s0 = s1; @@ -1024,11 +1110,11 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c24; + s1 = peg$c25; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } + if (peg$silentFails === 0) { peg$fail(peg$e33); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1037,7 +1123,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -1046,19 +1132,19 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c24; + s3 = peg$c25; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } + if (peg$silentFails === 0) { peg$fail(peg$e33); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f13(s2); + s0 = peg$f14(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1070,7 +1156,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } + if (peg$silentFails === 0) { peg$fail(peg$e32); } } return s0; @@ -1087,7 +1173,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { @@ -1097,7 +1183,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } } } } else { @@ -1105,13 +1191,13 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f14(s1); + s1 = peg$f15(s1); } s0 = s1; peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } return s0; @@ -1120,15 +1206,11 @@ function peg$parse(input, options) { function peg$parselogicalAnd() { var s0, s1; - peg$silentFails++; s0 = peg$currPos; s1 = peg$parse_(); peg$savedPos = s0; - s1 = peg$f15(); + s1 = peg$f16(); s0 = s1; - peg$silentFails--; - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } return s0; } @@ -1143,7 +1225,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e38); } } while (s1 !== peg$FAILED) { s0.push(s1); @@ -1152,12 +1234,12 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e38); } } } peg$silentFails--; s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } return s0; } diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 0f055f967a74..6027a94142a3 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -92,7 +92,14 @@ filterList ); } -filter = @(standardFilter / defaultFilter / multiSelectFilter / freeTextFilter) +filter + = @( + standardFilter + / defaultFilter + / multiSelectFilter + / freeTextFilter + / policyIDFilter + ) defaultFilter = _ key:defaultKey _ op:operator _ value:identifier { @@ -119,7 +126,12 @@ standardFilter ); } -operator +policyIDFilter "policyID filter" + = _ "policyID" _ op:operator _ value:identifier { + updateDefaultValues(key, value.trim()); + } + +operator "operator" = (":" / "=") { return "eq"; } / "!=" { return "neq"; } / ">=" { return "gte"; } @@ -127,15 +139,10 @@ operator / "<=" { return "lte"; } / "<" { return "lt"; } +policyIDKey "policyID" = @"policyID" + key "key" - = @( - "date" - / "amount" - / "merchant" - / "description" - / "reportID" - / "keyword" - ) + = @("date" / "amount" / "merchant" / "description" / "reportID" / "keyword") defaultKey "default key" = @("type" / "status" / "sortBy" / "sortOrder") @@ -159,6 +166,6 @@ quotedString "quote" = "\"" chars:[^"\r\n]* "\"" { return chars.join(""); } alphanumeric "word" = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { return chars.join(""); } -logicalAnd "and" = _ { return "and"; } +logicalAnd = _ { return "and"; } -_ "whitespace" = [ \t\r\n]* +_ "whitespace" = [ \t\r\n]* \ No newline at end of file From 10927cab586d0e4dcc08726b2836bac1ff7ffc8e Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 28 Aug 2024 10:59:47 +0200 Subject: [PATCH 03/11] fix bug --- src/libs/SearchParser/searchParser.js | 92 +++++++++++------------- src/libs/SearchParser/searchParser.peggy | 9 +-- 2 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index daa5480312d2..64ebfd7415fa 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -180,12 +180,12 @@ function peg$parse(input, options) { var peg$startRuleFunctions = { query: peg$parsequery }; var peg$startRuleFunction = peg$parsequery; - var peg$c0 = "policyID"; - var peg$c1 = "!="; - var peg$c2 = ">="; - var peg$c3 = ">"; - var peg$c4 = "<="; - var peg$c5 = "<"; + var peg$c0 = "!="; + var peg$c1 = ">="; + var peg$c2 = ">"; + var peg$c3 = "<="; + var peg$c4 = "<"; + var peg$c5 = "policyID"; var peg$c6 = "date"; var peg$c7 = "amount"; var peg$c8 = "merchant"; @@ -213,15 +213,15 @@ function peg$parse(input, options) { var peg$r3 = /^[ \t\r\n]/; var peg$e0 = peg$otherExpectation("policyID filter"); - var peg$e1 = peg$literalExpectation("policyID", false); - var peg$e2 = peg$otherExpectation("operator"); - var peg$e3 = peg$classExpectation([":", "="], false, false); - var peg$e4 = peg$literalExpectation("!=", false); - var peg$e5 = peg$literalExpectation(">=", false); - var peg$e6 = peg$literalExpectation(">", false); - var peg$e7 = peg$literalExpectation("<=", false); - var peg$e8 = peg$literalExpectation("<", false); - var peg$e9 = peg$otherExpectation("policyID"); + var peg$e1 = peg$otherExpectation("operator"); + var peg$e2 = peg$classExpectation([":", "="], false, false); + var peg$e3 = peg$literalExpectation("!=", false); + var peg$e4 = peg$literalExpectation(">=", false); + var peg$e5 = peg$literalExpectation(">", false); + var peg$e6 = peg$literalExpectation("<=", false); + var peg$e7 = peg$literalExpectation("<", false); + var peg$e8 = peg$otherExpectation("policyID"); + var peg$e9 = peg$literalExpectation("policyID", false); var peg$e10 = peg$otherExpectation("key"); var peg$e11 = peg$literalExpectation("date", false); var peg$e12 = peg$literalExpectation("amount", false); @@ -310,8 +310,8 @@ function peg$parse(input, options) { buildFilter(op, field, values[0]) ); }; - var peg$f6 = function(op, value) { - updateDefaultValues(key, value.trim()); + var peg$f6 = function(field, op, value) { + updateDefaultValues(field, value.trim()); }; var peg$f7 = function() { return "eq"; }; var peg$f8 = function() { return "neq"; }; @@ -545,15 +545,15 @@ function peg$parse(input, options) { var s0, s1; s0 = peg$currPos; - s1 = peg$parsestandardFilter(); + s1 = peg$parsepolicyIDFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsedefaultFilter(); + s1 = peg$parsestandardFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsemultiSelectFilter(); + s1 = peg$parsedefaultFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsefreeTextFilter(); + s1 = peg$parsemultiSelectFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsepolicyIDFilter(); + s1 = peg$parsefreeTextFilter(); } } } @@ -685,13 +685,7 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; s1 = peg$parse_(); - if (input.substr(peg$currPos, 8) === peg$c0) { - s2 = peg$c0; - peg$currPos += 8; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } + s2 = peg$parsepolicyIDKey(); if (s2 !== peg$FAILED) { s3 = peg$parse_(); s4 = peg$parseoperator(); @@ -700,7 +694,7 @@ function peg$parse(input, options) { s6 = peg$parseidentifier(); if (s6 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f6(s4, s6); + s0 = peg$f6(s2, s4, s6); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -732,7 +726,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { peg$fail(peg$e2); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -741,12 +735,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c1) { - s1 = peg$c1; + if (input.substr(peg$currPos, 2) === peg$c0) { + s1 = peg$c0; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -755,12 +749,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c2) { - s1 = peg$c2; + if (input.substr(peg$currPos, 2) === peg$c1) { + s1 = peg$c1; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -770,11 +764,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c3; + s1 = peg$c2; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -783,12 +777,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c4) { - s1 = peg$c4; + if (input.substr(peg$currPos, 2) === peg$c3) { + s1 = peg$c3; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -798,11 +792,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c5; + s1 = peg$c4; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -817,7 +811,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { peg$fail(peg$e1); } } return s0; @@ -828,12 +822,12 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 8) === peg$c0) { - s1 = peg$c0; + if (input.substr(peg$currPos, 8) === peg$c5) { + s1 = peg$c5; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } + if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s1 !== peg$FAILED) { s0 = s1; @@ -844,7 +838,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } return s0; diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 6027a94142a3..0233b98c6843 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -20,6 +20,7 @@ // logicalAnd: rule to match whitespace and return it as a logical 'and' operator // whitespace: rule to match whitespaces + // global initializer (code executed only once) {{ function buildFilter(operator, left, right) { @@ -94,11 +95,11 @@ filterList filter = @( - standardFilter + policyIDFilter + / standardFilter / defaultFilter / multiSelectFilter / freeTextFilter - / policyIDFilter ) defaultFilter @@ -127,8 +128,8 @@ standardFilter } policyIDFilter "policyID filter" - = _ "policyID" _ op:operator _ value:identifier { - updateDefaultValues(key, value.trim()); + = _ field:policyIDKey _ op:operator _ value:identifier { + updateDefaultValues(field, value.trim()); } operator "operator" From bb99c5ee1f9e337c035e5cd46f178b4da8b80c2b Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 28 Aug 2024 11:06:15 +0200 Subject: [PATCH 04/11] add comments to grammar --- src/libs/SearchParser/searchParser.peggy | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 0233b98c6843..4fea302ffe94 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -10,6 +10,7 @@ // freeTextFilter: rule to process the free text search values returned by the identifier rule. It builds filter Object. // multiSelectFilter: rule to process the multi-select values returned by the multiselectKey rule. It builds multiselect filter Object. // standardFilter: rule to process the values returned by the key rule. It builds filter Object. +// policyIDFilter: rule to process the policyIDFilter. It builds filter Object. // operator: rule to match pre-defined search syntax operators, e.g. !=, >, etc // key: rule to match pre-defined search syntax fields that aren't multi-select, e.g. amount, merchant, etc // defaultKey: rule to match pre-defined search syntax fields that are used to update default values, e.g. type, status, etc @@ -128,7 +129,7 @@ standardFilter } policyIDFilter "policyID filter" - = _ field:policyIDKey _ op:operator _ value:identifier { + = _ field:"policyID" _ op:operator _ value:identifier { updateDefaultValues(field, value.trim()); } @@ -140,8 +141,6 @@ operator "operator" / "<=" { return "lte"; } / "<" { return "lt"; } -policyIDKey "policyID" = @"policyID" - key "key" = @("date" / "amount" / "merchant" / "description" / "reportID" / "keyword") From b8d5fea26cec979430d2df263485f66df850ac5b Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 28 Aug 2024 11:18:02 +0200 Subject: [PATCH 05/11] fix merge --- src/libs/SearchParser/searchParser.js | 235 ++++++++++------------- src/libs/SearchParser/searchParser.peggy | 6 +- 2 files changed, 101 insertions(+), 140 deletions(-) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index 32f1a4b144fa..dd69e4e74313 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -180,12 +180,12 @@ function peg$parse(input, options) { var peg$startRuleFunctions = { query: peg$parsequery }; var peg$startRuleFunction = peg$parsequery; - var peg$c0 = "!="; - var peg$c1 = ">="; - var peg$c2 = ">"; - var peg$c3 = "<="; - var peg$c4 = "<"; - var peg$c5 = "policyID"; + var peg$c0 = "policyID"; + var peg$c1 = "!="; + var peg$c2 = ">="; + var peg$c3 = ">"; + var peg$c4 = "<="; + var peg$c5 = "<"; var peg$c6 = "date"; var peg$c7 = "amount"; var peg$c8 = "merchant"; @@ -213,53 +213,45 @@ function peg$parse(input, options) { var peg$r3 = /^[ \t\r\n]/; var peg$e0 = peg$otherExpectation("policyID filter"); - var peg$e1 = peg$otherExpectation("operator"); - var peg$e2 = peg$classExpectation([":", "="], false, false); - var peg$e3 = peg$literalExpectation("!=", false); - var peg$e4 = peg$literalExpectation(">=", false); - var peg$e5 = peg$literalExpectation(">", false); - var peg$e6 = peg$literalExpectation("<=", false); - var peg$e7 = peg$literalExpectation("<", false); - var peg$e8 = peg$otherExpectation("policyID"); - var peg$e9 = peg$literalExpectation("policyID", false); - var peg$e10 = peg$otherExpectation("key"); - var peg$e11 = peg$literalExpectation("date", false); - var peg$e12 = peg$literalExpectation("amount", false); - var peg$e13 = peg$literalExpectation("merchant", false); - var peg$e14 = peg$literalExpectation("description", false); - var peg$e15 = peg$literalExpectation("reportID", false); - var peg$e16 = peg$literalExpectation("keyword", false); - var peg$e17 = peg$otherExpectation("default key"); - var peg$e18 = peg$literalExpectation("type", false); - var peg$e19 = peg$literalExpectation("status", false); - var peg$e20 = peg$literalExpectation("sortBy", false); - var peg$e21 = peg$literalExpectation("sortOrder", false); - var peg$e22 = peg$otherExpectation("multiselect key"); - var peg$e23 = peg$literalExpectation("in", false); - var peg$e24 = peg$literalExpectation("currency", false); - var peg$e25 = peg$literalExpectation("tag", false); - var peg$e26 = peg$literalExpectation("category", false); - var peg$e27 = peg$literalExpectation("to", false); - var peg$e28 = peg$literalExpectation("taxRate", false); - var peg$e29 = peg$literalExpectation("cardID", false); - var peg$e30 = peg$literalExpectation("from", false); - var peg$e31 = peg$literalExpectation("expenseType", false); - var peg$e32 = peg$otherExpectation("quote"); - var peg$e33 = peg$literalExpectation("\"", false); - var peg$e34 = peg$classExpectation(["\"", "\r", "\n"], true, false); - var peg$e35 = peg$otherExpectation("word"); - var peg$e36 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false); - var peg$e37 = peg$otherExpectation("whitespace"); - var peg$e38 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); - - var peg$f0 = function(filters) { - const withDefaults = applyDefaults(filters); - if (defaultValues.policyID) { - return applyPolicyID(withDefaults); - } - - return withDefaults; - }; + var peg$e1 = peg$literalExpectation("policyID", false); + var peg$e2 = peg$otherExpectation("operator"); + var peg$e3 = peg$classExpectation([":", "="], false, false); + var peg$e4 = peg$literalExpectation("!=", false); + var peg$e5 = peg$literalExpectation(">=", false); + var peg$e6 = peg$literalExpectation(">", false); + var peg$e7 = peg$literalExpectation("<=", false); + var peg$e8 = peg$literalExpectation("<", false); + var peg$e9 = peg$otherExpectation("key"); + var peg$e10 = peg$literalExpectation("date", false); + var peg$e11 = peg$literalExpectation("amount", false); + var peg$e12 = peg$literalExpectation("merchant", false); + var peg$e13 = peg$literalExpectation("description", false); + var peg$e14 = peg$literalExpectation("reportID", false); + var peg$e15 = peg$literalExpectation("keyword", false); + var peg$e16 = peg$otherExpectation("default key"); + var peg$e17 = peg$literalExpectation("type", false); + var peg$e18 = peg$literalExpectation("status", false); + var peg$e19 = peg$literalExpectation("sortBy", false); + var peg$e20 = peg$literalExpectation("sortOrder", false); + var peg$e21 = peg$otherExpectation("multiselect key"); + var peg$e22 = peg$literalExpectation("in", false); + var peg$e23 = peg$literalExpectation("currency", false); + var peg$e24 = peg$literalExpectation("tag", false); + var peg$e25 = peg$literalExpectation("category", false); + var peg$e26 = peg$literalExpectation("to", false); + var peg$e27 = peg$literalExpectation("taxRate", false); + var peg$e28 = peg$literalExpectation("cardID", false); + var peg$e29 = peg$literalExpectation("from", false); + var peg$e30 = peg$literalExpectation("expenseType", false); + var peg$e31 = peg$otherExpectation("quote"); + var peg$e32 = peg$literalExpectation("\"", false); + var peg$e33 = peg$classExpectation(["\"", "\r", "\n"], true, false); + var peg$e34 = peg$otherExpectation("word"); + var peg$e35 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false); + var peg$e36 = peg$otherExpectation("whitespace"); + var peg$e37 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false); + + var peg$f0 = function(filters) { return applyDefaults(filters); }; var peg$f1 = function(head, tail) { const allFilters = [head, ...tail.map(([_, filter]) => filter)] .filter((filter) => filter !== null) @@ -295,10 +287,6 @@ function peg$parse(input, options) { buildFilter("and", result, filter) ) ); - - return allFilters.reduce((result, filter) => - buildFilter("and", result, filter) - ); }; var peg$f2 = function(key, op, value) { updateDefaultValues(key, value.trim()); @@ -692,7 +680,13 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; s1 = peg$parse_(); - s2 = peg$parsepolicyIDKey(); + if (input.substr(peg$currPos, 8) === peg$c0) { + s2 = peg$c0; + peg$currPos += 8; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e1); } + } if (s2 !== peg$FAILED) { s3 = peg$parse_(); s4 = peg$parseoperator(); @@ -733,7 +727,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -742,12 +736,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c0) { - s1 = peg$c0; + if (input.substr(peg$currPos, 2) === peg$c1) { + s1 = peg$c1; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -756,12 +750,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c1) { - s1 = peg$c1; + if (input.substr(peg$currPos, 2) === peg$c2) { + s1 = peg$c2; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -771,11 +765,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c2; + s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -784,12 +778,12 @@ function peg$parse(input, options) { s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c3) { - s1 = peg$c3; + if (input.substr(peg$currPos, 2) === peg$c4) { + s1 = peg$c4; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -799,11 +793,11 @@ function peg$parse(input, options) { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c4; + s1 = peg$c5; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; @@ -818,34 +812,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - - return s0; - } - - function peg$parsepolicyIDKey() { - var s0, s1; - - peg$silentFails++; - s0 = peg$currPos; - if (input.substr(peg$currPos, 8) === peg$c5) { - s1 = peg$c5; - peg$currPos += 8; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } - } - if (s1 !== peg$FAILED) { - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { peg$fail(peg$e2); } } return s0; @@ -861,7 +828,7 @@ function peg$parse(input, options) { peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } + if (peg$silentFails === 0) { peg$fail(peg$e10); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c7) { @@ -869,7 +836,7 @@ function peg$parse(input, options) { peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { peg$fail(peg$e11); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 8) === peg$c8) { @@ -877,7 +844,7 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 11) === peg$c9) { @@ -885,7 +852,7 @@ function peg$parse(input, options) { peg$currPos += 11; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 8) === peg$c10) { @@ -893,7 +860,7 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e14); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c11) { @@ -901,7 +868,7 @@ function peg$parse(input, options) { peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } + if (peg$silentFails === 0) { peg$fail(peg$e15); } } } } @@ -917,7 +884,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } + if (peg$silentFails === 0) { peg$fail(peg$e9); } } return s0; @@ -933,7 +900,7 @@ function peg$parse(input, options) { peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e17); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c13) { @@ -941,7 +908,7 @@ function peg$parse(input, options) { peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e18); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c14) { @@ -949,7 +916,7 @@ function peg$parse(input, options) { peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } + if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 9) === peg$c15) { @@ -957,7 +924,7 @@ function peg$parse(input, options) { peg$currPos += 9; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } + if (peg$silentFails === 0) { peg$fail(peg$e20); } } } } @@ -971,7 +938,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e16); } } return s0; @@ -987,7 +954,7 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } + if (peg$silentFails === 0) { peg$fail(peg$e22); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 8) === peg$c17) { @@ -995,7 +962,7 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } + if (peg$silentFails === 0) { peg$fail(peg$e23); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c18) { @@ -1003,7 +970,7 @@ function peg$parse(input, options) { peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e24); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 8) === peg$c19) { @@ -1011,7 +978,7 @@ function peg$parse(input, options) { peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c20) { @@ -1019,7 +986,7 @@ function peg$parse(input, options) { peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 7) === peg$c21) { @@ -1027,7 +994,7 @@ function peg$parse(input, options) { peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } + if (peg$silentFails === 0) { peg$fail(peg$e27); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 6) === peg$c22) { @@ -1035,7 +1002,7 @@ function peg$parse(input, options) { peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } + if (peg$silentFails === 0) { peg$fail(peg$e28); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c23) { @@ -1043,7 +1010,7 @@ function peg$parse(input, options) { peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } + if (peg$silentFails === 0) { peg$fail(peg$e29); } } if (s1 === peg$FAILED) { if (input.substr(peg$currPos, 11) === peg$c24) { @@ -1051,7 +1018,7 @@ function peg$parse(input, options) { peg$currPos += 11; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } + if (peg$silentFails === 0) { peg$fail(peg$e30); } } } } @@ -1070,7 +1037,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } + if (peg$silentFails === 0) { peg$fail(peg$e21); } } return s0; @@ -1111,12 +1078,11 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c25; s1 = peg$c25; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } + if (peg$silentFails === 0) { peg$fail(peg$e32); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1125,7 +1091,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } + if (peg$silentFails === 0) { peg$fail(peg$e33); } } while (s3 !== peg$FAILED) { s2.push(s3); @@ -1134,16 +1100,15 @@ function peg$parse(input, options) { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e34); } + if (peg$silentFails === 0) { peg$fail(peg$e33); } } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c25; s3 = peg$c25; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e33); } + if (peg$silentFails === 0) { peg$fail(peg$e32); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; @@ -1159,7 +1124,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } + if (peg$silentFails === 0) { peg$fail(peg$e31); } } return s0; @@ -1176,7 +1141,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { @@ -1186,7 +1151,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e36); } + if (peg$silentFails === 0) { peg$fail(peg$e35); } } } } else { @@ -1200,7 +1165,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e35); } + if (peg$silentFails === 0) { peg$fail(peg$e34); } } return s0; @@ -1228,7 +1193,7 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } } while (s1 !== peg$FAILED) { s0.push(s1); @@ -1237,12 +1202,12 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e38); } + if (peg$silentFails === 0) { peg$fail(peg$e37); } } } peg$silentFails--; s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e37); } + if (peg$silentFails === 0) { peg$fail(peg$e36); } return s0; } diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 4fea302ffe94..2cd86bd982d6 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -10,7 +10,7 @@ // freeTextFilter: rule to process the free text search values returned by the identifier rule. It builds filter Object. // multiSelectFilter: rule to process the multi-select values returned by the multiselectKey rule. It builds multiselect filter Object. // standardFilter: rule to process the values returned by the key rule. It builds filter Object. -// policyIDFilter: rule to process the policyIDFilter. It builds filter Object. +// policyIDFilter: rule to process the policyID. It builds filter Object. // operator: rule to match pre-defined search syntax operators, e.g. !=, >, etc // key: rule to match pre-defined search syntax fields that aren't multi-select, e.g. amount, merchant, etc // defaultKey: rule to match pre-defined search syntax fields that are used to update default values, e.g. type, status, etc @@ -88,10 +88,6 @@ filterList buildFilter("and", result, filter) ) ); - - return allFilters.reduce((result, filter) => - buildFilter("and", result, filter) - ); } filter From 7210342cc19bdef57c3d20ee764648ad8a73b19c Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 28 Aug 2024 11:29:15 +0200 Subject: [PATCH 06/11] fix spaces --- src/libs/SearchParser/searchParser.peggy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 2cd86bd982d6..3e9d7906a31d 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -21,7 +21,6 @@ // logicalAnd: rule to match whitespace and return it as a logical 'and' operator // whitespace: rule to match whitespaces - // global initializer (code executed only once) {{ function buildFilter(operator, left, right) { @@ -164,4 +163,4 @@ alphanumeric "word" logicalAnd = _ { return "and"; } -_ "whitespace" = [ \t\r\n]* \ No newline at end of file +_ "whitespace" = [ \t\r\n]* From 5098cd5d4de60bd3e786a1831dbed1e0a434a220 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Sep 2024 16:31:01 +0200 Subject: [PATCH 07/11] array in multiselect node --- src/components/Search/types.ts | 9 +- src/libs/SearchParser/searchParser.js | 602 ++++++++++------------- src/libs/SearchParser/searchParser.peggy | 97 ++-- src/libs/SearchUtils.ts | 32 +- 4 files changed, 335 insertions(+), 405 deletions(-) diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index 9f2aca1ff957..a7d8fcbdae3c 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -41,7 +41,7 @@ type SearchContext = { type ASTNode = { operator: ValueOf; left: ValueOf | ASTNode; - right: string | ASTNode; + right: string | ASTNode | string[]; }; type QueryFilter = { @@ -71,6 +71,13 @@ type SearchQueryJSON = { hash: number; } & SearchQueryAST; +type NewQueryFilter = { + operator: ValueOf; + value: string[]; +}; + +type NewFilter = NewQueryFilter[]; + export type { SelectedTransactionInfo, SelectedTransactions, diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index dd69e4e74313..32fd834c1346 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -180,69 +180,71 @@ function peg$parse(input, options) { var peg$startRuleFunctions = { query: peg$parsequery }; var peg$startRuleFunction = peg$parsequery; - var peg$c0 = "policyID"; - var peg$c1 = "!="; - var peg$c2 = ">="; - var peg$c3 = ">"; - var peg$c4 = "<="; - var peg$c5 = "<"; - var peg$c6 = "date"; - var peg$c7 = "amount"; - var peg$c8 = "merchant"; - var peg$c9 = "description"; - var peg$c10 = "reportID"; - var peg$c11 = "keyword"; - var peg$c12 = "type"; - var peg$c13 = "status"; - var peg$c14 = "sortBy"; - var peg$c15 = "sortOrder"; - var peg$c16 = "in"; - var peg$c17 = "currency"; - var peg$c18 = "tag"; - var peg$c19 = "category"; - var peg$c20 = "to"; - var peg$c21 = "taxRate"; - var peg$c22 = "cardID"; - var peg$c23 = "from"; - var peg$c24 = "expenseType"; - var peg$c25 = "\""; + var peg$c0 = "!="; + var peg$c1 = ">="; + var peg$c2 = ">"; + var peg$c3 = "<="; + var peg$c4 = "<"; + var peg$c5 = "date"; + var peg$c6 = "amount"; + var peg$c7 = "merchant"; + var peg$c8 = "description"; + var peg$c9 = "reportID"; + var peg$c10 = "keyword"; + var peg$c11 = "in"; + var peg$c12 = "currency"; + var peg$c13 = "tag"; + var peg$c14 = "category"; + var peg$c15 = "to"; + var peg$c16 = "taxRate"; + var peg$c17 = "cardID"; + var peg$c18 = "from"; + var peg$c19 = "expenseType"; + var peg$c20 = "has"; + var peg$c21 = "is"; + var peg$c22 = "type"; + var peg$c23 = "status"; + var peg$c24 = "sortBy"; + var peg$c25 = "sortOrder"; + var peg$c26 = "policyID"; + var peg$c27 = "\""; var peg$r0 = /^[:=]/; var peg$r1 = /^[^"\r\n]/; var peg$r2 = /^[A-Za-z0-9_@.\/#&+\-\\',;]/; var peg$r3 = /^[ \t\r\n]/; - var peg$e0 = peg$otherExpectation("policyID filter"); - var peg$e1 = peg$literalExpectation("policyID", false); - var peg$e2 = peg$otherExpectation("operator"); - var peg$e3 = peg$classExpectation([":", "="], false, false); - var peg$e4 = peg$literalExpectation("!=", false); - var peg$e5 = peg$literalExpectation(">=", false); - var peg$e6 = peg$literalExpectation(">", false); - var peg$e7 = peg$literalExpectation("<=", false); - var peg$e8 = peg$literalExpectation("<", false); - var peg$e9 = peg$otherExpectation("key"); - var peg$e10 = peg$literalExpectation("date", false); - var peg$e11 = peg$literalExpectation("amount", false); - var peg$e12 = peg$literalExpectation("merchant", false); - var peg$e13 = peg$literalExpectation("description", false); - var peg$e14 = peg$literalExpectation("reportID", false); - var peg$e15 = peg$literalExpectation("keyword", false); - var peg$e16 = peg$otherExpectation("default key"); - var peg$e17 = peg$literalExpectation("type", false); - var peg$e18 = peg$literalExpectation("status", false); - var peg$e19 = peg$literalExpectation("sortBy", false); - var peg$e20 = peg$literalExpectation("sortOrder", false); - var peg$e21 = peg$otherExpectation("multiselect key"); - var peg$e22 = peg$literalExpectation("in", false); - var peg$e23 = peg$literalExpectation("currency", false); - var peg$e24 = peg$literalExpectation("tag", false); - var peg$e25 = peg$literalExpectation("category", false); - var peg$e26 = peg$literalExpectation("to", false); - var peg$e27 = peg$literalExpectation("taxRate", false); - var peg$e28 = peg$literalExpectation("cardID", false); - var peg$e29 = peg$literalExpectation("from", false); - var peg$e30 = peg$literalExpectation("expenseType", false); + var peg$e0 = peg$otherExpectation("operator"); + var peg$e1 = peg$classExpectation([":", "="], false, false); + var peg$e2 = peg$literalExpectation("!=", false); + var peg$e3 = peg$literalExpectation(">=", false); + var peg$e4 = peg$literalExpectation(">", false); + var peg$e5 = peg$literalExpectation("<=", false); + var peg$e6 = peg$literalExpectation("<", false); + var peg$e7 = peg$otherExpectation("key"); + var peg$e8 = peg$literalExpectation("date", false); + var peg$e9 = peg$literalExpectation("amount", false); + var peg$e10 = peg$literalExpectation("merchant", false); + var peg$e11 = peg$literalExpectation("description", false); + var peg$e12 = peg$literalExpectation("reportID", false); + var peg$e13 = peg$literalExpectation("keyword", false); + var peg$e14 = peg$literalExpectation("in", false); + var peg$e15 = peg$literalExpectation("currency", false); + var peg$e16 = peg$literalExpectation("tag", false); + var peg$e17 = peg$literalExpectation("category", false); + var peg$e18 = peg$literalExpectation("to", false); + var peg$e19 = peg$literalExpectation("taxRate", false); + var peg$e20 = peg$literalExpectation("cardID", false); + var peg$e21 = peg$literalExpectation("from", false); + var peg$e22 = peg$literalExpectation("expenseType", false); + var peg$e23 = peg$literalExpectation("has", false); + var peg$e24 = peg$literalExpectation("is", false); + var peg$e25 = peg$otherExpectation("default key"); + var peg$e26 = peg$literalExpectation("type", false); + var peg$e27 = peg$literalExpectation("status", false); + var peg$e28 = peg$literalExpectation("sortBy", false); + var peg$e29 = peg$literalExpectation("sortOrder", false); + var peg$e30 = peg$literalExpectation("policyID", false); var peg$e31 = peg$otherExpectation("quote"); var peg$e32 = peg$literalExpectation("\"", false); var peg$e33 = peg$classExpectation(["\"", "\r", "\n"], true, false); @@ -254,8 +256,8 @@ function peg$parse(input, options) { var peg$f0 = function(filters) { return applyDefaults(filters); }; var peg$f1 = function(head, tail) { const allFilters = [head, ...tail.map(([_, filter]) => filter)] - .filter((filter) => filter !== null) - .filter(Boolean); + .filter(Boolean) + .filter((filter) => filter.right); if (!allFilters.length) { return null; } @@ -269,55 +271,43 @@ function peg$parse(input, options) { filter.left !== "keyword" && filter.right?.left !== "keyword" ); - if (!nonKeywords.length) { - return keywords.reduce((result, filter) => - buildFilter("or", result, filter) - ); - } - if (!keywords.length) { - return nonKeywords.reduce((result, filter) => - buildFilter("and", result, filter) - ); + const keywordFilter = buildFilter( + "eq", + "keyword", + keywords.map((filter) => filter.right).flat() + ); + if (keywordFilter.right.length > 0) { + nonKeywords.push(keywordFilter); } - - return buildFilter( - "and", - keywords.reduce((result, filter) => buildFilter("or", result, filter)), - nonKeywords.reduce((result, filter) => - buildFilter("and", result, filter) - ) + return nonKeywords.reduce((result, filter) => + buildFilter("and", result, filter) ); }; var peg$f2 = function(key, op, value) { - updateDefaultValues(key, value.trim()); + updateDefaultValues(key, value); }; - var peg$f3 = function(value) { return buildFilter("eq", "keyword", value.trim()); }; - var peg$f4 = function(field, op, value) { - return buildFilter(op, field, value); + var peg$f3 = function(value) { return buildFilter("eq", "keyword", value); }; + var peg$f4 = function(field, op, values) { + return buildFilter(op, field, values); }; - var peg$f5 = function(field, op, value) { - const values = value.split(","); - return values - .slice(1) - .reduce( - (acc, val) => - buildFilter("or", acc, buildFilter(op, field, val.trim())), - buildFilter(op, field, values[0]) - ); + var peg$f5 = function() { return "eq"; }; + var peg$f6 = function() { return "neq"; }; + var peg$f7 = function() { return "gte"; }; + var peg$f8 = function() { return "gt"; }; + var peg$f9 = function() { return "lte"; }; + var peg$f10 = function() { return "lt"; }; + var peg$f11 = function(parts) { + const value = parts.flat(); + if (value.length > 1) { + return value; + } + return value[0]; }; - var peg$f6 = function(field, op, value) { - updateDefaultValues(field, value.trim()); + var peg$f12 = function(chars) { return chars.join(""); }; + var peg$f13 = function(chars) { + return chars.join("").trim().split(",").filter(Boolean); }; - var peg$f7 = function() { return "eq"; }; - var peg$f8 = function() { return "neq"; }; - var peg$f9 = function() { return "gte"; }; - var peg$f10 = function() { return "gt"; }; - var peg$f11 = function() { return "lte"; }; - var peg$f12 = function() { return "lt"; }; - var peg$f13 = function(parts) { return parts.join(""); }; - var peg$f14 = function(chars) { return chars.join(""); }; - var peg$f15 = function(chars) { return chars.join(""); }; - var peg$f16 = function() { return "and"; }; + var peg$f14 = function() { return "and"; }; var peg$currPos = options.peg$currPos | 0; var peg$savedPos = peg$currPos; var peg$posDetailsCache = [{ line: 1, column: 1 }]; @@ -540,17 +530,11 @@ function peg$parse(input, options) { var s0, s1; s0 = peg$currPos; - s1 = peg$parsepolicyIDFilter(); + s1 = peg$parsestandardFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsestandardFilter(); + s1 = peg$parsedefaultFilter(); if (s1 === peg$FAILED) { - s1 = peg$parsedefaultFilter(); - if (s1 === peg$FAILED) { - s1 = peg$parsemultiSelectFilter(); - if (s1 === peg$FAILED) { - s1 = peg$parsefreeTextFilter(); - } - } + s1 = peg$parsefreeTextFilter(); } } if (s1 !== peg$FAILED) { @@ -612,37 +596,6 @@ function peg$parse(input, options) { return s0; } - function peg$parsemultiSelectFilter() { - var s0, s1, s2, s3, s4, s5, s6; - - s0 = peg$currPos; - s1 = peg$parse_(); - s2 = peg$parsemultiselectKey(); - if (s2 !== peg$FAILED) { - s3 = peg$parse_(); - s4 = peg$parseoperator(); - if (s4 !== peg$FAILED) { - s5 = peg$parse_(); - s6 = peg$parseidentifier(); - if (s6 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f4(s2, s4, s6); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - function peg$parsestandardFilter() { var s0, s1, s2, s3, s4, s5, s6; @@ -657,45 +610,7 @@ function peg$parse(input, options) { s6 = peg$parseidentifier(); if (s6 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f5(s2, s4, s6); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parsepolicyIDFilter() { - var s0, s1, s2, s3, s4, s5, s6; - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$parse_(); - if (input.substr(peg$currPos, 8) === peg$c0) { - s2 = peg$c0; - peg$currPos += 8; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s2 !== peg$FAILED) { - s3 = peg$parse_(); - s4 = peg$parseoperator(); - if (s4 !== peg$FAILED) { - s5 = peg$parse_(); - s6 = peg$parseidentifier(); - if (s6 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f6(s2, s4, s6); + s0 = peg$f4(s2, s4, s6); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -708,11 +623,6 @@ function peg$parse(input, options) { peg$currPos = s0; s0 = peg$FAILED; } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } return s0; } @@ -727,81 +637,81 @@ function peg$parse(input, options) { peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } + if (peg$silentFails === 0) { peg$fail(peg$e1); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f7(); + s1 = peg$f5(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c1) { - s1 = peg$c1; + if (input.substr(peg$currPos, 2) === peg$c0) { + s1 = peg$c0; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } + if (peg$silentFails === 0) { peg$fail(peg$e2); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f8(); + s1 = peg$f6(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c2) { - s1 = peg$c2; + if (input.substr(peg$currPos, 2) === peg$c1) { + s1 = peg$c1; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } + if (peg$silentFails === 0) { peg$fail(peg$e3); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f9(); + s1 = peg$f7(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c3; + s1 = peg$c2; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } + if (peg$silentFails === 0) { peg$fail(peg$e4); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f10(); + s1 = peg$f8(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c4) { - s1 = peg$c4; + if (input.substr(peg$currPos, 2) === peg$c3) { + s1 = peg$c3; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } + if (peg$silentFails === 0) { peg$fail(peg$e5); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f11(); + s1 = peg$f9(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c5; + s1 = peg$c4; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } + if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f12(); + s1 = peg$f10(); } s0 = s1; } @@ -812,7 +722,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } + if (peg$silentFails === 0) { peg$fail(peg$e0); } } return s0; @@ -823,52 +733,160 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c6) { - s1 = peg$c6; + if (input.substr(peg$currPos, 4) === peg$c5) { + s1 = peg$c5; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } + if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c7) { - s1 = peg$c7; + if (input.substr(peg$currPos, 6) === peg$c6) { + s1 = peg$c6; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } + if (peg$silentFails === 0) { peg$fail(peg$e9); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c8) { - s1 = peg$c8; + if (input.substr(peg$currPos, 8) === peg$c7) { + s1 = peg$c7; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } + if (peg$silentFails === 0) { peg$fail(peg$e10); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c9) { - s1 = peg$c9; + if (input.substr(peg$currPos, 11) === peg$c8) { + s1 = peg$c8; peg$currPos += 11; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } + if (peg$silentFails === 0) { peg$fail(peg$e11); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c10) { - s1 = peg$c10; + if (input.substr(peg$currPos, 8) === peg$c9) { + s1 = peg$c9; peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } + if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c11) { - s1 = peg$c11; + if (input.substr(peg$currPos, 7) === peg$c10) { + s1 = peg$c10; peg$currPos += 7; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } + if (peg$silentFails === 0) { peg$fail(peg$e13); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c11) { + s1 = peg$c11; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e14); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 8) === peg$c12) { + s1 = peg$c12; + peg$currPos += 8; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e15); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c13) { + s1 = peg$c13; + peg$currPos += 3; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e16); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 8) === peg$c14) { + s1 = peg$c14; + peg$currPos += 8; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e17); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c15) { + s1 = peg$c15; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e18); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 7) === peg$c16) { + s1 = peg$c16; + peg$currPos += 7; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e19); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 6) === peg$c17) { + s1 = peg$c17; + peg$currPos += 6; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e20); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 4) === peg$c18) { + s1 = peg$c18; + peg$currPos += 4; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e21); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 11) === peg$c19) { + s1 = peg$c19; + peg$currPos += 11; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e22); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c20) { + s1 = peg$c20; + peg$currPos += 3; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e23); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c11) { + s1 = peg$c11; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e14); } + } + if (s1 === peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c21) { + s1 = peg$c21; + peg$currPos += 2; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$e24); } + } + } + } + } + } + } + } + } + } + } + } + } } } } @@ -884,7 +902,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } + if (peg$silentFails === 0) { peg$fail(peg$e7); } } return s0; @@ -895,134 +913,44 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; - if (input.substr(peg$currPos, 4) === peg$c12) { - s1 = peg$c12; + if (input.substr(peg$currPos, 4) === peg$c22) { + s1 = peg$c22; peg$currPos += 4; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } + if (peg$silentFails === 0) { peg$fail(peg$e26); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c13) { - s1 = peg$c13; + if (input.substr(peg$currPos, 6) === peg$c23) { + s1 = peg$c23; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } + if (peg$silentFails === 0) { peg$fail(peg$e27); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c14) { - s1 = peg$c14; + if (input.substr(peg$currPos, 6) === peg$c24) { + s1 = peg$c24; peg$currPos += 6; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } + if (peg$silentFails === 0) { peg$fail(peg$e28); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c15) { - s1 = peg$c15; + if (input.substr(peg$currPos, 9) === peg$c25) { + s1 = peg$c25; peg$currPos += 9; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } - } - } - } - } - if (s1 !== peg$FAILED) { - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } - } - - return s0; - } - - function peg$parsemultiselectKey() { - var s0, s1; - - peg$silentFails++; - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c16) { - s1 = peg$c16; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c17) { - s1 = peg$c17; - peg$currPos += 8; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c18) { - s1 = peg$c18; - peg$currPos += 3; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c19) { - s1 = peg$c19; - peg$currPos += 8; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } + if (peg$silentFails === 0) { peg$fail(peg$e29); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 2) === peg$c20) { - s1 = peg$c20; - peg$currPos += 2; + if (input.substr(peg$currPos, 8) === peg$c26) { + s1 = peg$c26; + peg$currPos += 8; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c21) { - s1 = peg$c21; - peg$currPos += 7; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c22) { - s1 = peg$c22; - peg$currPos += 6; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 4) === peg$c23) { - s1 = peg$c23; - peg$currPos += 4; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } - } - if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c24) { - s1 = peg$c24; - peg$currPos += 11; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } - } - } - } - } + if (peg$silentFails === 0) { peg$fail(peg$e30); } } } } @@ -1037,7 +965,7 @@ function peg$parse(input, options) { peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } + if (peg$silentFails === 0) { peg$fail(peg$e25); } } return s0; @@ -1065,7 +993,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f13(s1); + s1 = peg$f11(s1); } s0 = s1; @@ -1078,7 +1006,7 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c25; + s1 = peg$c27; peg$currPos++; } else { s1 = peg$FAILED; @@ -1104,7 +1032,7 @@ function peg$parse(input, options) { } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c25; + s3 = peg$c27; peg$currPos++; } else { s3 = peg$FAILED; @@ -1112,7 +1040,7 @@ function peg$parse(input, options) { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s0 = peg$f14(s2); + s0 = peg$f12(s2); } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1159,7 +1087,7 @@ function peg$parse(input, options) { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$f15(s1); + s1 = peg$f13(s1); } s0 = s1; peg$silentFails--; @@ -1177,7 +1105,7 @@ function peg$parse(input, options) { s0 = peg$currPos; s1 = peg$parse_(); peg$savedPos = s0; - s1 = peg$f16(); + s1 = peg$f14(); s0 = s1; return s0; diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 3e9d7906a31d..cb88bf757c34 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -8,9 +8,7 @@ // filter: abstract rule to simplify the filterList rule. It takes all filter types. // defaultFilter: rule to process the default values returned by the defaultKey rule. It updates the default values object. // freeTextFilter: rule to process the free text search values returned by the identifier rule. It builds filter Object. -// multiSelectFilter: rule to process the multi-select values returned by the multiselectKey rule. It builds multiselect filter Object. // standardFilter: rule to process the values returned by the key rule. It builds filter Object. -// policyIDFilter: rule to process the policyID. It builds filter Object. // operator: rule to match pre-defined search syntax operators, e.g. !=, >, etc // key: rule to match pre-defined search syntax fields that aren't multi-select, e.g. amount, merchant, etc // defaultKey: rule to match pre-defined search syntax fields that are used to update default values, e.g. type, status, etc @@ -54,8 +52,8 @@ query = _ filters:filterList? _ { return applyDefaults(filters); } filterList = head:filter tail:(logicalAnd filter)* { const allFilters = [head, ...tail.map(([_, filter]) => filter)] - .filter((filter) => filter !== null) - .filter(Boolean); + .filter(Boolean) + .filter((filter) => filter.right); if (!allFilters.length) { return null; } @@ -69,63 +67,32 @@ filterList filter.left !== "keyword" && filter.right?.left !== "keyword" ); - if (!nonKeywords.length) { - return keywords.reduce((result, filter) => - buildFilter("or", result, filter) - ); - } - if (!keywords.length) { - return nonKeywords.reduce((result, filter) => - buildFilter("and", result, filter) - ); + const keywordFilter = buildFilter( + "eq", + "keyword", + keywords.map((filter) => filter.right).flat() + ); + if (keywordFilter.right.length > 0) { + nonKeywords.push(keywordFilter); } - - return buildFilter( - "and", - keywords.reduce((result, filter) => buildFilter("or", result, filter)), - nonKeywords.reduce((result, filter) => - buildFilter("and", result, filter) - ) + return nonKeywords.reduce((result, filter) => + buildFilter("and", result, filter) ); } -filter - = @( - policyIDFilter - / standardFilter - / defaultFilter - / multiSelectFilter - / freeTextFilter - ) +filter = @(standardFilter / defaultFilter / freeTextFilter) defaultFilter = _ key:defaultKey _ op:operator _ value:identifier { - updateDefaultValues(key, value.trim()); + updateDefaultValues(key, value); } freeTextFilter - = _ value:identifier _ { return buildFilter("eq", "keyword", value.trim()); } - -multiSelectFilter - = _ field:multiselectKey _ op:operator _ value:identifier { - return buildFilter(op, field, value); - } + = _ value:identifier _ { return buildFilter("eq", "keyword", value); } standardFilter - = _ field:key _ op:operator _ value:identifier { - const values = value.split(","); - return values - .slice(1) - .reduce( - (acc, val) => - buildFilter("or", acc, buildFilter(op, field, val.trim())), - buildFilter(op, field, values[0]) - ); - } - -policyIDFilter "policyID filter" - = _ field:"policyID" _ op:operator _ value:identifier { - updateDefaultValues(field, value.trim()); + = _ field:key _ op:operator _ values:identifier { + return buildFilter(op, field, values); } operator "operator" @@ -137,13 +104,14 @@ operator "operator" / "<" { return "lt"; } key "key" - = @("date" / "amount" / "merchant" / "description" / "reportID" / "keyword") - -defaultKey "default key" = @("type" / "status" / "sortBy" / "sortOrder") - -multiselectKey "multiselect key" = @( - "in" + "date" + / "amount" + / "merchant" + / "description" + / "reportID" + / "keyword" + / "in" / "currency" / "tag" / "category" @@ -152,14 +120,29 @@ multiselectKey "multiselect key" / "cardID" / "from" / "expenseType" + / "has" + / "in" + / "is" ) -identifier = parts:(quotedString / alphanumeric)+ { return parts.join(""); } +defaultKey "default key" + = @("type" / "status" / "sortBy" / "sortOrder" / "policyID") + +identifier + = parts:(quotedString / alphanumeric)+ { + const value = parts.flat(); + if (value.length > 1) { + return value; + } + return value[0]; + } quotedString "quote" = "\"" chars:[^"\r\n]* "\"" { return chars.join(""); } alphanumeric "word" - = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { return chars.join(""); } + = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { + return chars.join("").trim().split(",").filter(Boolean); + } logicalAnd = _ { return "and"; } diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 4a8864fef769..cb1c0d7d3cc2 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -409,10 +409,11 @@ function buildAmountFilterQuery(filterValues: Partial } function sanitizeString(str: string) { - if (str.includes(' ') || str.includes(',')) { - return `"${str}"`; + const safeStr = str; + if (safeStr.includes(' ') || safeStr.includes(',')) { + return `"${safeStr}"`; } - return str; + return safeStr; } function getExpenseTypeTranslationKey(expenseType: ValueOf): TranslationPaths { @@ -441,7 +442,7 @@ function buildQueryStringFromFilters(filterValues: Partial CONST.SEARCH.SYNTAX_FILTER_KEYS[key] === filterKey); if (keyInCorrectForm) { - return `${CONST.SEARCH.SYNTAX_FILTER_KEYS[keyInCorrectForm]}:${filterValue as string}`; + return `${filterValue as string}`; } } @@ -489,7 +490,7 @@ function getFilters(queryJSON: SearchQueryJSON) { traverse(node.left); } - if (typeof node?.right === 'object' && node.right) { + if (typeof node?.right === 'object' && node.right && !Array.isArray(node.right)) { traverse(node.right); } @@ -504,15 +505,26 @@ function getFilters(queryJSON: SearchQueryJSON) { // the "?? []" is added only for typescript because otherwise TS throws an error, in newer TS versions this should be fixed const filterArray = filters[nodeKey] ?? []; - filterArray.push({ - operator: node.operator, - value: node.right as string | number, - }); + console.log(node); + if (!Array.isArray(node.right)) { + filterArray.push({ + operator: node.operator, + value: node.right as string | number, + }); + } else { + node.right.forEach((element) => { + filterArray.push({ + operator: node.operator, + value: element as string | number, + }); + }); + } } if (queryJSON.filters) { traverse(queryJSON.filters); } + console.log('filters', filters); return filters; } @@ -544,7 +556,7 @@ function buildFilterString(filterName: string, queryFilters: QueryFilter[]) { if ((queryFilter.operator === 'eq' && queryFilters[index - 1]?.operator === 'eq') || (queryFilter.operator === 'neq' && queryFilters[index - 1]?.operator === 'neq')) { filterValueString += ` ${sanitizeString(queryFilter.value.toString())}`; } else { - filterValueString += ` ${filterName}${operatorToSignMap[queryFilter.operator]}${queryFilter.value}`; + filterValueString += ` ${filterName}${operatorToSignMap[queryFilter.operator]}${sanitizeString(queryFilter.value.toString())}`; } }); From 1c94450be46e0483874c89779031a5f5a4e1a4d6 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Sep 2024 16:43:19 +0200 Subject: [PATCH 08/11] fix grammar and remove comments --- src/libs/SearchParser/searchParser.peggy | 40 ++++++++++++++---------- src/libs/SearchUtils.ts | 2 -- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index baaf32d870bb..bea1e5cfd6ff 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -11,28 +11,33 @@ // standardFilter: rule to process the values returned by the key rule. It builds filter Object. // operator: rule to match pre-defined search syntax operators, e.g. !=, >, etc // key: rule to match pre-defined search syntax fields, e.g. amount, merchant, etc +// defaultKey: rule to match pre-defined search syntax fields that are used to update default values, e.g. type, status, etc // identifier: composite rule to match patterns defined by the quotedString and alphanumeric rules // quotedString: rule to match a quoted string pattern, e.g. "this is a quoted string" // alphanumeric: rule to match unquoted alphanumeric characters, e.g. a-z, 0-9, _, @, etc // logicalAnd: rule to match whitespace and return it as a logical 'and' operator // whitespace: rule to match whitespaces -{ - const defaultValues = { - "type": "expense", - "status": "all", - "sortBy": "date", - "sortOrder": "desc", - }; - +// global initializer (code executed only once) +{{ function buildFilter(operator, left, right) { return { operator, left, right }; } +}} + +// per-parser initializer (code executed before every parse) +{ + const defaultValues = { + type: "expense", + status: "all", + sortBy: "date", + sortOrder: "desc", + }; function applyDefaults(filters) { return { ...defaultValues, - filters + filters, }; } @@ -92,10 +97,10 @@ standardFilter operator "operator" = (":" / "=") { return "eq"; } / "!=" { return "neq"; } - / ">" { return "gt"; } / ">=" { return "gte"; } - / "<" { return "lt"; } + / ">" { return "gt"; } / "<=" { return "lte"; } + / "<" { return "lt"; } key "key" = @( @@ -122,18 +127,21 @@ key "key" defaultKey "default key" = @("type" / "status" / "sortBy" / "sortOrder" / "policyID") -identifier = parts:(quotedString / alphanumeric)+ { - const value = parts.flat(); +identifier + = parts:(quotedString / alphanumeric)+ { + const value = parts.flat(); if (value.length > 1) { - return value; + return value; } return value[0]; - } + } quotedString "quote" = "\"" chars:[^"\r\n]* "\"" { return chars.join(""); } alphanumeric "word" - = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { return chars.join(""); } + = chars:[A-Za-z0-9_@./#&+\-\\',;]+ { + return chars.join("").trim().split(",").filter(Boolean); + } logicalAnd = _ { return "and"; } diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index bf5824fdb46a..b3e3696730e4 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -510,7 +510,6 @@ function getFilters(queryJSON: SearchQueryJSON) { // the "?? []" is added only for typescript because otherwise TS throws an error, in newer TS versions this should be fixed const filterArray = filters[nodeKey] ?? []; - console.log(node); if (!Array.isArray(node.right)) { filterArray.push({ operator: node.operator, @@ -529,7 +528,6 @@ function getFilters(queryJSON: SearchQueryJSON) { if (queryJSON.filters) { traverse(queryJSON.filters); } - console.log('filters', filters); return filters; } From 62d6a44fcab1358b88e2d245c332c502511e1e6e Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Sep 2024 16:57:39 +0200 Subject: [PATCH 09/11] update tests --- tests/unit/SearchParserTest.ts | 140 +++++++-------------------------- 1 file changed, 30 insertions(+), 110 deletions(-) diff --git a/tests/unit/SearchParserTest.ts b/tests/unit/SearchParserTest.ts index c8d3764f0546..1f2a97771bf3 100644 --- a/tests/unit/SearchParserTest.ts +++ b/tests/unit/SearchParserTest.ts @@ -193,17 +193,9 @@ const tests = [ right: '200', }, right: { - operator: 'or', - left: { - operator: 'eq', - left: 'expenseType', - right: 'cash', - }, - right: { - operator: 'eq', - left: 'expenseType', - right: 'card', - }, + operator: 'eq', + left: 'expenseType', + right: ['cash', 'card'], }, }, right: { @@ -219,25 +211,9 @@ const tests = [ }, }, right: { - operator: 'or', - left: { - operator: 'or', - left: { - operator: 'eq', - left: 'category', - right: 'travel', - }, - right: { - operator: 'eq', - left: 'category', - right: 'hotel', - }, - }, - right: { - operator: 'eq', - left: 'category', - right: 'meal & entertainment', - }, + operator: 'eq', + left: 'category', + right: ['travel', 'hotel', 'meal & entertainment'], }, }, }, @@ -252,23 +228,15 @@ const tests = [ filters: { operator: 'and', left: { - operator: 'or', - left: { - operator: 'eq', - left: 'keyword', - right: 'las', - }, - right: { - operator: 'eq', - left: 'keyword', - right: 'vegas', - }, - }, - right: { operator: 'gt', left: 'amount', right: '200', }, + right: { + operator: 'eq', + left: 'keyword', + right: ['las', 'vegas'], + }, }, }, }, @@ -282,19 +250,6 @@ const tests = [ filters: { operator: 'and', left: { - operator: 'or', - left: { - operator: 'eq', - left: 'keyword', - right: 'las', - }, - right: { - operator: 'eq', - left: 'keyword', - right: 'vegas', - }, - }, - right: { operator: 'and', left: { operator: 'gt', @@ -307,6 +262,11 @@ const tests = [ right: 'Hotel : Marriott', }, }, + right: { + operator: 'eq', + left: 'keyword', + right: ['las', 'vegas'], + }, }, }, }, @@ -320,19 +280,6 @@ const tests = [ filters: { operator: 'and', left: { - operator: 'or', - left: { - operator: 'eq', - left: 'keyword', - right: 'las', - }, - right: { - operator: 'eq', - left: 'keyword', - right: 'vegas', - }, - }, - right: { operator: 'and', left: { operator: 'and', @@ -351,55 +298,28 @@ const tests = [ right: 'Hotel : Marriott', }, }, - right: { - operator: 'or', - left: { - operator: 'eq', - left: 'date', - right: '2024-01-01', - }, - right: { - operator: 'eq', - left: 'date', - right: '2024-02-01', - }, - }, - }, - right: { - operator: 'or', - left: { - operator: 'eq', - left: 'merchant', - right: 'Expensify', - }, - right: { - operator: 'eq', - left: 'merchant', - right: 'Inc.', - }, - }, - }, - right: { - operator: 'or', - left: { - operator: 'or', - left: { - operator: 'eq', - left: 'tag', - right: 'hotel', - }, right: { operator: 'eq', - left: 'tag', - right: 'travel', + left: 'date', + right: ['2024-01-01', '2024-02-01'], }, }, right: { operator: 'eq', - left: 'tag', - right: 'meals & entertainment', + left: 'merchant', + right: 'Expensify, Inc.', }, }, + right: { + operator: 'eq', + left: 'tag', + right: ['hotel', 'travel', 'meals & entertainment'], + }, + }, + right: { + operator: 'eq', + left: 'keyword', + right: ['las', 'vegas'], }, }, }, From e7b253acfa0a2a25f183fb92debc598268de67e9 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Sep 2024 17:11:35 +0200 Subject: [PATCH 10/11] fix merge --- src/libs/SearchParser/searchParser.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index d7e724ac3f34..32fd834c1346 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -1006,7 +1006,6 @@ function peg$parse(input, options) { peg$silentFails++; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c27; s1 = peg$c27; peg$currPos++; } else { @@ -1033,7 +1032,6 @@ function peg$parse(input, options) { } } if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c27; s3 = peg$c27; peg$currPos++; } else { From 15bb04e8003762d08ad9107cc31294a077d3bfbe Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 5 Sep 2024 18:03:11 +0200 Subject: [PATCH 11/11] lint fix --- src/components/Search/types.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index a7d8fcbdae3c..4a431b98ceca 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -71,13 +71,6 @@ type SearchQueryJSON = { hash: number; } & SearchQueryAST; -type NewQueryFilter = { - operator: ValueOf; - value: string[]; -}; - -type NewFilter = NewQueryFilter[]; - export type { SelectedTransactionInfo, SelectedTransactions,