From 148a63ae7e2633b69446372fa9ee475fa7a9eb0a Mon Sep 17 00:00:00 2001 From: William Carroll Date: Thu, 19 Jan 2023 15:19:49 -0800 Subject: fix(wpcarro/slx): Forward config to all functions Oops... Change-Id: I985a1a10e3009107ca2b8f65e5377f36fe0531fa Reviewed-on: https://cl.tvl.fyi/c/depot/+/7875 Autosubmit: wpcarro Reviewed-by: wpcarro Tested-by: BuildkiteCI --- users/wpcarro/slx.js/index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'users/wpcarro') diff --git a/users/wpcarro/slx.js/index.js b/users/wpcarro/slx.js/index.js index 7eba2dca91bf..9f2ed675f7a9 100644 --- a/users/wpcarro/slx.js/index.js +++ b/users/wpcarro/slx.js/index.js @@ -1,12 +1,12 @@ function select(query, xs, config) { - const predicate = compile(parse(query), config); + const predicate = compile(parse(query, config), config); return xs.filter(predicate); } function compile(ast, config) { if (ast.type === 'CONJUNCTION') { - const lhs = compile(ast.lhs); - const rhs = compile(ast.rhs); + const lhs = compile(ast.lhs, compile); + const rhs = compile(ast.rhs, compile); if (ast.joint === 'AND') { return function(x) { @@ -50,7 +50,7 @@ function compile(ast, config) { } } if (ast.type === 'SELECTION') { - const f = compile(ast.val); + const f = compile(ast.val, config); return function(row) { return ast.negate ? !f(row[ast.key]) : f(row[ast.key]); }; @@ -225,16 +225,16 @@ function parser(tokens) { return { i: 0, tokens }; } -function parse(x) { +function parse(x, config) { const tokens = tokenize(x); const p = parser(tokens); - return conjunction(p); + return conjunction(p, config); } -function conjunction(p) { +function conjunction(p, config) { skipWhitespace(p); - const lhs = selection(p); + const lhs = selection(p, config); skipWhitespace(p); if (p.i >= p.tokens.length) { @@ -250,7 +250,7 @@ function conjunction(p) { p.i += 1; } skipWhitespace(p); - let rhs = conjunction(p); + let rhs = conjunction(p, config); return { type: 'CONJUNCTION', @@ -267,7 +267,7 @@ function peekType(n, p) { return null; } -function selection(p) { +function selection(p, config) { // column:value OR -column:value if ((peekType(0, p) === 'ATOM' && peekType(1, p) === 'COLON') || (peekType(0, p) === 'NEGATE' && peekType(1, p) === 'ATOM' && peekType(2, p) === 'COLON')) { @@ -289,7 +289,7 @@ function selection(p) { val, }; } else { - const val = value(p); + const val = value(p, config); return { type: 'SELECTION', negate, -- cgit 1.4.1