goodguide-gibbon 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/goodguide/gibbon/version.rb +1 -1
- data/vendor/gibbon/lib/gibbon.browser.js +77 -65
- metadata +2 -2
@@ -858,8 +858,7 @@ Gibbon.AST = AST = (function(_super) {
|
|
858
858
|
flow: ['head', 'tail'],
|
859
859
|
metadata: ['key', 'text'],
|
860
860
|
definition: ['metadata', 'name', 'frame'],
|
861
|
-
frame: ['definitions', 'flow']
|
862
|
-
program: ['definitions']
|
861
|
+
frame: ['definitions', 'flow']
|
863
862
|
});
|
864
863
|
|
865
864
|
inspectDefinitions = function(defs) {
|
@@ -956,9 +955,6 @@ Gibbon.AST = AST = (function(_super) {
|
|
956
955
|
out.push(flow.inspect());
|
957
956
|
out.push(")");
|
958
957
|
return out.join('');
|
959
|
-
},
|
960
|
-
program: function(definitions) {
|
961
|
-
return inspectDefinitions(definitions);
|
962
958
|
}
|
963
959
|
});
|
964
960
|
};
|
@@ -992,7 +988,7 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
|
|
992
988
|
})(Union);
|
993
989
|
|
994
990
|
parse = Gibbon.parse = (function() {
|
995
|
-
var accessor, accessorExpr, 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, integer, integerExpr, isString, label, labelVal, lbrace, lbrack, lexeme, listExpr, listType, lparen, metadata, name, nativeId, nativeType, nonPairedFlow, numericExpr, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, rbrace, rbrack, regex, rparen, signature, simpleType, singletonFlow, str, string, stringExpr, substExpr, succeed, tassign, type, typeVar, variable, whitespace, wildType, wildcard;
|
991
|
+
var accessor, accessorExpr, 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, rbrace, rbrack, regex, rparen, signature, simpleType, singletonFlow, str, string, stringExpr, substExpr, succeed, tassign, type, typeVar, variable, whitespace, wildType, wildcard;
|
996
992
|
string = Parsimmon.string, regex = Parsimmon.regex, succeed = Parsimmon.succeed, fail = Parsimmon.fail;
|
997
993
|
Parsimmon.Parser.prototype.expected = function(message) {
|
998
994
|
var _this = this;
|
@@ -1114,23 +1110,22 @@ parse = Gibbon.parse = (function() {
|
|
1114
1110
|
});
|
1115
1111
|
definition = metadata.many().then(function(md) {
|
1116
1112
|
return name.then(function(n) {
|
1117
|
-
return define.
|
1113
|
+
return define.then(innerFrame.expected()).map(function(fl) {
|
1118
1114
|
return AST.definition(md, n, fl);
|
1119
1115
|
});
|
1120
1116
|
});
|
1121
1117
|
});
|
1122
|
-
|
1123
|
-
return flow.expected().
|
1118
|
+
frame = definition.many().then(function(defs) {
|
1119
|
+
return flow.expected().map(function(fl) {
|
1124
1120
|
return AST.frame(defs, fl);
|
1125
1121
|
});
|
1126
1122
|
});
|
1123
|
+
parenFrame = lparen.then(frame).skip(rparen.expected());
|
1127
1124
|
freeFrame = flow.map(function(fl) {
|
1128
1125
|
return AST.frame([], fl);
|
1129
1126
|
});
|
1130
|
-
|
1131
|
-
program = ignore.then(
|
1132
|
-
return AST.program(defs);
|
1133
|
-
}));
|
1127
|
+
innerFrame = parenFrame.or(freeFrame);
|
1128
|
+
program = ignore.then(frame);
|
1134
1129
|
tassign = lexeme(string('='));
|
1135
1130
|
bang = lexeme(string('!'));
|
1136
1131
|
nativeId = lexeme(regex(/^\w+/));
|
@@ -1763,20 +1758,22 @@ analyze = Gibbon.analyze = (function() {
|
|
1763
1758
|
|
1764
1759
|
})();
|
1765
1760
|
Scope = (function() {
|
1766
|
-
|
1767
|
-
|
1761
|
+
var makeKey;
|
1762
|
+
|
1763
|
+
Scope.global = function(context, frame) {
|
1764
|
+
return new Scope(null, [], frame, context);
|
1768
1765
|
};
|
1769
1766
|
|
1770
|
-
function Scope(parent, breadcrumbs,
|
1767
|
+
function Scope(parent, breadcrumbs, frame, context) {
|
1771
1768
|
this.parent = parent;
|
1772
1769
|
this.breadcrumbs = breadcrumbs;
|
1773
|
-
this.
|
1770
|
+
this.frame = frame;
|
1774
1771
|
this.context = context;
|
1775
1772
|
this.bindings = new Hash;
|
1776
1773
|
}
|
1777
1774
|
|
1778
|
-
Scope.prototype.extend = function(name,
|
1779
|
-
return new Scope(this, this.breadcrumbs.concat([name]),
|
1775
|
+
Scope.prototype.extend = function(name, frame) {
|
1776
|
+
return new Scope(this, this.breadcrumbs.concat([name]), frame, this.context);
|
1780
1777
|
};
|
1781
1778
|
|
1782
1779
|
Scope.prototype.lookup = function(nativeId, name, cb) {
|
@@ -1811,31 +1808,33 @@ analyze = Gibbon.analyze = (function() {
|
|
1811
1808
|
return TypeLookup.local(this.keyFor(name));
|
1812
1809
|
};
|
1813
1810
|
|
1811
|
+
makeKey = function(crumbs) {
|
1812
|
+
return '/' + crumbs.join('/');
|
1813
|
+
};
|
1814
|
+
|
1815
|
+
Scope.prototype.key = function() {
|
1816
|
+
return makeKey(this.breadcrumbs);
|
1817
|
+
};
|
1818
|
+
|
1814
1819
|
Scope.prototype.keyFor = function(name) {
|
1815
|
-
return this.breadcrumbs.concat([name])
|
1820
|
+
return makeKey(this.breadcrumbs.concat([name]));
|
1816
1821
|
};
|
1817
1822
|
|
1818
|
-
Scope.prototype.
|
1819
|
-
var def, frameScope, global, _i, _len, _ref4
|
1820
|
-
|
1821
|
-
global = TypeExpr["native"](this.context.globalID);
|
1822
|
-
_ref4 = this.definitions;
|
1823
|
-
_results = [];
|
1823
|
+
Scope.prototype.analyze = function(push) {
|
1824
|
+
var def, frame, frameScope, global, key, _i, _len, _ref4;
|
1825
|
+
_ref4 = this.frame.definitions;
|
1824
1826
|
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
1825
1827
|
def = _ref4[_i];
|
1826
|
-
this.
|
1827
|
-
frameScope
|
1828
|
-
|
1829
|
-
_results.push((function(def) {
|
1830
|
-
var key, pusher;
|
1831
|
-
key = _this.keyFor(def.name);
|
1832
|
-
pusher = function(lhs, rhs) {
|
1833
|
-
return push(key, def, [lhs, rhs]);
|
1834
|
-
};
|
1835
|
-
return frameScope.analyzeFlow(def.frame.flow, global, pusher);
|
1836
|
-
})(def));
|
1828
|
+
frameScope = this.extend(def.name, def.frame);
|
1829
|
+
frameScope.analyze(push);
|
1830
|
+
this.bindings.set(def.name, frameScope);
|
1837
1831
|
}
|
1838
|
-
|
1832
|
+
key = this.key();
|
1833
|
+
global = TypeExpr["native"](this.context.globalID);
|
1834
|
+
frame = this.frame;
|
1835
|
+
return this.analyzeFlow(this.frame.flow, global, function(lhs, rhs) {
|
1836
|
+
return push(key, frame, [lhs, rhs]);
|
1837
|
+
});
|
1839
1838
|
};
|
1840
1839
|
|
1841
1840
|
Scope.prototype.analyzeFlow = function(flow, global, push) {
|
@@ -1919,13 +1918,13 @@ analyze = Gibbon.analyze = (function() {
|
|
1919
1918
|
return function(globalID, externalLookup, program) {
|
1920
1919
|
var constraintMap, context, scope;
|
1921
1920
|
context = new NativeContext(globalID, externalLookup);
|
1922
|
-
scope = Scope.global(context, program
|
1921
|
+
scope = Scope.global(context, program);
|
1923
1922
|
constraintMap = new Hash;
|
1924
|
-
scope.
|
1923
|
+
scope.analyze(function(key, frame, constraint) {
|
1925
1924
|
var entry;
|
1926
1925
|
entry = constraintMap.cache(key, function() {
|
1927
1926
|
return {
|
1928
|
-
|
1927
|
+
frame: frame,
|
1929
1928
|
constraints: []
|
1930
1929
|
};
|
1931
1930
|
});
|
@@ -1949,7 +1948,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1949
1948
|
infinite: ['type'],
|
1950
1949
|
destructure: ['type'],
|
1951
1950
|
access: ['type'],
|
1952
|
-
circular: ['
|
1951
|
+
circular: ['crumbs']
|
1953
1952
|
});
|
1954
1953
|
|
1955
1954
|
return TypeError;
|
@@ -1974,21 +1973,24 @@ analyze = Gibbon.analyze = (function() {
|
|
1974
1973
|
return loop_();
|
1975
1974
|
};
|
1976
1975
|
return function(constraintMap, finish) {
|
1977
|
-
var
|
1976
|
+
var errors, frameTypes, initialCrumbs, k, locks, semantics, solutions, solveEntry;
|
1978
1977
|
errors = [];
|
1979
1978
|
solutions = new CompMap(function(x, y) {
|
1980
1979
|
return x.equals(y);
|
1981
1980
|
});
|
1982
1981
|
semantics = new Hash;
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1982
|
+
frameTypes = new Hash;
|
1983
|
+
locks = new Hash;
|
1984
|
+
solveEntry = function(crumbs, solved) {
|
1985
|
+
var constraints, dependencies, done, error, frame, fullSubstitute, key, lhs, nextCrumbs, rhs, semanticAccessors, simplify, substitute, _i, _len, _ref5, _ref6;
|
1986
|
+
key = crumbs[crumbs.length - 1];
|
1986
1987
|
if (semantics.has(key)) {
|
1987
1988
|
return solved();
|
1988
1989
|
}
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1990
|
+
nextCrumbs = crumbs.concat([key]);
|
1991
|
+
_ref5 = constraintMap.get(key), frame = _ref5.frame, constraints = _ref5.constraints;
|
1992
|
+
console.log('locking', key);
|
1993
|
+
locks.set(key, true);
|
1992
1994
|
semanticAccessors = new CompMap;
|
1993
1995
|
dependencies = [];
|
1994
1996
|
for (_i = 0, _len = constraints.length; _i < _len; _i++) {
|
@@ -2049,16 +2051,16 @@ analyze = Gibbon.analyze = (function() {
|
|
2049
2051
|
return cb(TypeExpr.fromAST(Gibbon.parse.unitType(response.type)));
|
2050
2052
|
},
|
2051
2053
|
local: function(key) {
|
2052
|
-
var
|
2054
|
+
var localFrame;
|
2055
|
+
nextCrumbs = crumbs.concat([key]);
|
2053
2056
|
semanticAccessors.set(accessor, Semantic.localAccessor(key));
|
2054
|
-
|
2055
|
-
|
2056
|
-
return cb(error('circular', localDef));
|
2057
|
-
} else {
|
2058
|
-
return solveEntry(key, function() {
|
2059
|
-
return cb(definitionTypes.get(key));
|
2060
|
-
});
|
2057
|
+
if (locks.get(key)) {
|
2058
|
+
return cb(error('circular', nextCrumbs));
|
2061
2059
|
}
|
2060
|
+
localFrame = constraintMap.get(key).frame;
|
2061
|
+
return solveEntry(nextCrumbs, function() {
|
2062
|
+
return cb(frameTypes.get(key));
|
2063
|
+
});
|
2062
2064
|
}
|
2063
2065
|
});
|
2064
2066
|
});
|
@@ -2078,15 +2080,14 @@ analyze = Gibbon.analyze = (function() {
|
|
2078
2080
|
var flowType, toSemanticTree;
|
2079
2081
|
flowType = function(expr) {
|
2080
2082
|
if (!solutions.has(TypeExpr.expr(expr))) {
|
2081
|
-
solutions.get(TypeExpr.expr(expr));
|
2082
2083
|
throw 'unsolved!';
|
2083
2084
|
}
|
2084
2085
|
return solutions.get(TypeExpr.expr(expr)).realize();
|
2085
2086
|
};
|
2086
2087
|
toSemanticTree = function(expr) {
|
2087
2088
|
return expr.cases({
|
2088
|
-
|
2089
|
-
return Semantic.definition(dependencies, toSemanticTree(
|
2089
|
+
frame: function(_, flow) {
|
2090
|
+
return Semantic.definition(dependencies, toSemanticTree(flow));
|
2090
2091
|
},
|
2091
2092
|
flow: function(head, tail) {
|
2092
2093
|
return Semantic.flow(flowType(this), toSemanticTree(head), tail && toSemanticTree(tail));
|
@@ -2148,10 +2149,10 @@ analyze = Gibbon.analyze = (function() {
|
|
2148
2149
|
return logConstraint('=> ', k, v);
|
2149
2150
|
});
|
2150
2151
|
console.log('setting key: ' + key);
|
2151
|
-
semantics.set(key, toSemanticTree(
|
2152
|
-
|
2153
|
-
console.log('unlocking',
|
2154
|
-
|
2152
|
+
semantics.set(key, toSemanticTree(frame));
|
2153
|
+
frameTypes.set(key, solutions.get(TypeExpr.expr(frame.flow)));
|
2154
|
+
console.log('unlocking', key);
|
2155
|
+
locks.set(key, false);
|
2155
2156
|
return solved();
|
2156
2157
|
};
|
2157
2158
|
return consume(constraints.reverse(), done, function(lhs, rhs, push, next) {
|
@@ -2252,7 +2253,18 @@ analyze = Gibbon.analyze = (function() {
|
|
2252
2253
|
});
|
2253
2254
|
});
|
2254
2255
|
};
|
2255
|
-
|
2256
|
+
initialCrumbs = (function() {
|
2257
|
+
var _i, _len, _ref5, _results;
|
2258
|
+
_ref5 = constraintMap.keys();
|
2259
|
+
_results = [];
|
2260
|
+
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
2261
|
+
k = _ref5[_i];
|
2262
|
+
_results.push([k]);
|
2263
|
+
}
|
2264
|
+
return _results;
|
2265
|
+
})();
|
2266
|
+
console.log('initial crumbs', initialCrumbs);
|
2267
|
+
return contMap(initialCrumbs, solveEntry, function() {
|
2256
2268
|
if (errors.length === 0) {
|
2257
2269
|
errors = null;
|
2258
2270
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodguide-gibbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
type: :runtime
|