Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
8 Makefile
View
@@ -10,8 +10,8 @@ JS = $(subst src/,lib/,$(SRC:.coffee=.js))
TESTSRC = $(wildcard src/tests/*.coffee)
TESTJS = $(subst src/,,$(TESTSRC:.coffee=.js))
-test: $(TESTJS)
-
- #RES = cat $@ sed -n '/<</,/>>/p' | sed 's/^[ \t]*//'
-
all: $(JS)
+ cat lib/start.js $(JS) lib/end.js >lib/pun.js
+
+test: $(TESTJS)
+ #RES = cat $@ sed -n '/<</,/>>/p' | sed 's/^[ \t]*//'
3  lib/curry.js
View
@@ -0,0 +1,3 @@
+(function() {
+
+}).call(this);
1  lib/end.js
View
@@ -0,0 +1 @@
+}).call(this);
106 lib/pattern.js
View
@@ -0,0 +1,106 @@
+(function() {
+ var bindIdent, matchInnerPattern, matchPattern, 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 === 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;
+ };
+ addExports({
+ _: {},
+ $: 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);
+ }
+ }
+ };
+ }
+ });
+ pun.$.__rawBindIdent = rawBindIdent;
+}).call(this);
27 lib/pun.js
View
@@ -1,5 +1,20 @@
+(function(){
+ var out = (typeof process === 'undefined' || !process.versions)
+ ? this.window || {}
+ : exports;
+
+ var pun = out.pun = {};
+
+ var addExports = function(es) {
+ for(var e in es)
+ pun[e] = es[e];
+ };
+
(function() {
- var bindIdent, matchInnerPattern, matchPattern, out, rawBindIdent, seeIfBinding, subIdent;
+
+}).call(this);
+(function() {
+ var bindIdent, matchInnerPattern, matchPattern, rawBindIdent, seeIfBinding, subIdent;
bindIdent = {};
rawBindIdent = {};
subIdent = {};
@@ -19,7 +34,7 @@
};
matchPattern = function(bindings, args, value, pattern) {
var i, key, valuePattern, vtype, _ref;
- if (pattern === out.pun._) {
+ if (pattern === pun._) {
return true;
}
if (pattern.__rawBindIdent === rawBindIdent) {
@@ -70,8 +85,7 @@
}
return true;
};
- out = this.windows || exports;
- out.pun = {
+ addExports({
_: {},
$: function(binding, innerPattern) {
return {
@@ -102,6 +116,7 @@
}
};
}
- };
- out.pun.$.__rawBindIdent = rawBindIdent;
+ });
+ pun.$.__rawBindIdent = rawBindIdent;
+}).call(this);
}).call(this);
12 lib/start.js
View
@@ -0,0 +1,12 @@
+(function(){
+ var out = (typeof process === 'undefined' || !process.versions)
+ ? this.window || {}
+ : exports;
+
+ var pun = out.pun = {};
+
+ var addExports = function(es) {
+ for(var e in es)
+ pun[e] = es[e];
+ };
+
0  src/curry.coffee
View
No changes.
11 src/pun.coffee → src/pattern.coffee
View
@@ -20,7 +20,7 @@ matchInnerPattern = (bindings, args, value, pattern) ->
matchPattern = (bindings, args, value, pattern) ->
# wildcard operator means we accept all
- if pattern == out.pun._
+ if pattern == pun._
return true
# see if it's a "raw param"
@@ -76,11 +76,7 @@ matchPattern = (bindings, args, value, pattern) ->
return true
-# export to window if browser or exports if node
-out = (this.windows || exports)
-
-out.pun =
-
+addExports(
# wildcard operator
_: {}
@@ -102,7 +98,8 @@ out.pun =
if matchPattern bindings, matchArgs, value, pattern
return matchFunc.apply bindings, matchArgs
+)
# add an ident to the raw $ so we can use it as a param
-out.pun.$.__rawBindIdent = rawBindIdent
+pun.$.__rawBindIdent = rawBindIdent
6 tests/load.html
View
@@ -1,5 +1,11 @@
<html>
<head>
<script src="../lib/pun.js" /></script>
+ <script>
+
+ var $ = pun.$;
+ var _ = pun._;
+
+ </script>
</head>
</html>

No commit comments for this range

Something went wrong with that request. Please try again.