From f704918fe2b187d715fe985ebffebdfbdc4b541f Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Wed, 14 Sep 2016 16:15:20 -0400 Subject: Add repeat and input --- lib/doml.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/doml.js') diff --git a/lib/doml.js b/lib/doml.js index c813db9..181f574 100644 --- a/lib/doml.js +++ b/lib/doml.js @@ -151,6 +151,23 @@ 'call': function(dataset, children, context) { return context[dataset.name](children); + }, + + 'repeat': function(dataset, children, context) { + var times = me.evaluate(children[0], context); + for (var n = 0; n < times; n++) { + if (dataset.iteration) { + context[dataset.iteration] = n; + } + me.evaluate(children[1], context); + } + }, + + 'input': function(dataset, children, context) { + var msg = dataset.prompt || dataset.name; + var rawInput = prompt(dataset.prompt); + context[dataset.name] = me.Types[dataset.type](rawInput); + return context[dataset.name]; } }; @@ -176,6 +193,22 @@ 'bin-op': function(e) { return [ e.dataset.op ]; + }, + + 'input': function(e) { + return [ e.dataset.name ]; + }, + + 'call': function(e) { + return [ e.dataset.name ]; + }, + + 'function': function(e) { + return [ e.dataset.args ]; + }, + + 'repeat': function(e) { + return [ e.dataset.iteration ]; } }; -- cgit v1.2.3