Have filter_term accept an object, not a tuple.

This is more phasing out of tuples for narrowing.

(imported from commit 7c8b801e807053f60bee5086df6acb70b852a79c)
This commit is contained in:
Steve Howell
2014-02-03 12:54:36 -05:00
parent eea8c0d1d5
commit 889adfa0e0

View File

@@ -1,16 +1,16 @@
var Filter = (function () { var Filter = (function () {
function filter_term(operator, operand) { function filter_term(opts) {
// For legacy reasons we must represent filter_terms as tuples // For legacy reasons we must represent filter_terms as tuples
// until we phase out all the code that assumes tuples. // until we phase out all the code that assumes tuples.
var term = []; var term = [];
term[0] = operator; term[0] = opts.operator;
term[1] = operand; term[1] = opts.operand;
// This is the new style we are phasing in. (Yes, the same // This is the new style we are phasing in. (Yes, the same
// object can be treated like either a tuple or a struct.) // object can be treated like either a tuple or a struct.)
term.operator = operator; term.operator = opts.operator;
term.operand = operand; term.operand = opts.operand;
return term; return term;
} }
@@ -169,7 +169,10 @@ Filter.canonicalize_tuple = function (tuple) {
} }
// We may want to consider allowing mixed-case operators at some point // We may want to consider allowing mixed-case operators at some point
return filter_term(operator, operand); return filter_term({
operator: operator,
operand: operand
});
}; };
@@ -198,7 +201,9 @@ function decodeOperand(encoded, operator) {
Filter.parse = function (str) { Filter.parse = function (str) {
var operators = []; var operators = [];
var search_term = []; var search_term = [];
var operator;
var operand; var operand;
var term;
var matches = str.match(/"[^"]+"|\S+/g); var matches = str.match(/"[^"]+"|\S+/g);
if (matches === null) { if (matches === null) {
@@ -215,13 +220,16 @@ Filter.parse = function (str) {
// FIXME: Should we skip unknown operator names here? // FIXME: Should we skip unknown operator names here?
operator = parts.shift(); operator = parts.shift();
operand = decodeOperand(parts.join(':'), operator); operand = decodeOperand(parts.join(':'), operator);
operators.push(filter_term(operator, operand)); term = filter_term({operator: operator, operand: operand});
operators.push(term);
} }
}); });
// NB: Callers of 'parse' can assume that the 'search' operator is last. // NB: Callers of 'parse' can assume that the 'search' operator is last.
if (search_term.length > 0) { if (search_term.length > 0) {
operator = 'search';
operand = search_term.join(' '); operand = search_term.join(' ');
operators.push(filter_term('search', operand)); term = filter_term({operator: operator, operand: operand});
operators.push(term);
} }
return operators; return operators;
}; };