From f1fc2707bb1081cf63169d71cde259482b7bcddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Smodi=C5=A1?= Date: Wed, 15 Jul 2015 22:32:32 +0200 Subject: Added support for displaying hints. For now triggered by hand via a console, e.g. FireBug. --- js/def_parser.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'js/def_parser.js') 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.} 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 -- cgit v1.2.1