-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcparser.js
33 lines (28 loc) · 909 Bytes
/
cparser.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
var CommandParser = function(cpu) {
var _cpu;
var commandparser = {}
function CommandParser(cpu) {
if (!(this instanceof CommandParser)) {
return new CommandParser(cpu);
}
_cpu = cpu;
}
CommandParser.prototype.addParser = function (command, parser) {
commandparser[command] = parser;
};
CommandParser.prototype.parse = function (commandstring, callback) {
var commandarr = commandstring.split(" ");
var options = [];
var command = commandarr[0];
for(var i=1; i<commandarr.length; i++) {
options.push(commandarr[i]);
}
if(typeof(command) === "string" && commandparser[command] !== undefined) {
commandparser[command].call(this, _cpu, options, callback);
} else {
_cpu.module("util").log("Unknown command: \"" + command + "\"");
}
};
return new CommandParser(cpu);
};
var exports = module.exports = CommandParser;