diff options
Diffstat (limited to 'js/def_parser.js')
-rw-r--r-- | js/def_parser.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/js/def_parser.js b/js/def_parser.js index 91ca35d..fd34e80 100644 --- a/js/def_parser.js +++ b/js/def_parser.js @@ -356,6 +356,23 @@ else throw new Error("Unexpected token: expected a string, number, object, or array, at line " + token.line + ", column " + token.column); }; + + /** + * @typedef {string|{type: string, message: string}} HintDefinition + */ + /** + * @typedef {Object} PrologTaskDef a Prolog assignment definition + * @property {string} description the assignment description + * @property {Object.<string, HintDefinition>} hint the assignment hint definitions, keyed by hint ID + */ + + /** + * Converts the given pythonic assignment definition into a JavaScriptish definition, + * executes it, and takes the variables "description" and "hint" from the definition. + * + * @param {string} definition The assignment definition. + * @returns {PrologTaskDef} + */ codeq.parseDefinition = function (definition) { var next = tokenize(definition), vars = { 'description': true, 'hint': true }, @@ -408,12 +425,11 @@ } parts[0] = 'var ' + v.join(', ') + ';\n'; - parts.push(';\n__params__.description = description;\n__params__.hint = hint;'); + parts.push(';\nreturn {"description":description,"hint":hint};'); v = parts.join(''); codeq.log.debug("Creating a new parseInfo function having the body:\n" + v); fn = new Function("__params__", v); - obj = {}; - fn(obj); + obj = fn(); return obj; // obj now contains "description" and "hint" }; // parseDefinition |