// -*- 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: Giovanni Campagna import * as $runtime from "../sentence-generator/runtime"; import type $SentenceGenerator from "../sentence-generator/generator"; import * as $SentenceGeneratorTypes from "../sentence-generator/types"; import * as $I18n from "../i18n/index"; import { Ast, } from 'thingtalk'; import ThingpediaLoader from './load-thingpedia'; import * as C from './ast_manip'; export const timer : $SentenceGeneratorTypes.NonTerminal = "timer"; /** * Load the templates in this file. * * This is an autogenerated method that will be called by the {@link SentenceGenerator} * when the templates are imported. */ export async function $load($options : $SentenceGeneratorTypes.GrammarOptions, $locale : $I18n.LanguagePack, $grammar : $SentenceGenerator, $loader : ThingpediaLoader) : Promise { $grammar.declareSymbol("timer"); $grammar.addRule("timer", [new $runtime.NonTerminal("at_time", "time", undefined)], $locale._("{every day|each day|daily|once a day} ${time}"), ((time : Ast.Value) : (Ast.FunctionCallExpression)|null => C.makeRepeatingTimeTimer($loader, [time])), undefined, { }); $grammar.addRule("timer", [new $runtime.NonTerminal("constant_Time", "time1", undefined), new $runtime.NonTerminal("constant_Time", "time2", undefined)], $locale._("{every day|each day|daily|twice a day} at ${time1} and ${time2}"), ((time1 : Ast.Value, time2 : Ast.Value) : (Ast.FunctionCallExpression)|null => C.makeRepeatingTimeTimer($loader, [time1, time2])), undefined, { }); $grammar.addRule("timer", [new $runtime.NonTerminal("at_time", "time", undefined)], "${time}", ((time : Ast.Value) : (Ast.FunctionCallExpression)|null => C.makeDateTimer($loader, C.makeDateWithDateTime(null, time))), undefined, { }); $grammar.addRule("timer", [new $runtime.NonTerminal("constant_Date", "date", undefined)], $locale._("on ${date}"), ((date : Ast.Value) : (Ast.FunctionCallExpression)|null => C.makeDateTimer($loader, date)), undefined, { }); if (!$options.flags.turking) { $grammar.addRule("timer", [new $runtime.NonTerminal("unit_Measure_ms", "unit", undefined)], $locale._("{once {each|every|per|a}|each|every} ${unit}"), ((unit : 'ms'|'s'|'min'|'h'|'day'|'week'|'mon'|'year') : (Ast.FunctionCallExpression)|null => C.makeIntervalTimer($loader, unit)), undefined, { }); $grammar.addRule("timer", [new $runtime.NonTerminal("constant_Number", "freq", undefined), new $runtime.NonTerminal("unit_Measure_ms", "unit", undefined)], $locale._("${freq} times {each|every|per|a} ${unit}"), ((freq : Ast.NumberValue, unit : 'ms'|'s'|'min'|'h'|'day'|'week'|'mon'|'year') : (Ast.FunctionCallExpression)|null => C.makeFrequencyTimer($loader, freq, unit)), undefined, { }); } };