-
Notifications
You must be signed in to change notification settings - Fork 1
/
runiq.js
36 lines (29 loc) · 1.05 KB
/
runiq.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
var Assign = require('lodash.assign');
var RuniqParser = require('./parser');
var RuniqInterpreter = require('./interpreter');
var RuniqLib = require('./lib');
var DEFAULT_OPTIONS = {};
function _createLibrary() {
return RuniqLib();
}
// Just a simplified wrapper API for executing Runiq programs,
// one that assumes you probably don't need to toy around with
// the parser etc. Pass a program string, and your options,
// which can/should include a `success` and `error` callback.
function run(program, options, library) {
var opts = Assign({}, DEFAULT_OPTIONS, options);
var argv = opts.argv || [];
var event = opts.event || null;
var tokens = RuniqParser.lex(program);
var ast = RuniqParser.parse(tokens);
if (!library) library = _createLibrary();
var interpreter = new RuniqInterpreter(library, opts);
interpreter.run(ast, argv, event, function(err, result) {
if (err && opts.error) return opts.error(err);
if (opts.success) return opts.success(result);
});
}
module.exports = {
run: run
};