Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Callum Rogers
committed
Apr 2, 2012
1 parent
3b0d865
commit c9a5331
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(function() { | ||
|
||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
(function() { | ||
var bindIdent, matchInnerPattern, matchPattern, out, rawBindIdent, seeIfBinding, subIdent; | ||
bindIdent = {}; | ||
rawBindIdent = {}; | ||
subIdent = {}; | ||
seeIfBinding = function(bindings, args, value, pattern) { | ||
if ((pattern.__bindIdent != null) && pattern.__bindIdent === bindIdent) { | ||
bindings[pattern.binding] = value; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
matchInnerPattern = function(bindings, args, value, pattern) { | ||
if (pattern.innerPattern) { | ||
return matchPattern(bindings, args, value, pattern.innerPattern); | ||
} else { | ||
return true; | ||
} | ||
}; | ||
matchPattern = function(bindings, args, value, pattern) { | ||
var i, key, valuePattern, vtype, _ref; | ||
if (pattern === out.pun._) { | ||
return true; | ||
} | ||
if (pattern.__rawBindIdent === rawBindIdent) { | ||
args.push(value); | ||
return true; | ||
} | ||
if (seeIfBinding(bindings, args, value, pattern)) { | ||
return matchInnerPattern(bindings, args, value, pattern); | ||
} | ||
switch (typeof pattern) { | ||
case 'number': | ||
case 'string': | ||
case 'boolean': | ||
case null: | ||
case void 0: | ||
return pattern === value; | ||
case 'function': | ||
vtype = typeof value; | ||
switch (pattern) { | ||
case Number: | ||
return vtype === 'number' || value instanceof Number; | ||
case String: | ||
return vtype === 'string' || value instanceof String; | ||
case Boolean: | ||
return vtype === 'boolean' || value instanceof Boolean; | ||
default: | ||
return value instanceof pattern; | ||
} | ||
break; | ||
case 'object': | ||
if (Array.isArray(pattern)) { | ||
if (value.length !== pattern.length) { | ||
return false; | ||
} | ||
for (i = 0, _ref = value.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { | ||
if (!matchPattern(bindings, args, value[i], pattern[i])) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
for (key in pattern) { | ||
valuePattern = pattern[key]; | ||
if (!matchPattern(bindings, args, value[key], valuePattern)) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
}; | ||
out = this.windows || exports; | ||
out.pun = { | ||
_: {}, | ||
$: function(binding, innerPattern) { | ||
return { | ||
__bindIdent: bindIdent, | ||
binding: binding, | ||
innerPattern: innerPattern | ||
}; | ||
}, | ||
s: function(subPattern) { | ||
return { | ||
__subIdent: subIdent, | ||
subPattern: subPattern | ||
}; | ||
}, | ||
match: function() { | ||
var args; | ||
args = arguments; | ||
return function(value) { | ||
var bindings, i, matchArgs, matchFunc, pattern, _ref; | ||
for (i = 0, _ref = args.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { | ||
pattern = args[i++]; | ||
matchFunc = args[i]; | ||
bindings = {}; | ||
matchArgs = []; | ||
if (matchPattern(bindings, matchArgs, value, pattern)) { | ||
return matchFunc.apply(bindings, matchArgs); | ||
} | ||
} | ||
}; | ||
} | ||
}; | ||
out.pun.$.__rawBindIdent = rawBindIdent; | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.