goodguide-gibbon 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/goodguide-gibbon.gemspec +2 -1
- data/lib/goodguide/gibbon.rb +95 -43
- data/lib/goodguide/gibbon/version.rb +1 -1
- data/vendor/gibbon/lib/gibbon.browser.dev.js +2906 -0
- data/vendor/gibbon/lib/gibbon.browser.js +206 -199
- data/vendor/gibbon/package.json +2 -1
- metadata +3 -2
@@ -339,7 +339,7 @@ var Gibbon;
|
|
339
339
|
|
340
340
|
Gibbon = {};
|
341
341
|
// Generated by CoffeeScript 1.6.3
|
342
|
-
var CompMap, Hash, Map, Union, allocate, asyncMap, catLists, contIter, contMap, genId, isArray, uniq, _ref,
|
342
|
+
var CompMap, DEBUG, Hash, Map, Union, allocate, asyncMap, catLists, contIter, contMap, genId, isArray, uniq, _ref,
|
343
343
|
__slice = [].slice,
|
344
344
|
__hasProp = {}.hasOwnProperty,
|
345
345
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
@@ -352,6 +352,12 @@ genId = (function() {
|
|
352
352
|
};
|
353
353
|
})();
|
354
354
|
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
355
361
|
isArray = Array.isArray || function(arg) {
|
356
362
|
return Object.prototype.toString.call(arg) === '[object Array]';
|
357
363
|
};
|
@@ -849,10 +855,10 @@ Gibbon.AST = AST = (function(_super) {
|
|
849
855
|
percent: ['value'],
|
850
856
|
fraction: ['numerator', 'denominator'],
|
851
857
|
string: ['value'],
|
852
|
-
accessor: ['name'],
|
853
858
|
subst: ['flow'],
|
854
859
|
block: ['flow'],
|
855
860
|
list: ['elements'],
|
861
|
+
query: ['type', 'name'],
|
856
862
|
func: ['name', 'args'],
|
857
863
|
pair: ['first', 'second'],
|
858
864
|
flow: ['head', 'tail'],
|
@@ -887,8 +893,11 @@ Gibbon.AST = AST = (function(_super) {
|
|
887
893
|
string: function(s) {
|
888
894
|
return "'" + s + "'";
|
889
895
|
},
|
890
|
-
|
891
|
-
|
896
|
+
query: function(query, name) {
|
897
|
+
if (query === 'access') {
|
898
|
+
query = '';
|
899
|
+
}
|
900
|
+
return "@" + query + "(" + name + ")";
|
892
901
|
},
|
893
902
|
subst: function(flow) {
|
894
903
|
return "(" + (flow.inspect()) + ")";
|
@@ -983,12 +992,20 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
|
|
983
992
|
arrow: ['from', 'to']
|
984
993
|
});
|
985
994
|
|
995
|
+
TypeAST.parse = function(str) {
|
996
|
+
return parse.type(str);
|
997
|
+
};
|
998
|
+
|
999
|
+
TypeAST.parseUnit = function(str) {
|
1000
|
+
return parse.unitType(str);
|
1001
|
+
};
|
1002
|
+
|
986
1003
|
return TypeAST;
|
987
1004
|
|
988
1005
|
})(Union);
|
989
1006
|
|
990
1007
|
parse = Gibbon.parse = (function() {
|
991
|
-
var
|
1008
|
+
var arrow, arrowType, assertString, bang, blockExpr, blockType, comma, comment, component, concrete, decimal, decimalExpr, define, definition, expr, fail, flow, fraction, fractionExpr, frame, freeFrame, fullSignature, func, funcPlaceholder, identifier, ignore, innerFrame, integer, integerExpr, isString, label, labelVal, lbrace, lbrack, lexeme, listExpr, listType, lparen, metadata, name, nativeId, nativeType, nonPairedFlow, numericExpr, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, question, rbrace, rbrack, regex, rparen, signature, simpleType, singletonFlow, str, string, stringExpr, substExpr, succeed, tassign, type, typeVar, variable, whitespace, wildType, wildcard;
|
992
1009
|
string = Parsimmon.string, regex = Parsimmon.regex, succeed = Parsimmon.succeed, fail = Parsimmon.fail;
|
993
1010
|
Parsimmon.Parser.prototype.expected = function(message) {
|
994
1011
|
var _this = this;
|
@@ -1025,9 +1042,9 @@ parse = Gibbon.parse = (function() {
|
|
1025
1042
|
lparen = lexeme(string('('));
|
1026
1043
|
rparen = lexeme(string(')'));
|
1027
1044
|
comma = lexeme(string(','));
|
1045
|
+
question = lexeme(string('?'));
|
1028
1046
|
name = lexeme(identifier);
|
1029
1047
|
str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'").expected()));
|
1030
|
-
accessor = lexeme(string('@').then(identifier.expected()));
|
1031
1048
|
fraction = lexeme(regex(/^\d+\/\d+/));
|
1032
1049
|
decimal = lexeme(regex(/^\d+\.\d+/));
|
1033
1050
|
percent = lexeme(regex(/^\d+%/));
|
@@ -1054,10 +1071,20 @@ parse = Gibbon.parse = (function() {
|
|
1054
1071
|
stringExpr = str.map(function(s) {
|
1055
1072
|
return AST.string(s);
|
1056
1073
|
});
|
1074
|
+
query = string('@').then((function() {
|
1075
|
+
var accessor, fullQuery, parenName;
|
1076
|
+
parenName = lparen.then(lexeme(identifier).expected()).skip(rparen.expected());
|
1077
|
+
accessor = parenName.map(function(name) {
|
1078
|
+
return AST.query('access', name);
|
1079
|
+
});
|
1080
|
+
fullQuery = identifier.then(function(q) {
|
1081
|
+
return parenName.map(function(name) {
|
1082
|
+
return AST.query(q, name);
|
1083
|
+
});
|
1084
|
+
});
|
1085
|
+
return accessor.or(fullQuery);
|
1086
|
+
})());
|
1057
1087
|
numericExpr = percentExpr.or(decimalExpr.or(fractionExpr.or(integerExpr)));
|
1058
|
-
accessorExpr = accessor.map(function(name) {
|
1059
|
-
return AST.accessor(name);
|
1060
|
-
});
|
1061
1088
|
parenFlow = lparen.then(function() {
|
1062
1089
|
return flow.expected().skip(rparen.expected());
|
1063
1090
|
});
|
@@ -1077,7 +1104,7 @@ parse = Gibbon.parse = (function() {
|
|
1077
1104
|
blockExpr = lbrace.then(function() {
|
1078
1105
|
return flow.skip(rbrace.expected());
|
1079
1106
|
}).map(AST.block);
|
1080
|
-
expr =
|
1107
|
+
expr = query.or(substExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr)))));
|
1081
1108
|
singletonFlow = expr.map(function(e) {
|
1082
1109
|
return AST.flow(e, null);
|
1083
1110
|
});
|
@@ -1443,7 +1470,7 @@ Gibbon.Semantic = Semantic = (function(_super) {
|
|
1443
1470
|
Semantic.types({
|
1444
1471
|
definition: ['dependencies', 'flow'],
|
1445
1472
|
literal: ['syntax'],
|
1446
|
-
|
1473
|
+
query: ['annotations'],
|
1447
1474
|
localAccessor: ['name'],
|
1448
1475
|
pair: ['first', 'second'],
|
1449
1476
|
block: ['body'],
|
@@ -1466,7 +1493,7 @@ Gibbon.TypeLookup = TypeLookup = (function(_super) {
|
|
1466
1493
|
}
|
1467
1494
|
|
1468
1495
|
TypeLookup.types({
|
1469
|
-
response: ['
|
1496
|
+
response: ['analysis'],
|
1470
1497
|
local: ['name']
|
1471
1498
|
});
|
1472
1499
|
|
@@ -1531,7 +1558,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1531
1558
|
TypeExpr.types({
|
1532
1559
|
expr: ['expr'],
|
1533
1560
|
variable: ['name'],
|
1534
|
-
|
1561
|
+
query: ['input', 'scope', 'query'],
|
1535
1562
|
destructure: ['constraint', 'name', 'argnum'],
|
1536
1563
|
"native": ['id'],
|
1537
1564
|
param: ['name', 'constraints'],
|
@@ -1569,8 +1596,8 @@ analyze = Gibbon.analyze = (function() {
|
|
1569
1596
|
variable: function(name) {
|
1570
1597
|
return "%" + name;
|
1571
1598
|
},
|
1572
|
-
|
1573
|
-
return "@" +
|
1599
|
+
query: function(input, _, query) {
|
1600
|
+
return "@" + query.type + "(" + query.name + ")[" + (input.inspect()) + "]";
|
1574
1601
|
},
|
1575
1602
|
destructure: function(constraint, name, argnum) {
|
1576
1603
|
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
@@ -1609,11 +1636,11 @@ analyze = Gibbon.analyze = (function() {
|
|
1609
1636
|
expr: function(e) {
|
1610
1637
|
return e === other.expr;
|
1611
1638
|
},
|
1612
|
-
|
1639
|
+
query: function(input, scope, query) {
|
1613
1640
|
if (scope !== other.scope) {
|
1614
1641
|
return false;
|
1615
1642
|
}
|
1616
|
-
if (
|
1643
|
+
if (query !== other.query) {
|
1617
1644
|
return false;
|
1618
1645
|
}
|
1619
1646
|
return input.equals(other.input);
|
@@ -1623,7 +1650,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1623
1650
|
},
|
1624
1651
|
param: function(name, constraints) {
|
1625
1652
|
var constraint, i, _i, _len;
|
1626
|
-
if (name !== other.
|
1653
|
+
if (name !== other.type) {
|
1627
1654
|
return false;
|
1628
1655
|
}
|
1629
1656
|
for (i = _i = 0, _len = constraints.length; _i < _len; i = ++_i) {
|
@@ -1635,7 +1662,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1635
1662
|
return true;
|
1636
1663
|
},
|
1637
1664
|
destructure: function(constraint, name, argnum) {
|
1638
|
-
if (name !== other.
|
1665
|
+
if (name !== other.type) {
|
1639
1666
|
return false;
|
1640
1667
|
}
|
1641
1668
|
if (argnum !== other.argnum) {
|
@@ -1699,8 +1726,8 @@ analyze = Gibbon.analyze = (function() {
|
|
1699
1726
|
return _results;
|
1700
1727
|
})());
|
1701
1728
|
},
|
1702
|
-
|
1703
|
-
return TypeExpr.
|
1729
|
+
query: function(input, scope, query) {
|
1730
|
+
return TypeExpr.query(f(input), scope, query);
|
1704
1731
|
},
|
1705
1732
|
destructure: function(constraint, name, argnum) {
|
1706
1733
|
return TypeExpr.destructure(f(constraint), name, argnum);
|
@@ -1718,9 +1745,9 @@ analyze = Gibbon.analyze = (function() {
|
|
1718
1745
|
return cb(TypeExpr.param(name, ps));
|
1719
1746
|
});
|
1720
1747
|
},
|
1721
|
-
|
1748
|
+
query: function(input, scope, query) {
|
1722
1749
|
return f(input, function(i) {
|
1723
|
-
return cb(TypeExpr.
|
1750
|
+
return cb(TypeExpr.query(i, scope, query));
|
1724
1751
|
});
|
1725
1752
|
},
|
1726
1753
|
destructure: function(param, name, argnum) {
|
@@ -1745,12 +1772,12 @@ analyze = Gibbon.analyze = (function() {
|
|
1745
1772
|
this.externalLookup = externalLookup;
|
1746
1773
|
}
|
1747
1774
|
|
1748
|
-
NativeContext.prototype.
|
1749
|
-
return this.externalLookup.call(null, id,
|
1775
|
+
NativeContext.prototype.query = function(id, query, cb) {
|
1776
|
+
return this.externalLookup.call(null, id, query, TypeAST, function(err, analysis) {
|
1750
1777
|
if (err) {
|
1751
1778
|
throw err;
|
1752
1779
|
}
|
1753
|
-
return cb(TypeLookup.response(
|
1780
|
+
return cb(TypeLookup.response(analysis));
|
1754
1781
|
});
|
1755
1782
|
};
|
1756
1783
|
|
@@ -1776,17 +1803,17 @@ analyze = Gibbon.analyze = (function() {
|
|
1776
1803
|
return new Scope(this, this.breadcrumbs.concat([name]), frame, this.context);
|
1777
1804
|
};
|
1778
1805
|
|
1779
|
-
Scope.prototype.lookup = function(nativeId,
|
1806
|
+
Scope.prototype.lookup = function(nativeId, query, cb) {
|
1780
1807
|
var lexical;
|
1781
|
-
if (nativeId === this.context.globalID) {
|
1782
|
-
lexical = this.lexicalLookup(name);
|
1808
|
+
if (query.type === 'access' && nativeId === this.context.globalID) {
|
1809
|
+
lexical = this.lexicalLookup(query.name);
|
1783
1810
|
if (lexical) {
|
1784
1811
|
return cb(lexical);
|
1785
1812
|
} else {
|
1786
|
-
return this.context.
|
1813
|
+
return this.context.query(nativeId, query, cb);
|
1787
1814
|
}
|
1788
1815
|
} else {
|
1789
|
-
return this.context.
|
1816
|
+
return this.context.query(nativeId, query, cb);
|
1790
1817
|
}
|
1791
1818
|
};
|
1792
1819
|
|
@@ -1843,10 +1870,10 @@ analyze = Gibbon.analyze = (function() {
|
|
1843
1870
|
this.analyzeFlow(flow.tail, global, push);
|
1844
1871
|
}
|
1845
1872
|
return flow.head.cases({
|
1846
|
-
|
1873
|
+
query: function() {
|
1847
1874
|
var input;
|
1848
1875
|
input = flow.tail ? TypeExpr.expr(flow.tail) : global;
|
1849
|
-
return push(TypeExpr.expr(flow), TypeExpr.
|
1876
|
+
return push(TypeExpr.expr(flow), TypeExpr.query(input, _this, flow.head));
|
1850
1877
|
},
|
1851
1878
|
pair: function(first, second) {
|
1852
1879
|
_this.analyzeFlow(first, global, push);
|
@@ -1934,7 +1961,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1934
1961
|
};
|
1935
1962
|
})();
|
1936
1963
|
solve = (function() {
|
1937
|
-
var TypeError, consume,
|
1964
|
+
var TypeError, consume, _ref4;
|
1938
1965
|
TypeError = (function(_super) {
|
1939
1966
|
__extends(TypeError, _super);
|
1940
1967
|
|
@@ -1954,9 +1981,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1954
1981
|
return TypeError;
|
1955
1982
|
|
1956
1983
|
})(Union);
|
1957
|
-
|
1958
|
-
return console.log(prefix, lhs.inspect(), '=', rhs.inspect());
|
1959
|
-
};
|
1984
|
+
|
1960
1985
|
consume = function(array, next, body) {
|
1961
1986
|
var loop_, push;
|
1962
1987
|
push = function(x, y) {
|
@@ -1982,21 +2007,18 @@ analyze = Gibbon.analyze = (function() {
|
|
1982
2007
|
frameTypes = new Hash;
|
1983
2008
|
locks = new Hash;
|
1984
2009
|
solveEntry = function(crumbs, solved) {
|
1985
|
-
var constraints, dependencies, done, error, frame, fullSubstitute, key,
|
2010
|
+
var constraints, dependencies, done, error, frame, fullSubstitute, key, nextCrumbs, semanticAccessors, simplify, substitute, _ref5;
|
1986
2011
|
key = crumbs[crumbs.length - 1];
|
1987
2012
|
if (semantics.has(key)) {
|
1988
2013
|
return solved();
|
1989
2014
|
}
|
1990
2015
|
nextCrumbs = crumbs.concat([key]);
|
1991
2016
|
_ref5 = constraintMap.get(key), frame = _ref5.frame, constraints = _ref5.constraints;
|
1992
|
-
|
2017
|
+
|
1993
2018
|
locks.set(key, true);
|
1994
2019
|
semanticAccessors = new CompMap;
|
1995
2020
|
dependencies = [];
|
1996
|
-
|
1997
|
-
_ref6 = constraints[_i], lhs = _ref6[0], rhs = _ref6[1];
|
1998
|
-
logConstraint('-> ', lhs, rhs);
|
1999
|
-
}
|
2021
|
+
|
2000
2022
|
substitute = function(texpr, cb) {
|
2001
2023
|
return solutions.fetchAsync(texpr, (function() {
|
2002
2024
|
return texpr.mapAsync(substitute, cb);
|
@@ -2005,9 +2027,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2005
2027
|
fullSubstitute = function(texpr, cb) {
|
2006
2028
|
return substitute(texpr, function(substituted) {
|
2007
2029
|
return simplify(substituted, function(result) {
|
2008
|
-
|
2009
|
-
logConstraint('%> ', texpr, result);
|
2010
|
-
}
|
2030
|
+
|
2011
2031
|
return cb(result);
|
2012
2032
|
});
|
2013
2033
|
});
|
@@ -2038,22 +2058,21 @@ analyze = Gibbon.analyze = (function() {
|
|
2038
2058
|
}));
|
2039
2059
|
});
|
2040
2060
|
},
|
2041
|
-
|
2061
|
+
query: function(input, scope, query) {
|
2042
2062
|
return simplify(input, function(x) {
|
2043
2063
|
return x.cases({
|
2044
2064
|
"native": function(id) {
|
2045
|
-
|
2046
|
-
return scope.lookup(id, accessor.name, function(lookup) {
|
2065
|
+
return scope.lookup(id, query, function(lookup) {
|
2047
2066
|
dependencies.push(lookup);
|
2048
2067
|
return lookup.cases({
|
2049
|
-
response: function(
|
2050
|
-
semanticAccessors.set(
|
2051
|
-
return cb(TypeExpr.fromAST(
|
2068
|
+
response: function(analysis) {
|
2069
|
+
semanticAccessors.set(query, Semantic.query(analysis.annotations));
|
2070
|
+
return cb(TypeExpr.fromAST(analysis.type));
|
2052
2071
|
},
|
2053
2072
|
local: function(key) {
|
2054
2073
|
var localFrame;
|
2055
2074
|
nextCrumbs = crumbs.concat([key]);
|
2056
|
-
semanticAccessors.set(
|
2075
|
+
semanticAccessors.set(query, Semantic.localAccessor(key));
|
2057
2076
|
if (locks.get(key)) {
|
2058
2077
|
return cb(error('circular', nextCrumbs));
|
2059
2078
|
}
|
@@ -2092,19 +2111,17 @@ analyze = Gibbon.analyze = (function() {
|
|
2092
2111
|
flow: function(head, tail) {
|
2093
2112
|
return Semantic.flow(flowType(this), toSemanticTree(head), tail && toSemanticTree(tail));
|
2094
2113
|
},
|
2095
|
-
|
2096
|
-
|
2097
|
-
debugger;
|
2098
|
-
}
|
2114
|
+
query: function(type, name) {
|
2115
|
+
|
2099
2116
|
return semanticAccessors.get(this);
|
2100
2117
|
},
|
2101
2118
|
func: function(name, args) {
|
2102
2119
|
var a;
|
2103
2120
|
return Semantic.func(name, (function() {
|
2104
|
-
var
|
2121
|
+
var _i, _len, _results;
|
2105
2122
|
_results = [];
|
2106
|
-
for (
|
2107
|
-
a = args[
|
2123
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
2124
|
+
a = args[_i];
|
2108
2125
|
_results.push(toSemanticTree(a));
|
2109
2126
|
}
|
2110
2127
|
return _results;
|
@@ -2119,10 +2136,10 @@ analyze = Gibbon.analyze = (function() {
|
|
2119
2136
|
list: function(elements) {
|
2120
2137
|
var e;
|
2121
2138
|
return Semantic.list((function() {
|
2122
|
-
var
|
2139
|
+
var _i, _len, _results;
|
2123
2140
|
_results = [];
|
2124
|
-
for (
|
2125
|
-
e = elements[
|
2141
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
2142
|
+
e = elements[_i];
|
2126
2143
|
_results.push(toSemanticTree(e));
|
2127
2144
|
}
|
2128
2145
|
return _results;
|
@@ -2145,19 +2162,17 @@ analyze = Gibbon.analyze = (function() {
|
|
2145
2162
|
}
|
2146
2163
|
});
|
2147
2164
|
};
|
2148
|
-
|
2149
|
-
|
2150
|
-
});
|
2151
|
-
console.log('setting key: ' + key);
|
2165
|
+
|
2166
|
+
|
2152
2167
|
semantics.set(key, toSemanticTree(frame));
|
2153
2168
|
frameTypes.set(key, solutions.get(TypeExpr.expr(frame.flow)));
|
2154
|
-
|
2169
|
+
|
2155
2170
|
locks.set(key, false);
|
2156
2171
|
return solved();
|
2157
2172
|
};
|
2158
2173
|
return consume(constraints.reverse(), done, function(lhs, rhs, push, next) {
|
2159
2174
|
var log, matchError, skip, solveFor, swap;
|
2160
|
-
|
2175
|
+
|
2161
2176
|
if (lhs.equals(rhs)) {
|
2162
2177
|
return next();
|
2163
2178
|
}
|
@@ -2168,7 +2183,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2168
2183
|
push(solutions.get(lhs), rhs);
|
2169
2184
|
return next();
|
2170
2185
|
} else {
|
2171
|
-
|
2186
|
+
|
2172
2187
|
solutions.set(lhs, rhs);
|
2173
2188
|
mapper = function(k, texpr, cb) {
|
2174
2189
|
return fullSubstitute(texpr, (function(s) {
|
@@ -2181,7 +2196,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2181
2196
|
});
|
2182
2197
|
};
|
2183
2198
|
log = function() {
|
2184
|
-
|
2199
|
+
|
2185
2200
|
return next();
|
2186
2201
|
};
|
2187
2202
|
skip = function() {
|
@@ -2199,7 +2214,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2199
2214
|
expr: solveFor,
|
2200
2215
|
variable: solveFor,
|
2201
2216
|
any: skip,
|
2202
|
-
|
2217
|
+
query: function() {
|
2203
2218
|
return rhs.cases({
|
2204
2219
|
expr: swap,
|
2205
2220
|
variable: swap,
|
@@ -2224,23 +2239,23 @@ analyze = Gibbon.analyze = (function() {
|
|
2224
2239
|
param: function() {
|
2225
2240
|
return rhs.cases({
|
2226
2241
|
param: function() {
|
2227
|
-
var constraint, i,
|
2242
|
+
var constraint, i, _i, _len, _ref6;
|
2228
2243
|
if (lhs.name !== rhs.name) {
|
2229
2244
|
return matchError();
|
2230
2245
|
}
|
2231
|
-
|
2232
|
-
for (i =
|
2233
|
-
constraint =
|
2246
|
+
_ref6 = lhs.constraints;
|
2247
|
+
for (i = _i = 0, _len = _ref6.length; _i < _len; i = ++_i) {
|
2248
|
+
constraint = _ref6[i];
|
2234
2249
|
push(constraint, rhs.constraints[i]);
|
2235
2250
|
}
|
2236
2251
|
return next();
|
2237
2252
|
},
|
2238
|
-
|
2239
|
-
var c, i,
|
2240
|
-
|
2241
|
-
for (i =
|
2242
|
-
c =
|
2243
|
-
push(c, TypeExpr.destructure(rhs, lhs.
|
2253
|
+
query: function() {
|
2254
|
+
var c, i, _i, _len, _ref6;
|
2255
|
+
_ref6 = lhs.constraints;
|
2256
|
+
for (i = _i = 0, _len = _ref6.length; _i < _len; i = ++_i) {
|
2257
|
+
c = _ref6[i];
|
2258
|
+
push(c, TypeExpr.destructure(rhs, lhs.type(i)));
|
2244
2259
|
}
|
2245
2260
|
return next();
|
2246
2261
|
},
|
@@ -2263,7 +2278,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2263
2278
|
}
|
2264
2279
|
return _results;
|
2265
2280
|
})();
|
2266
|
-
|
2281
|
+
|
2267
2282
|
return contMap(initialCrumbs, solveEntry, function() {
|
2268
2283
|
if (errors.length === 0) {
|
2269
2284
|
errors = null;
|
@@ -2277,9 +2292,9 @@ analyze = Gibbon.analyze = (function() {
|
|
2277
2292
|
if (!(program instanceof AST)) {
|
2278
2293
|
program = AST.fromJSON(program);
|
2279
2294
|
}
|
2280
|
-
|
2281
|
-
|
2282
|
-
constraints = generate(globalID, external.
|
2295
|
+
|
2296
|
+
|
2297
|
+
constraints = generate(globalID, external.analyzeQuery, program);
|
2283
2298
|
return solve(constraints, cb);
|
2284
2299
|
};
|
2285
2300
|
})();
|
@@ -2447,6 +2462,45 @@ Value = Gibbon.Value = Value = (function(_super) {
|
|
2447
2462
|
});
|
2448
2463
|
};
|
2449
2464
|
|
2465
|
+
Value.prototype.mapPromise = function(f) {
|
2466
|
+
return this.cases({
|
2467
|
+
list: function(promises) {
|
2468
|
+
return Promise.combine(promises).then(function(els) {
|
2469
|
+
var el;
|
2470
|
+
return Promise.combine((function() {
|
2471
|
+
var _i, _len, _results;
|
2472
|
+
_results = [];
|
2473
|
+
for (_i = 0, _len = els.length; _i < _len; _i++) {
|
2474
|
+
el = els[_i];
|
2475
|
+
_results.push(f(el));
|
2476
|
+
}
|
2477
|
+
return _results;
|
2478
|
+
})()).map(function(els) {
|
2479
|
+
return Value.list(els);
|
2480
|
+
});
|
2481
|
+
});
|
2482
|
+
},
|
2483
|
+
pair: function(eFirst, eSecond) {
|
2484
|
+
return Promise.combine([eFirst, eSecond]).then(function(first, second) {
|
2485
|
+
return Promise.combine([f(first), f(second)]).map(function(_arg) {
|
2486
|
+
var mFirst, mSecond;
|
2487
|
+
mFirst = _arg[0], mSecond = _arg[1];
|
2488
|
+
return Value.pair(mFirst, mSecond);
|
2489
|
+
});
|
2490
|
+
});
|
2491
|
+
},
|
2492
|
+
other: function() {
|
2493
|
+
return Promise.unit(this);
|
2494
|
+
}
|
2495
|
+
});
|
2496
|
+
};
|
2497
|
+
|
2498
|
+
Value.prototype.resolve = function() {
|
2499
|
+
return this.mapPromise(function(x) {
|
2500
|
+
return x.resolve();
|
2501
|
+
});
|
2502
|
+
};
|
2503
|
+
|
2450
2504
|
return Value;
|
2451
2505
|
|
2452
2506
|
})(Union);
|
@@ -2604,7 +2658,7 @@ Dependency = (function(_super) {
|
|
2604
2658
|
}
|
2605
2659
|
|
2606
2660
|
Dependency.types({
|
2607
|
-
|
2661
|
+
query: ['entity', 'query'],
|
2608
2662
|
lexical: ['key']
|
2609
2663
|
});
|
2610
2664
|
|
@@ -2613,11 +2667,11 @@ Dependency = (function(_super) {
|
|
2613
2667
|
return false;
|
2614
2668
|
}
|
2615
2669
|
return this.cases({
|
2616
|
-
|
2670
|
+
query: function(entity, query) {
|
2617
2671
|
if (entity.id !== other.entity.id) {
|
2618
2672
|
return false;
|
2619
2673
|
}
|
2620
|
-
if (
|
2674
|
+
if (query.annotations !== other.query.annotations) {
|
2621
2675
|
return false;
|
2622
2676
|
}
|
2623
2677
|
return true;
|
@@ -2630,8 +2684,8 @@ Dependency = (function(_super) {
|
|
2630
2684
|
|
2631
2685
|
Dependency.prototype.inspect = function() {
|
2632
2686
|
return this.cases({
|
2633
|
-
lookup: function(entity,
|
2634
|
-
return "" + (
|
2687
|
+
lookup: function(entity, query) {
|
2688
|
+
return "" + (query.inspect()) + "<" + entity.id + ">";
|
2635
2689
|
},
|
2636
2690
|
lexical: function(definition) {
|
2637
2691
|
return "@" + definition.name;
|
@@ -2644,85 +2698,38 @@ Dependency = (function(_super) {
|
|
2644
2698
|
})(Union);
|
2645
2699
|
|
2646
2700
|
eval_ = Gibbon["eval"] = (function() {
|
2647
|
-
var
|
2648
|
-
Context = (function() {
|
2649
|
-
var CACHE;
|
2650
|
-
|
2651
|
-
CACHE = new Hash;
|
2652
|
-
|
2653
|
-
function Context(global, client) {
|
2654
|
-
this.global = global;
|
2655
|
-
this.client = client;
|
2656
|
-
this.globalPromise = Promise.unit(this.global);
|
2657
|
-
}
|
2658
|
-
|
2659
|
-
Context.prototype.lookup = function(entity, accessor) {
|
2660
|
-
var annotations, id,
|
2661
|
-
_this = this;
|
2662
|
-
annotations = accessor.annotations;
|
2663
|
-
id = entity.id;
|
2664
|
-
return CACHE.cache("" + id + "/" + (JSON.stringify(annotations)), function() {
|
2665
|
-
return new Promise(function(fail, cc) {
|
2666
|
-
return _this.client.getValue(id, annotations, function(err, val) {
|
2667
|
-
var dependency;
|
2668
|
-
if (err) {
|
2669
|
-
return fail(err);
|
2670
|
-
}
|
2671
|
-
dependency = Dependency.lookup(entity, accessor);
|
2672
|
-
return Value.fromJSON(val).promise().depends([dependency]);
|
2673
|
-
});
|
2674
|
-
});
|
2675
|
-
});
|
2676
|
-
};
|
2677
|
-
|
2678
|
-
return Context;
|
2679
|
-
|
2680
|
-
})();
|
2681
|
-
Scope = (function() {
|
2682
|
-
Scope.global = function(context) {
|
2683
|
-
return new Scope(null, [], context);
|
2684
|
-
};
|
2685
|
-
|
2686
|
-
function Scope(parent, definitions, context) {
|
2687
|
-
var def, _i, _len, _ref2;
|
2688
|
-
this.parent = parent;
|
2689
|
-
this.definitions = definitions;
|
2690
|
-
this.context = context;
|
2691
|
-
this.bindings = new Hash;
|
2692
|
-
_ref2 = this.definitions;
|
2693
|
-
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
2694
|
-
def = _ref2[_i];
|
2695
|
-
this.setupBinding(def);
|
2696
|
-
}
|
2697
|
-
}
|
2698
|
-
|
2699
|
-
Scope.prototype.setupBinding = function(def) {};
|
2700
|
-
|
2701
|
-
Scope.prototype.extend = function(definitions) {
|
2702
|
-
return new Scope(this, definitions, this.context);
|
2703
|
-
};
|
2704
|
-
|
2705
|
-
Scope.prototype.allResults = function() {};
|
2706
|
-
|
2707
|
-
return Scope;
|
2708
|
-
|
2709
|
-
})();
|
2701
|
+
var evalAll;
|
2710
2702
|
evalAll = function(semantics, entity, client) {
|
2711
2703
|
var evalFlow, globalPromise, resultThunks, results;
|
2704
|
+
results = new Hash;
|
2705
|
+
globalPromise = Promise.unit(entity);
|
2706
|
+
resultThunks = new Hash;
|
2707
|
+
semantics.each(function(key, definition) {
|
2708
|
+
return resultThunks.set(key, Promise.lazy(function() {
|
2709
|
+
return evalFlow(definition.flow, globalPromise).then(function(val) {
|
2710
|
+
return val.resolve();
|
2711
|
+
}).after(function(val, deps) {
|
2712
|
+
deps = uniq(deps, function(x, y) {
|
2713
|
+
return x.equals(y);
|
2714
|
+
});
|
2715
|
+
return results.set(key, [val, deps]);
|
2716
|
+
});
|
2717
|
+
}));
|
2718
|
+
});
|
2712
2719
|
evalFlow = function(flow, global) {
|
2713
2720
|
var input;
|
2714
2721
|
input = flow.tail ? evalFlow(flow.tail, global) : global;
|
2715
2722
|
return flow.head.cases({
|
2716
|
-
|
2723
|
+
query: function(annotations) {
|
2717
2724
|
return input.then(function(entity) {
|
2718
2725
|
var _this = this;
|
2719
2726
|
return new Promise(function(fail, cc) {
|
2720
|
-
return client.
|
2727
|
+
return client.performQuery(entity.id, annotations, function(err, val) {
|
2721
2728
|
var dependency;
|
2722
2729
|
if (err) {
|
2723
2730
|
return fail(err);
|
2724
2731
|
}
|
2725
|
-
dependency = Dependency.
|
2732
|
+
dependency = Dependency.query(entity, flow.head);
|
2726
2733
|
return Value.fromJSON(val).promise().depends([dependency]).force(fail, cc);
|
2727
2734
|
});
|
2728
2735
|
});
|
@@ -2788,19 +2795,6 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2788
2795
|
}
|
2789
2796
|
});
|
2790
2797
|
};
|
2791
|
-
resultThunks = new Hash;
|
2792
|
-
results = new Hash;
|
2793
|
-
globalPromise = Promise.unit(entity);
|
2794
|
-
semantics.each(function(key, definition) {
|
2795
|
-
return resultThunks.set(key, Promise.lazy(function() {
|
2796
|
-
return evalFlow(definition.flow, globalPromise).after(function(val, deps) {
|
2797
|
-
deps = uniq(deps, function(x, y) {
|
2798
|
-
return x.equals(y);
|
2799
|
-
});
|
2800
|
-
return results.set(key, [val, deps]);
|
2801
|
-
});
|
2802
|
-
}));
|
2803
|
-
});
|
2804
2798
|
return new Promise(function(fail, cc) {
|
2805
2799
|
return Promise.combine(resultThunks.values()).force(fail, function(_, deps) {
|
2806
2800
|
return cc(results, deps);
|
@@ -2832,41 +2826,54 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2832
2826
|
// Generated by CoffeeScript 1.6.3
|
2833
2827
|
Gibbon.jsonConsumer = (function() {
|
2834
2828
|
return function(tables) {
|
2835
|
-
|
2836
|
-
|
2837
|
-
|
2838
|
-
|
2839
|
-
|
2829
|
+
var getType, getValue;
|
2830
|
+
getType = function(id, accessorName, t, callback) {
|
2831
|
+
var fields;
|
2832
|
+
if (!tables.hasOwnProperty(id)) {
|
2833
|
+
return callback(new Error("no such type " + id));
|
2834
|
+
}
|
2835
|
+
fields = tables[id].fields;
|
2836
|
+
if (!fields.hasOwnProperty(accessorName)) {
|
2837
|
+
return callback(new Error("" + id + " has no field " + accessorName));
|
2838
|
+
}
|
2839
|
+
return callback(null, {
|
2840
|
+
type: t.parseUnit(fields[accessorName]),
|
2841
|
+
annotations: {
|
2842
|
+
name: accessorName,
|
2843
|
+
table: id
|
2840
2844
|
}
|
2841
|
-
|
2842
|
-
|
2843
|
-
|
2845
|
+
});
|
2846
|
+
};
|
2847
|
+
getValue = function(id, annotations, callback) {
|
2848
|
+
var entity, values;
|
2849
|
+
if (!tables.hasOwnProperty(annotations.table)) {
|
2850
|
+
return callback(new Error("no such type " + annotations.table));
|
2851
|
+
}
|
2852
|
+
values = tables[annotations.table].values;
|
2853
|
+
if (!values[id]) {
|
2854
|
+
return callback(new Error("no entity with id " + id));
|
2855
|
+
}
|
2856
|
+
entity = values[id];
|
2857
|
+
if (!entity.hasOwnProperty(annotations.name)) {
|
2858
|
+
return callback(null, null);
|
2859
|
+
}
|
2860
|
+
return callback(null, entity[annotations.name]);
|
2861
|
+
};
|
2862
|
+
return {
|
2863
|
+
analyzeQuery: function(id, query, t, callback) {
|
2864
|
+
switch (query.type) {
|
2865
|
+
case 'access':
|
2866
|
+
return getType(id, query.name, t, callback);
|
2867
|
+
default:
|
2868
|
+
return callback(new Error("unknown query `" + query.type + "'"));
|
2844
2869
|
}
|
2845
|
-
return callback(null, {
|
2846
|
-
type: fields[accessorName],
|
2847
|
-
annotations: {
|
2848
|
-
name: accessorName,
|
2849
|
-
table: id
|
2850
|
-
}
|
2851
|
-
});
|
2852
2870
|
},
|
2853
|
-
|
2854
|
-
|
2855
|
-
if (!tables.hasOwnProperty(annotations.table)) {
|
2856
|
-
return callback(new Error("no such type " + annotations.table));
|
2857
|
-
}
|
2858
|
-
values = tables[annotations.table].values;
|
2859
|
-
if (!values[id]) {
|
2860
|
-
return callback(new Error("no entity with id " + id));
|
2861
|
-
}
|
2862
|
-
entity = values[id];
|
2863
|
-
if (!entity.hasOwnProperty(annotations.name)) {
|
2864
|
-
return callback(null, null);
|
2865
|
-
}
|
2866
|
-
return callback(null, entity[annotations.name]);
|
2871
|
+
performQuery: function(id, annotations, callback) {
|
2872
|
+
return getValue(id, annotations, callback);
|
2867
2873
|
}
|
2868
2874
|
};
|
2869
2875
|
};
|
2870
2876
|
})();
|
2871
2877
|
return Gibbon;
|
2872
2878
|
})();
|
2879
|
+
|