"use strict";
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 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: 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;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Coref actions: actions that operate on the current result, referred by coreference ("it", "that", "the restaurant")
const thingtalk_1 = require("thingtalk");
const C = __importStar(require("../../ast_manip"));
const D = __importStar(require("../../dialogue_acts"));
async function default_1($runtime, $ttUtils, $options, $locale, $grammar, $loader) {
    $grammar.declareSymbol("coref_action_phrase");
    $grammar.addRule("coref_action_phrase", [new $runtime.NonTerminal("action_coref_context", undefined)], ((action) => {
        if (!(action.expression instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        if (action.slot !== null || !$loader.isIDType(action.type)) // TODO: non-id parameter passing
            return null;
        return C.replacePlaceholderWithUndefined(action.expression.invocation, action.pname);
    }), C.invocationKeyFn, {});
    $grammar.addRule("coref_action_phrase", [new $runtime.NonTerminal("get_command_coref_context", undefined)], ((action) => {
        if (!(action.expression instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        if (action.slot !== null || !$loader.isIDType(action.type)) // TODO: non-id parameter passing
            return null;
        return C.replacePlaceholderWithUndefined(action.expression.invocation, action.pname);
    }), C.invocationKeyFn, {});
    $grammar.declareSymbol("list_coref_action_phrase");
    $grammar.addRule("list_coref_action_phrase", [new $runtime.NonTerminal("action_coref_list_context", undefined)], ((action) => {
        if (!(action.expression instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        if (action.slot !== null || !$loader.isIDType(action.type)) // TODO: non-id parameter passing
            return null;
        return C.replacePlaceholderWithUndefined(action.expression.invocation, action.pname);
    }), C.invocationKeyFn, {});
    $grammar.addRule("list_coref_action_phrase", [new $runtime.NonTerminal("get_command_coref_list_context", undefined)], ((action) => {
        if (!(action.expression instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        if (action.slot !== null || !$loader.isIDType(action.type)) // TODO: non-id parameter passing
            return null;
        return C.replacePlaceholderWithUndefined(action.expression.invocation, action.pname);
    }), C.invocationKeyFn, {});
    $grammar.declareSymbol("contextual_action_phrase");
    $grammar.addRule("contextual_action_phrase", [new $runtime.NonTerminal("complete_action", undefined)], ((action) => {
        if (!(action instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        return action.invocation;
    }), C.invocationKeyFn, {});
    $grammar.addRule("contextual_action_phrase", [new $runtime.NonTerminal("complete_get_command", undefined)], ((action) => {
        if (!(action instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        return action.invocation;
    }), C.invocationKeyFn, {});
    $grammar.declareSymbol("action_coref_recommendation");
    $grammar.addRule("action_coref_recommendation", ["would you like to", new $runtime.NonTerminal("coref_action_phrase", undefined), "?"], (($0, action, $1) => {
        if (action.in_params.some((ip) => !ip.value.isUndefined))
            return null;
        return action;
    }), C.invocationKeyFn, { priority: (1) });
    $grammar.addRule("action_coref_recommendation", ["would you like me to", new $runtime.NonTerminal("coref_action_phrase", undefined), " for you ?"], (($0, action, $1) => {
        if (action.in_params.some((ip) => !ip.value.isUndefined))
            return null;
        return action;
    }), C.invocationKeyFn, { priority: (1) });
    $grammar.declareSymbol("action_coref_list_proposal");
    $grammar.addRule("action_coref_list_proposal", ["would you like to", new $runtime.NonTerminal("list_coref_action_phrase", undefined), "?"], (($0, action, $1) => {
        if (action.in_params.some((ip) => !ip.value.isUndefined))
            return null;
        return action;
    }), C.invocationKeyFn, { priority: (1) });
    $grammar.declareSymbol("coref_action_command");
    $grammar.addRule("coref_action_command", [new $runtime.NonTerminal("ctx_with_action", undefined), new $runtime.NonTerminal("coref_action_phrase", ["functionName", 0, "nextFunction"])], ((ctx, base) => D.contextualAction(ctx, base)), C.invocationKeyFn, {});
    $grammar.addRule("coref_action_command", [new $runtime.NonTerminal("ctx_without_action", undefined), new $runtime.NonTerminal("coref_action_phrase", undefined)], ((ctx, base) => base), C.invocationKeyFn, {});
    $grammar.addRule("coref_action_command", [new $runtime.NonTerminal("coref_action_command", undefined), new $runtime.NonTerminal("preposition_input_param", ["functionName", 0, "functionName"])], ((action, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.addRule("coref_action_command", [new $runtime.NonTerminal("coref_action_command", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("npp_input_param", ["functionName", 0, "functionName"])], ((action, $0, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.declareSymbol("action_by_name_command");
    $grammar.addRule("action_by_name_command", [new $runtime.NonTerminal("ctx_incomplete_action", undefined), new $runtime.NonTerminal("contextual_action_phrase", ["functionName", 0, "nextFunction"])], ((ctx, base) => D.contextualAction(ctx, base)), C.invocationKeyFn, {});
    $grammar.addRule("action_by_name_command", [new $runtime.NonTerminal("ctx_without_action", undefined), new $runtime.NonTerminal("contextual_action_phrase", undefined)], ((ctx, base) => base), C.invocationKeyFn, {});
    $grammar.addRule("action_by_name_command", [new $runtime.NonTerminal("action_by_name_command", undefined), new $runtime.NonTerminal("preposition_input_param", ["functionName", 0, "functionName"])], ((action, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.addRule("action_by_name_command", [new $runtime.NonTerminal("action_by_name_command", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("npp_input_param", ["functionName", 0, "functionName"])], ((action, $0, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.declareSymbol("action_continuation_command");
    $grammar.addRule("action_continuation_command", [new $runtime.NonTerminal("ctx_incomplete_action", undefined), new $runtime.NonTerminal("coref_action_phrase", ["functionName", 0, "nextFunction"])], ((ctx, base) => D.contextualAction(ctx, base)), C.invocationKeyFn, {});
    $grammar.addRule("action_continuation_command", [new $runtime.NonTerminal("ctx_incomplete_action", undefined), new $runtime.NonTerminal("contextual_action_phrase", ["functionName", 0, "nextFunction"])], ((ctx, base) => D.contextualAction(ctx, base)), C.invocationKeyFn, {});
    $grammar.addRule("action_continuation_command", [new $runtime.NonTerminal("action_continuation_command", undefined), new $runtime.NonTerminal("preposition_input_param", ["functionName", 0, "functionName"])], ((action, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.addRule("action_continuation_command", [new $runtime.NonTerminal("action_continuation_command", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("npp_input_param", ["functionName", 0, "functionName"])], ((action, $0, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.declareSymbol("continuation_query");
    $grammar.addRule("continuation_query", [new $runtime.NonTerminal("ctx_incomplete_action", undefined), new $runtime.NonTerminal("complete_table", ["functionName", 0, "nextFunction"])], ((ctx, base) => {
        if (!(base instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        return D.contextualAction(ctx, base.invocation);
    }), C.invocationKeyFn, {});
    $grammar.declareSymbol("action_description_phrase");
    $grammar.addRule("action_description_phrase", [new $runtime.NonTerminal("coref_action_phrase", undefined)], (($0) => { return $0; }), C.invocationKeyFn, { identity: (true) });
    $grammar.addRule("action_description_phrase", [new $runtime.NonTerminal("thingpedia_complete_action", undefined)], ((action) => {
        if (!(action instanceof thingtalk_1.Ast.InvocationExpression))
            return null;
        return action.invocation;
    }), C.invocationKeyFn, {});
    $grammar.addRule("action_description_phrase", [new $runtime.NonTerminal("action_description_phrase", undefined), new $runtime.NonTerminal("preposition_input_param", ["functionName", 0, "functionName"])], ((action, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
    $grammar.addRule("action_description_phrase", [new $runtime.NonTerminal("action_description_phrase", undefined), new $runtime.Choice(["with", "having"]), new $runtime.NonTerminal("npp_input_param", ["functionName", 0, "functionName"])], ((action, $0, param) => C.addInvocationInputParam($loader, action, param)), C.invocationKeyFn, {});
}
exports.default = default_1;
;
//# sourceMappingURL=coref-actions.genie.js.map