diff options
author | Aleš Smodiš <aless@guru.si> | 2015-07-15 22:32:32 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-07-15 22:32:32 +0200 |
commit | f1fc2707bb1081cf63169d71cde259482b7bcddc (patch) | |
tree | ddac344f39d8134a675c8b80df5bd37f2960dc0f /js/def_parser.js | |
parent | 6a7d1532a223ccf6d69f573c4d6b91fa2bc840d8 (diff) |
Added support for displaying hints. For now triggered by hand via a console, e.g. FireBug.
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 |