aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-09-14 15:14:39 -0400
committerBen Burwell <ben.burwell@trifecta.com>2016-09-14 15:14:39 -0400
commit2c1eee7b2a99985bbe92426368ea32360a4cc0b2 (patch)
treeff5ab31064f64a742d213bc08d5a0e3aa95e74e7
parent7ce57c859ab914d65df9c659e1a6ef3fde79c63c (diff)
Implement functions/calls
-rw-r--r--lib/doml.js15
-rw-r--r--prog/function.html31
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/doml.js b/lib/doml.js
index 332a17e..c813db9 100644
--- a/lib/doml.js
+++ b/lib/doml.js
@@ -136,6 +136,21 @@
return me.evaluate(child, context);
});
console.log.apply(this, args);
+ },
+
+ 'function': function(dataset, children, context) {
+ var argNames = dataset.args.split(',');
+ return function(argValues) {
+ for (var idx = 0; idx < argNames.length; idx++) {
+ var argName = argNames[idx];
+ context[argName] = me.evaluate(argValues[idx], context);
+ }
+ me.evaluate(children[0], context);
+ }
+ },
+
+ 'call': function(dataset, children, context) {
+ return context[dataset.name](children);
}
};
diff --git a/prog/function.html b/prog/function.html
new file mode 100644
index 0000000..2fe8d40
--- /dev/null
+++ b/prog/function.html
@@ -0,0 +1,31 @@
+<!doctype html>
+<html>
+ <head>
+ <script src="../lib/doml.js"></script>
+ <script>
+ Doml.runOnLoad();
+ </script>
+ <link type="stylesheet" href="../lib/style.css">
+ </head>
+ <body>
+ <span class="statement-sequence">
+ <span class="assign" data-name="myFunc">
+ <span class="function" data-args="stringToPrint,val1,val2">
+ <span class="print">
+ <span class="variable" data-name="stringToPrint"></span>
+ <span class="bin-op" data-op="+">
+ <span class="variable" data-name="val1"></span>
+ <span class="variable" data-name="val2"></span>
+ </span>
+ </span>
+ </span>
+ </span>
+
+ <span class="call" data-name="myFunc">
+ <span class="constant" data-val="hello, world!" data-type="string"></span>
+ <span class="constant" data-val="3.5" data-type="number"></span>
+ <span class="constant" data-val="7" data-type="number"></span>
+ </span>
+ </span>
+ </body>
+</html>