"use strict";
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2019-2020 The Board of Trustees of the Leland Stanford Junior University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Silei Xu <silei@cs.stanford.edu>
//         Giovanni Campagna <gcampagn@cs.stanford.edu>
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const assert_1 = __importDefault(require("assert"));
const thingtalk_1 = require("thingtalk");
const C = __importStar(require("../ast_manip"));
async function default_1($runtime, $ttUtils, $options, $locale, $grammar, $loader) {
    const HERE = new thingtalk_1.Ast.Value.Location(new thingtalk_1.Ast.Location.Relative('current_location'));
    $grammar.declareSymbol("get_predicate_filter");
    $grammar.addRule("get_predicate_filter", ["before", new $runtime.NonTerminal("constant_Time", undefined)], (($0, t1) => C.timeGetPredicate($loader, null, t1)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["after", new $runtime.NonTerminal("constant_Time", undefined)], (($0, t2) => C.timeGetPredicate($loader, t2, null)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["between", new $runtime.NonTerminal("constant_Time", undefined), "and", new $runtime.NonTerminal("constant_Time", undefined)], (($0, t1, $1, t2) => C.timeGetPredicate($loader, t1, t2)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["my location is", new $runtime.NonTerminal("constant_Location", undefined)], (($0, loc) => C.locationGetPredicate($loader, loc)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["my location is not", new $runtime.NonTerminal("constant_Location", undefined)], (($0, loc) => C.locationGetPredicate($loader, loc, true)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["i am at", new $runtime.NonTerminal("constant_Location", undefined)], (($0, loc) => C.locationGetPredicate($loader, loc)), undefined, {});
    $grammar.addRule("get_predicate_filter", ["i am not at", new $runtime.NonTerminal("constant_Location", undefined)], (($0, loc) => C.locationGetPredicate($loader, loc, true)), undefined, {});
    $grammar.addRule("get_predicate_filter", [new $runtime.NonTerminal("projection_Any", undefined), new $runtime.Choice(["is", "is exactly", "is equal to"]), new $runtime.NonTerminal("constant_Any", undefined)], ((proj, $0, x) => C.makeGetPredicate(proj, '==', x)), undefined, {});
    $grammar.addRule("get_predicate_filter", [new $runtime.NonTerminal("projection_Any", undefined), new $runtime.Choice(["is not", "is n't", "is different than"]), new $runtime.NonTerminal("constant_Any", undefined)], ((proj, $0, x) => C.makeGetPredicate(proj, '==', x, true)), undefined, {});
    $grammar.declareSymbol("if_filter");
    if ($options.flags.get_predicate) {
        $grammar.addRule("if_filter", [new $runtime.NonTerminal("get_predicate_filter", undefined)], (($0) => { return $0; }), C.filterKeyFn, { identity: (true) });
    }
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["is", "is exactly", "is equal to"]), new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["is", "is exactly", "is equal to"]), new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["is not", "is n't", "is different than"]), new $runtime.NonTerminal("constant_Any", ["type", 1, "type"])], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x, true)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), "is", new $runtime.Choice(["greater than", "higher than", "larger than", "more than", "at least", "not less than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), "is", new $runtime.Choice(["smaller than", "lower than", "less than", "at most", "not more than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), "is", new $runtime.Choice(["more expensive", "more costly", "more"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), "is", new $runtime.Choice(["less expensive", "cheaper", "less"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "is", new $runtime.Choice(["longer than", "no shorter than"]), new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "is", new $runtime.Choice(["no longer than", "shorter than"]), new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), "is", new $runtime.Choice(["larger", "more", "no smaller", "no less"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), "is", new $runtime.Choice(["smaller", "less", "no larger", "no more"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), "is", new $runtime.Choice(["heavier", "larger"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), "is", new $runtime.Choice(["lighter", "smaller"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), "is", new $runtime.Choice(["hotter", "higher"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), "is", new $runtime.Choice(["cooler", "colder", "lower"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), "is", new $runtime.Choice(["farther", "more distant", "longer"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), "is", new $runtime.Choice(["nearer", "closer", "shorter", "no longer", "no farther"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), "is", new $runtime.Choice(["larger", "bigger", "no smaller"]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), "is", new $runtime.Choice(["smaller", "no larger", "no bigger"]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), "is", new $runtime.Choice(["larger", "bigger", "no smaller"]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), "is", new $runtime.Choice(["smaller", "no larger", "no bigger"]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), "is", new $runtime.Choice(["faster", "quicker", "speedier"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), "is", new $runtime.Choice(["slower", "more slowly"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), "is", new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
        $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), "is", new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
        $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), "is", new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
        $grammar.addRule("if_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), "is", new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Array__Any", undefined), new $runtime.Choice(["contain", "include"]), new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, 'contains', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Array__Any", undefined), "do not", new $runtime.Choice(["contain", "include"]), new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, $2, x) => C.makeFilter($loader, p, 'contains', x, true)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["contains", "includes"]), new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), "does not", new $runtime.Choice(["contain", "include"]), new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, $2, x) => C.makeFilter($loader, p, '=~', x, true)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.RecurrentTimeSpecification))]), new $runtime.Choice(["contains", "includes"]), new $runtime.NonTerminal("constant_Date", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.RecurrentTimeSpecification))]), "does not", new $runtime.Choice(["contain", "include"]), new $runtime.NonTerminal("constant_Date", undefined)], (($0, p, $1, $2, x) => C.makeFilter($loader, p, '=~', x, true)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.RecurrentTimeSpecification))]), new $runtime.Choice(["contains", "includes"]), new $runtime.NonTerminal("constant_Time", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.RecurrentTimeSpecification))]), "does not", new $runtime.Choice(["contain", "include"]), new $runtime.NonTerminal("constant_Time", undefined)], (($0, p, $1, $2, x) => C.makeFilter($loader, p, '=~', x, true)), C.filterKeyFn, {});
    $grammar.addRule("if_filter", [new $runtime.NonTerminal("constant_String", undefined), "is in", new $runtime.NonTerminal("the_out_param_Any", ["type", ((thingtalk_1.Type.String))])], ((x, $0, p) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        if ($options.flags.range_filters) {
            $grammar.addRule("if_filter", [new $runtime.NonTerminal("range_filter", undefined)], (($0) => { return $0; }), C.filterKeyFn, { identity: (true) });
        }
    }
    $grammar.declareSymbol("edge_filter");
    if (!$options.flags.turking) {
        $grammar.addRule("edge_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["becomes", "becomes equal to"]), new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["greater than", "higher than", "larger than", "more than", "at least", "not less than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["smaller than", "lower than", "less than", "at most", "not more than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["more expensive", "more costly", "more"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["less expensive", "cheaper", "less"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), new $runtime.Choice(["is now", "becomes", "goes"]), "longer than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), new $runtime.Choice(["is now", "becomes", "goes"]), "shorter than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["larger", "more"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["smaller", "less"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["heavier", "larger"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["lighter", "smaller"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["hotter", "higher"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["cooler", "colder", "lower"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["farther", "more distant", "longer"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["nearer", "closer", "shorter"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["bigger", "larger"]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), new $runtime.Choice(["is now", "becomes", "goes"]), "smaller", "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["bigger", "larger"]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), new $runtime.Choice(["is now", "becomes", "goes"]), "smaller", "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["faster", "quicker", "speedier"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["slower", "more slowly"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, $2, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("edge_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), new $runtime.Choice(["is now", "becomes", "goes"]), new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.declareSymbol("either_filter");
    $grammar.addRule("either_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["is", "is equal to", "is one of", "is either"]), new $runtime.NonTerminal("constant_or_pairs", ["type", 1, "type"])], (($0, param, $1, pair) => {
        // param is a Value.VarRef
        //console.log('param: ' + param.name);
        const [v1, v2] = pair;
        let vtype = v1.getType();
        if (vtype.isBoolean) // "is equal to true or false" does not make sense
            return null;
        return C.makeFilter($loader, param, 'in_array', new thingtalk_1.Ast.Value.Array([v1, v2]));
    }), C.filterKeyFn, {});
    $grammar.addRule("either_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), new $runtime.Choice(["is", "is equal to", "is one of", "is either"]), new $runtime.NonTerminal("constant_or_pairs", ["type", ((thingtalk_1.Type.String))])], (($0, param, $1, pair) => {
        // param is a Value.VarRef
        //console.log('param: ' + param.name);
        const [v1, v2] = pair;
        let vtype = v1.getType();
        if (vtype.isBoolean) // "is equal to true or false" does not make sense
            return null;
        return C.makeFilter($loader, param, 'in_array', new thingtalk_1.Ast.Value.Array([v1, v2]));
    }), C.filterKeyFn, {});
    $grammar.addRule("either_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.Choice(["not", "neither"]), new $runtime.NonTerminal("constant_nor_pairs", ["type", 1, "type"])], (($0, param, $1, $2, pair) => {
        // param is a Value.VarRef
        //console.log('param: ' + param.name);
        const [v1, v2] = pair;
        let vtype = v1.getType();
        if (vtype.isBoolean) // "is neither true nor false" does not make sense
            return null;
        return C.makeFilter($loader, param, 'in_array', new thingtalk_1.Ast.Value.Array([v1, v2]), true);
    }), C.filterKeyFn, {});
    $grammar.declareSymbol("range");
    $grammar.addRule("range", ["between", new $runtime.NonTerminal("constant_Numeric", undefined), "and", new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, v1, $1, v2) => {
        assert_1.default(v1.getType().equals(v2.getType()));
        if (v1.equals(v2))
            return null;
        return [v1, v2];
    }), C.valueArrayKeyFn, {});
    $grammar.addRule("range", ["in the range from", new $runtime.NonTerminal("constant_Numeric", undefined), "to", new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, v1, $1, v2) => {
        assert_1.default(v1.getType().equals(v2.getType()));
        if (v1.equals(v2))
            return null;
        return [v1, v2];
    }), C.valueArrayKeyFn, {});
    $grammar.declareSymbol("range_filter");
    $grammar.addRule("range_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "is", new $runtime.NonTerminal("range", ["type", 1, "type"])], (($0, param, $1, range) => {
        const [v1, v2] = range;
        const f1 = C.makeFilter($loader, param, '>=', v1);
        const f2 = C.makeFilter($loader, param, '<=', v2);
        if (!f1 || !f2)
            return null;
        return { schema: f1.schema, ptype: f1.ptype,
            ast: new thingtalk_1.Ast.BooleanExpression.And(null, [f1.ast, f2.ast]) };
    }), C.filterKeyFn, {});
    $grammar.declareSymbol("with_filter");
    $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "equal to", new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", undefined), "equal to", new $runtime.NonTerminal("constant_Any", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["containing", "including"]), new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_String", undefined), new $runtime.Choice(["in the", "in its", "in their"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))])], ((x, $0, p) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if ($options.flags.schema_org) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["being", "containing"]), new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if ($options.flags.schema_org) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_String", undefined), new $runtime.Choice(["as", "in the"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))])], ((x, $0, p) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), "equal to", new $runtime.NonTerminal("constant_String_ContextRef", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["containing", "including"]), new $runtime.NonTerminal("constant_String_ContextRef", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_String_ContextRef", undefined), new $runtime.Choice(["in the", "in its", "in their"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))])], ((x, $0, p) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if ($options.flags.schema_org) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["being", "containing"]), new $runtime.NonTerminal("constant_String_ContextRef", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if ($options.flags.schema_org) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_String_ContextRef", undefined), new $runtime.Choice(["as", "in the"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))])], ((x, $0, p) => C.makeFilter($loader, p, '=~', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), "containing both", new $runtime.NonTerminal("constant_String", undefined), "and", new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x, $2, y) => C.makeAndFilter($loader, p, '=~', [x, y])), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), "containing neither", new $runtime.NonTerminal("constant_String", undefined), "nor", new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x, $2, y) => C.makeAndFilter($loader, p, '=~', [x, y], true)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["both", new $runtime.NonTerminal("constant_String", undefined), "and", new $runtime.NonTerminal("constant_String", undefined), "in", new $runtime.NonTerminal("the_out_param_Any", ["type", ((thingtalk_1.Type.String))])], (($0, x, $1, y, $2, p) => C.makeAndFilter($loader, p, '=~', [x, y])), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), "containing either", new $runtime.NonTerminal("constant_String", undefined), "or", new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x, $2, y) => C.makeOrFilter($loader, p, '=~', [x, y])), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["either", new $runtime.NonTerminal("constant_String", undefined), "or", new $runtime.NonTerminal("constant_String", undefined), "in", new $runtime.NonTerminal("the_out_param_Any", ["type", ((thingtalk_1.Type.String))])], (($0, x, $1, y, $2, p) => C.makeOrFilter($loader, p, '=~', [x, y])), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.String))]), new $runtime.Choice(["containing", "including"]), new $runtime.NonTerminal("constant_String", undefined), new $runtime.Choice(["but not", "without", "but no"]), new $runtime.NonTerminal("constant_String", undefined)], (($0, p, $1, x, $2, y) => C.makeButFilter($loader, p, '=~', [x, y])), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), new $runtime.Choice(["greater than", "higher than", "larger than", "more than", "at least", "not less than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), new $runtime.Choice(["smaller than", "lower than", "less than", "at most", "not more than"]), new $runtime.NonTerminal("constant_Number", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Number", undefined), new $runtime.Choice(["or more", "or higher", "or greater", "or above"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Number", undefined), new $runtime.Choice(["or less", "or lower", "or below"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["over", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))])], (($0, x, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), new $runtime.Choice(["more expensive", "more costly", "more"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), new $runtime.Choice(["less expensive", "cheaper", "less"]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Currency", undefined), new $runtime.Choice(["or more", "or above"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Currency", undefined), new $runtime.Choice(["or less", "or cheaper", "or below"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "longer than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "shorter than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_ms", undefined), new $runtime.Choice(["or longer", "or more"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_ms", undefined), new $runtime.Choice(["or shorter", "or less"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), new $runtime.Choice(["larger", "more"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), new $runtime.Choice(["smaller", "less"]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_byte", undefined), new $runtime.Choice(["or larger", "or more"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_byte", undefined), new $runtime.Choice(["or smaller", "or less"]), "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), new $runtime.Choice(["heavier", "larger"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), new $runtime.Choice(["lighter", "smaller"]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_kg", undefined), "or more", "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Measure_kg", undefined), "or less", "the", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))])], ((x, $0, $1, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["over", new $runtime.NonTerminal("constant_Measure_kg", undefined), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))])], (($0, x, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), new $runtime.Choice(["hotter", "higher"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), new $runtime.Choice(["cooler", "colder", "lower"]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), new $runtime.Choice(["farther", "more distant", "longer"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), new $runtime.Choice(["nearer", "closer", "shorter"]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), new $runtime.Choice(["larger", "bigger"]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), "smaller", "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), new $runtime.Choice(["larger", "bigger"]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), "smaller", "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), new $runtime.Choice(["faster", "quicker", "speedier"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), new $runtime.Choice(["slower", "more slowly"]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], ((p, $0, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Date", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), new $runtime.Choice(["after", "later than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), new $runtime.Choice(["before", "earlier than", "sooner than"]), new $runtime.NonTerminal("constant_Time", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["greater", "higher", "larger", "more"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), "than", new $runtime.NonTerminal("constant_Number", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["smaller", "lower", "less"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))]), "than", new $runtime.NonTerminal("constant_Number", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["more expensive", "more costly", "more"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["less expensive", "cheaper", "less"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Currency))]), "than", new $runtime.NonTerminal("constant_Currency", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["longer", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["shorter", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('ms')))]), "than", new $runtime.NonTerminal("constant_Measure_ms", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["larger", "more"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["smaller", "less"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('byte')))]), "than", new $runtime.NonTerminal("constant_Measure_byte", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["heavier", "larger"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["lighter", "smaller"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('kg')))]), "than", new $runtime.NonTerminal("constant_Measure_kg", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["hotter", "higher"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["cooler", "colder", "lower"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('C')))]), "than", new $runtime.NonTerminal("constant_Measure_C", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["farther", "more distant", "longer"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["nearer", "closer", "shorter"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m')))]), "than", new $runtime.NonTerminal("constant_Measure_m", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["bigger", "larger"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["smaller", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m2')))]), "than", new $runtime.NonTerminal("constant_Measure_m2", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["bigger", "larger"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["smaller", new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('m3')))]), "than", new $runtime.NonTerminal("constant_Measure_m3", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["faster", "quicker", "speedier"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["slower", "more slowly"]), new $runtime.NonTerminal("out_param_Any", ["type", ((new thingtalk_1.Type.Measure('mps')))]), "than", new $runtime.NonTerminal("constant_Measure_mps", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["later", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), "than", new $runtime.NonTerminal("constant_Date", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["earlier", "sooner"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Date))]), "than", new $runtime.NonTerminal("constant_Date", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["later", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), "than", new $runtime.NonTerminal("constant_Time", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["earlier", "sooner"]), new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Time))]), "than", new $runtime.NonTerminal("constant_Time", undefined)], (($0, p, $1, x) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        if ($options.flags.range_filters) {
            $grammar.addRule("with_filter", [new $runtime.NonTerminal("range_with_filter", undefined)], ((f) => f), C.filterKeyFn, {});
        }
        $grammar.addRule("with_filter", ["no", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))])], (($0, param) => C.makeFilter($loader, param, '==', new thingtalk_1.Ast.Value.Number(0))), C.filterKeyFn, {});
        $grammar.addRule("with_filter", ["zero", new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Number))])], (($0, param) => C.makeFilter($loader, param, '==', new thingtalk_1.Ast.Value.Number(0))), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Any", undefined), "containing", new $runtime.NonTerminal("constant_Any", undefined)], ((p, $0, x) => C.makeFilter($loader, p, 'contains', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Any", undefined), "containing no", new $runtime.NonTerminal("constant_Any", undefined)], ((p, $0, x) => C.makeFilter($loader, p, 'contains', x, true)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Any", undefined), "in", "the", new $runtime.NonTerminal("out_param_Array__Any", undefined)], ((x, $0, $1, p) => C.makeFilter($loader, p, 'contains', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Any", undefined), "containing", new $runtime.NonTerminal("both_prefix", undefined), new $runtime.NonTerminal("constant_pairs", ["type", 0, "elem"])], ((p, $0, $1, pair) => C.makeAndFilter($loader, p, 'contains', pair)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("both_prefix", undefined), new $runtime.NonTerminal("constant_pairs", undefined), "in", "the", new $runtime.NonTerminal("out_param_Array__Any", ["elem", 1, "type"])], (($0, pair, $1, $2, p) => C.makeAndFilter($loader, p, 'contains', pair)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Any", undefined), "containing either", new $runtime.NonTerminal("constant_or_pairs", ["type", 0, "elem"])], ((p, $0, pair) => C.makeOrFilter($loader, p, 'contains', pair)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["either", new $runtime.NonTerminal("constant_or_pairs", undefined), "in", "the", new $runtime.NonTerminal("out_param_Array__Any", ["elem", 1, "type"])], (($0, pair, $1, $2, p) => C.makeOrFilter($loader, p, 'contains', pair)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Any", ["type", ((thingtalk_1.Type.Any))]), new $runtime.Choice(["containing", "including"]), new $runtime.NonTerminal("constant_String", undefined), new $runtime.Choice(["but not", "without", "but no"]), new $runtime.NonTerminal("constant_String", undefined)], ((p, $0, x, $1, y) => C.makeButFilter($loader, p, 'contains', [x, y])), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["no", "zero"]), new $runtime.NonTerminal("out_param_Array__Any", undefined)], (($0, p) => C.makeAggregateFilter(p, 'count', '*', '==', new thingtalk_1.Ast.Value.Number(0))), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Any", undefined)], ((x, p) => C.makeAggregateFilter(p, 'count', '*', '==', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["no", "zero"]), new $runtime.NonTerminal("out_param_ArrayCount", undefined)], (($0, p) => C.makeFilter($loader, p, '==', new thingtalk_1.Ast.Value.Number(0))), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_ArrayCount", undefined)], ((x, p) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["no", "zero"]), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["lower than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 3, "type"])], (($0, p, $1, f, $2, x) => {
            const filter = C.makeFilter($loader, f, '<=', x);
            return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '==', new thingtalk_1.Ast.Value.Number(0));
        }), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["no", "zero"]), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["greater than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 3, "type"])], (($0, p, $1, f, $2, x) => {
            const filter = C.makeFilter($loader, f, '>=', x);
            return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '==', new thingtalk_1.Ast.Value.Number(0));
        }), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["greater than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 2, "type"])], ((p, $0, f, $1, x) => {
        const filter = C.makeFilter($loader, f, '<=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '>=', new thingtalk_1.Ast.Value.Number(1));
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["lower than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 2, "type"])], ((p, $0, f, $1, x) => {
        const filter = C.makeFilter($loader, f, '>=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '>=', new thingtalk_1.Ast.Value.Number(1));
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("with_filter", undefined)], ((p, $0, f) => {
        return C.makeAggregateFilterWithFilter(p, f, 'count', '*', '>=', new thingtalk_1.Ast.Value.Number(1));
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["greater than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 3, "type"])], ((v, p, $0, f, $1, x) => {
        const filter = C.makeFilter($loader, f, '<=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '==', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["more than", "at least", "no fewer than"]), new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Any", undefined)], (($0, x, p) => C.makeAggregateFilter(p, 'count', '*', '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["fewer than", "at most", "no more than"]), new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Any", undefined)], (($0, x, p) => C.makeAggregateFilter(p, 'count', '*', '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["more than", "at least", "no fewer than"]), new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_ArrayCount", undefined)], (($0, x, p) => C.makeFilter($loader, p, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["fewer than", "at most", "no more than"]), new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_ArrayCount", undefined)], (($0, x, p) => C.makeFilter($loader, p, '<=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["no more than", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["lower than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 4, "type"])], (($0, v, p, $1, f, $2, x) => {
        const filter = C.makeFilter($loader, f, '<=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '<=', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["at most", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["lower than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 4, "type"])], (($0, v, p, $1, f, $2, x) => {
        const filter = C.makeFilter($loader, f, '<=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '<=', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["fewer than", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["lower than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 4, "type"])], (($0, v, p, $1, f, $2, x) => {
        const filter = C.makeFilter($loader, f, '<=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '<=', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["more than", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["greater than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 4, "type"])], (($0, v, p, $1, f, $2, x) => {
        const filter = C.makeFilter($loader, f, '>=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '>=', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["at least", new $runtime.NonTerminal("constant_Number", undefined), new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.Choice(["greater than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 4, "type"])], (($0, v, p, $1, f, $2, x) => {
        const filter = C.makeFilter($loader, f, '>=', x);
        return C.makeAggregateFilterWithFilter(p, filter, 'count', '*', '>=', v);
    }), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'sum', null, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["greater than", "more than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'sum', null, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["lower than", "less than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'sum', null, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'sum', f, '==', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["greater than", "more than", "higher than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'sum', f, '>=', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["total", "sum"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["smaller than", "less than", "lower than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'sum', f, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'avg', null, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["greater than", "more than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'avg', null, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["lower than", "less than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'avg', null, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'avg', f, '==', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["greater than", "more than", "higher than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'avg', f, '>=', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", ["average", new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["smaller than", "less than", "lower than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'avg', f, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'max', null, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["greater than", "more than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'max', null, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["lower than", "less than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'max', null, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'max', f, '==', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["greater than", "more than", "higher than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'max', f, '>=', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["maximum", "highest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["smaller than", "less than", "lower than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'max', f, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'min', null, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["greater than", "more than", "above"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'min', null, '>=', x)), C.filterKeyFn, {});
    $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Array__Any", ["is_numeric_elem", (true)]), new $runtime.Choice(["lower than", "less than", "below"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "elem"])], (($0, p, $1, x) => C.makeAggregateFilter(p, 'min', null, '<=', x)), C.filterKeyFn, {});
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["of", "being"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'min', f, '==', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["greater than", "more than", "higher than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'min', f, '>=', x)), C.filterKeyFn, {});
    }
    if (!$options.flags.turking) {
        $grammar.addRule("with_filter", [new $runtime.Choice(["minimum", "lowest"]), new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), "of", new $runtime.NonTerminal("out_param_Array__Compound", undefined), new $runtime.Choice(["smaller than", "less than", "lower than"]), new $runtime.NonTerminal("constant_Numeric", ["type", 1, "type"])], (($0, f, $1, p, $2, x) => C.makeAggregateFilter(p, 'min', f, '>=', x)), C.filterKeyFn, {});
    }
    $grammar.declareSymbol("range_with_filter");
    $grammar.addRule("range_with_filter", [new $runtime.NonTerminal("out_param_Any", ["is_numeric", (true)]), new $runtime.NonTerminal("range", undefined)], ((param, range) => {
        const [v1, v2] = range;
        const f1 = C.makeFilter($loader, param, '>=', v1);
        const f2 = C.makeFilter($loader, param, '<=', v2);
        if (!f1 || !f2)
            return null;
        return { schema: f1.schema, ptype: f1.ptype,
            ast: new thingtalk_1.Ast.BooleanExpression.And(null, [f1.ast, f2.ast]) };
    }), C.filterKeyFn, {});
    $grammar.declareSymbol("both_prefix");
    $grammar.addRule("both_prefix", ["both"], (($0) => "both"), undefined, { identity: (true) });
    $grammar.declareSymbol("nearby_filter");
    $grammar.addRule("nearby_filter", ["here"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", ["around here"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", ["near here"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", ["nearby"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", ["around me"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", ["in this area"], (($0) => C.makeDomainIndependentFilter('geo', '==', HERE)), undefined, {});
    $grammar.addRule("nearby_filter", [new $runtime.Choice(["in", "around", "near"]), new $runtime.NonTerminal("constant_Location", undefined)], (($0, x) => C.makeDomainIndependentFilter('geo', '==', x)), undefined, {});
    $grammar.declareSymbol("whose_npp_filter");
    $grammar.addRule("whose_npp_filter", [new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.NonTerminal("constant_Any", undefined)], ((p, $0, x) => C.makeFilter($loader, p, '==', x)), C.filterKeyFn, {});
    $grammar.addRule("whose_npp_filter", [new $runtime.NonTerminal("out_param_Any", undefined), "is", new $runtime.NonTerminal("constant_Any", undefined)], ((p, $0, x) => C.makeFilter($loader, p, 'contains', x)), C.filterKeyFn, {});
    $grammar.declareSymbol("quality_filter");
    $grammar.addRule("quality_filter", ["good"], (($0) => C.makeDomainIndependentFilter('aggregateRating.ratingValue', '>=', new thingtalk_1.Ast.Value.Number(4))), undefined, {});
    $grammar.addRule("quality_filter", ["great"], (($0) => C.makeDomainIndependentFilter('aggregateRating.ratingValue', '>=', new thingtalk_1.Ast.Value.Number(4))), undefined, {});
    $grammar.addRule("quality_filter", ["nice"], (($0) => C.makeDomainIndependentFilter('aggregateRating.ratingValue', '>=', new thingtalk_1.Ast.Value.Number(4))), undefined, {});
    $grammar.addRule("quality_filter", ["decent"], (($0) => C.makeDomainIndependentFilter('aggregateRating.ratingValue', '>=', new thingtalk_1.Ast.Value.Number(4))), undefined, {});
    $grammar.declareSymbol("within_filter");
    $grammar.addRule("within_filter", ["within", new $runtime.NonTerminal("constant_Measure_m", undefined), new $runtime.Choice(["", "radius", "of here", "from here", "from me", "of me", "of this area", "of my location", "from current location"])], (($0, distance, $1) => ({ distance, place: HERE })), undefined, {});
    $grammar.addRule("within_filter", ["within", new $runtime.NonTerminal("constant_Measure_m", undefined), new $runtime.Choice(["", "radius"]), new $runtime.Choice(["of", "from"]), new $runtime.NonTerminal("constant_Location", undefined)], (($0, distance, $1, $2, place) => ({ distance, place })), undefined, {});
}
exports.default = default_1;
;
//# sourceMappingURL=filters.genie.js.map