| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Classes for custom functions for the speech rule engine. | 6 * @fileoverview Classes for custom functions for the speech rule engine. |
| 7 * | 7 * |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 goog.provide('cvox.SpeechRuleFunctions'); | 10 goog.provide('cvox.SpeechRuleFunctions'); |
| 11 goog.provide('cvox.SpeechRuleFunctions.ContextFunctions'); | 11 goog.provide('cvox.SpeechRuleFunctions.ContextFunctions'); |
| 12 goog.provide('cvox.SpeechRuleFunctions.CustomQueries'); | 12 goog.provide('cvox.SpeechRuleFunctions.CustomQueries'); |
| 13 goog.provide('cvox.SpeechRuleFunctions.CustomStrings'); | 13 goog.provide('cvox.SpeechRuleFunctions.CustomStrings'); |
| 14 | 14 |
| 15 | 15 |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @constructor | 18 * @constructor |
| 19 */ | 19 */ |
| 20 cvox.SpeechRuleFunctions = function() { }; | 20 cvox.SpeechRuleFunctions = function() {}; |
| 21 | 21 |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Private superclass of all the custom function stores. | 24 * Private superclass of all the custom function stores. |
| 25 * @constructor | 25 * @constructor |
| 26 * @param {string} prefix A prefix string for the function names. | 26 * @param {string} prefix A prefix string for the function names. |
| 27 * @param {Object<Function>} store Storage object. | 27 * @param {Object<Function>} store Storage object. |
| 28 * @private | 28 * @private |
| 29 */ | 29 */ |
| 30 cvox.SpeechRuleFunctions.Store_ = function(prefix, store) { | 30 cvox.SpeechRuleFunctions.Store_ = function(prefix, store) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 */ | 63 */ |
| 64 cvox.SpeechRuleFunctions.CustomQuery; | 64 cvox.SpeechRuleFunctions.CustomQuery; |
| 65 | 65 |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * @constructor | 68 * @constructor |
| 69 * @extends {cvox.SpeechRuleFunctions.Store_} | 69 * @extends {cvox.SpeechRuleFunctions.Store_} |
| 70 */ | 70 */ |
| 71 cvox.SpeechRuleFunctions.CustomQueries = function() { | 71 cvox.SpeechRuleFunctions.CustomQueries = function() { |
| 72 var store = | 72 var store = |
| 73 /** @type {Object<cvox.SpeechRuleFunctions.CustomQuery>} */ ({}); | 73 /** @type {Object<cvox.SpeechRuleFunctions.CustomQuery>} */ ({}); |
| 74 goog.base(this, 'CQF', store); | 74 goog.base(this, 'CQF', store); |
| 75 }; | 75 }; |
| 76 goog.inherits(cvox.SpeechRuleFunctions.CustomQueries, | 76 goog.inherits( |
| 77 cvox.SpeechRuleFunctions.Store_); | 77 cvox.SpeechRuleFunctions.CustomQueries, cvox.SpeechRuleFunctions.Store_); |
| 78 | 78 |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Context function for use in speech rules. | 81 * Context function for use in speech rules. |
| 82 * @typedef {function(!Node): string} | 82 * @typedef {function(!Node): string} |
| 83 */ | 83 */ |
| 84 cvox.SpeechRuleFunctions.CustomString; | 84 cvox.SpeechRuleFunctions.CustomString; |
| 85 | 85 |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @constructor | 88 * @constructor |
| 89 * @extends {cvox.SpeechRuleFunctions.Store_} | 89 * @extends {cvox.SpeechRuleFunctions.Store_} |
| 90 */ | 90 */ |
| 91 cvox.SpeechRuleFunctions.CustomStrings = function() { | 91 cvox.SpeechRuleFunctions.CustomStrings = function() { |
| 92 var store = | 92 var store = |
| 93 /** @type {Object<cvox.SpeechRuleFunctions.CustomString>} */ ({}); | 93 /** @type {Object<cvox.SpeechRuleFunctions.CustomString>} */ ({}); |
| 94 goog.base(this, 'CSF', store); | 94 goog.base(this, 'CSF', store); |
| 95 }; | 95 }; |
| 96 goog.inherits(cvox.SpeechRuleFunctions.CustomStrings, | 96 goog.inherits( |
| 97 cvox.SpeechRuleFunctions.Store_); | 97 cvox.SpeechRuleFunctions.CustomStrings, cvox.SpeechRuleFunctions.Store_); |
| 98 | 98 |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Context function for use in speech rules. | 101 * Context function for use in speech rules. |
| 102 * @typedef {function(Array<Node>, ?string): (function(): string)} | 102 * @typedef {function(Array<Node>, ?string): (function(): string)} |
| 103 */ | 103 */ |
| 104 cvox.SpeechRuleFunctions.ContextFunction; | 104 cvox.SpeechRuleFunctions.ContextFunction; |
| 105 | 105 |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * @constructor | 108 * @constructor |
| 109 * @extends {cvox.SpeechRuleFunctions.Store_} | 109 * @extends {cvox.SpeechRuleFunctions.Store_} |
| 110 */ | 110 */ |
| 111 cvox.SpeechRuleFunctions.ContextFunctions = function() { | 111 cvox.SpeechRuleFunctions.ContextFunctions = function() { |
| 112 var store = | 112 var store = |
| 113 /** @type {Object<cvox.SpeechRuleFunctions.ContextFunction>} */ | 113 /** @type {Object<cvox.SpeechRuleFunctions.ContextFunction>} */ |
| 114 ({}); | 114 ({}); |
| 115 goog.base(this, 'CTXF', store); | 115 goog.base(this, 'CTXF', store); |
| 116 }; | 116 }; |
| 117 goog.inherits(cvox.SpeechRuleFunctions.ContextFunctions, | 117 goog.inherits( |
| 118 cvox.SpeechRuleFunctions.Store_); | 118 cvox.SpeechRuleFunctions.ContextFunctions, cvox.SpeechRuleFunctions.Store_); |
| 119 | 119 |
| 120 | 120 |
| 121 /** | 121 /** |
| 122 * Checks validity for a custom function name. | 122 * Checks validity for a custom function name. |
| 123 * @param {string} name The name of the custom function. | 123 * @param {string} name The name of the custom function. |
| 124 * @return {!boolean} True if the name is valid. | 124 * @return {!boolean} True if the name is valid. |
| 125 * @private | 125 * @private |
| 126 */ | 126 */ |
| 127 cvox.SpeechRuleFunctions.Store_.prototype. | 127 cvox.SpeechRuleFunctions.Store_.prototype.checkCustomFunctionSyntax_ = function( |
| 128 checkCustomFunctionSyntax_ = function(name) { | 128 name) { |
| 129 var reg = new RegExp('^' + this.prefix_); | 129 var reg = new RegExp('^' + this.prefix_); |
| 130 if (!name.match(reg)) { | 130 if (!name.match(reg)) { |
| 131 console.log( | 131 console.log( |
| 132 'FunctionError: Invalid function name. Expected prefix' + | 132 'FunctionError: Invalid function name. Expected prefix' + this.prefix_); |
| 133 this.prefix_); | 133 return false; |
| 134 return false; | 134 } |
| 135 } | 135 return true; |
| 136 return true; | 136 }; |
| 137 }; | |
| OLD | NEW |