mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-31 08:04:40 +02:00
ok optimistic parsing going
This commit is contained in:
parent
8a1986a923
commit
f8b9c8b583
9 changed files with 1509 additions and 1317 deletions
|
@ -351,3 +351,4 @@ var LevelBuilder = Level.extend({
|
|||
});
|
||||
|
||||
exports.LevelBuilder = LevelBuilder;
|
||||
exports.regexMap = regexMap;
|
||||
|
|
|
@ -427,4 +427,4 @@ var Level = Sandbox.extend({
|
|||
});
|
||||
|
||||
exports.Level = Level;
|
||||
|
||||
exports.regexMap = regexMap;
|
||||
|
|
|
@ -4,8 +4,9 @@ var GitCommands = require('../git/commands');
|
|||
var SandboxCommands = require('../level/SandboxCommands');
|
||||
|
||||
// more or less a static class
|
||||
function ParseWaterfall(options) {
|
||||
var ParseWaterfall = function(options) {
|
||||
options = options || {};
|
||||
this.options = options;
|
||||
this.shortcutWaterfall = options.shortcutWaterfall || [
|
||||
GitCommands.shortcutMap
|
||||
];
|
||||
|
@ -15,11 +16,19 @@ function ParseWaterfall(options) {
|
|||
SandboxCommands.instantCommands
|
||||
];
|
||||
|
||||
this.parseWaterfall = options.parseWaterfall || [
|
||||
// defer the parse waterfall until later...
|
||||
};
|
||||
|
||||
ParseWaterfall.prototype.initParseWaterfall = function() {
|
||||
// by deferring the initialization here, we dont require()
|
||||
// level too early (which barfs our init)
|
||||
this.parseWaterfall = this.options.parseWaterfall || [
|
||||
GitCommands.parse,
|
||||
SandboxCommands.parse
|
||||
SandboxCommands.parse,
|
||||
SandboxCommands.getOptimisticLevelParse(),
|
||||
SandboxCommands.getOptimisticLevelBuilderParse()
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
ParseWaterfall.prototype.clone = function() {
|
||||
return new ParseWaterfall({
|
||||
|
@ -30,6 +39,9 @@ ParseWaterfall.prototype.clone = function() {
|
|||
};
|
||||
|
||||
ParseWaterfall.prototype.getWaterfallMap = function() {
|
||||
if (!this.parseWaterfall) {
|
||||
this.initParseWaterfall();
|
||||
}
|
||||
return {
|
||||
shortcutWaterfall: this.shortcutWaterfall,
|
||||
instantWaterfall: this.instantWaterfall,
|
||||
|
@ -83,6 +95,10 @@ ParseWaterfall.prototype.processInstant = function(commandStr, instantCommands)
|
|||
};
|
||||
|
||||
ParseWaterfall.prototype.parseAll = function(commandStr) {
|
||||
if (!this.parseWaterfall) {
|
||||
this.initParseWaterfall();
|
||||
}
|
||||
|
||||
var toReturn = false;
|
||||
_.each(this.parseWaterfall, function(parseFunc) {
|
||||
var results = parseFunc(commandStr);
|
||||
|
|
|
@ -60,3 +60,23 @@ var regexMap = {
|
|||
exports.instantCommands = instantCommands;
|
||||
exports.parse = util.genParseCommand(regexMap, 'processSandboxCommand');
|
||||
|
||||
// optimistically parse some level and level builder commands; we do this
|
||||
// so you can enter things like "level intro1; show goal" and not
|
||||
// have it barf. when the
|
||||
// command fires the event, it will check if there is a listener and if not throw
|
||||
// an error
|
||||
|
||||
// note: these are getters / setters because the require kills us
|
||||
exports.getOptimisticLevelParse = function() {
|
||||
return util.genParseCommand(
|
||||
require('../level').regexMap,
|
||||
'processLevelCommand'
|
||||
);
|
||||
};
|
||||
|
||||
exports.getOptimisticLevelBuilderParse = function() {
|
||||
return util.genParseCommand(
|
||||
require('../level/builder').regexMap,
|
||||
'processLevelBuilderCommand'
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue