goodguide-gibbon 0.3.7 → 0.3.8
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/lib/goodguide/gibbon.rb +9 -3
- data/vendor/gibbon/lib/gibbon.browser.dev.js +223 -220
- data/vendor/gibbon/lib/gibbon.browser.js +223 -220
- metadata +4 -4
data/lib/goodguide/gibbon.rb
CHANGED
@@ -71,14 +71,20 @@ module GoodGuide
|
|
71
71
|
end
|
72
72
|
|
73
73
|
private
|
74
|
+
def inspect_expr(expr)
|
75
|
+
obj = JS.default.gibbon[:TypeExpr].fromJSON(expr)
|
76
|
+
inspect = obj[:inspect]
|
77
|
+
inspect.methodcall(obj)
|
78
|
+
end
|
79
|
+
|
74
80
|
def semantic_error_message(e)
|
75
81
|
case e['_tag']
|
76
82
|
when 'match'
|
77
|
-
lhs = e['lhs']
|
78
|
-
rhs = e['rhs']
|
83
|
+
lhs = inspect_expr e['lhs']
|
84
|
+
rhs = inspect_expr e['rhs']
|
79
85
|
"could not match #{lhs} with #{rhs}"
|
80
86
|
when 'destructure'
|
81
|
-
type = e['type']
|
87
|
+
type = inspect_expr e['type']
|
82
88
|
"could not destructure #{type}"
|
83
89
|
when 'lookup'
|
84
90
|
query_name = e['query']['name']
|
@@ -1219,7 +1219,7 @@ parse = Gibbon.parse = (function() {
|
|
1219
1219
|
return parse;
|
1220
1220
|
})();
|
1221
1221
|
// Generated by CoffeeScript 1.6.3
|
1222
|
-
var Semantic, Type, TypeLookup, analyze, _ref, _ref1, _ref2,
|
1222
|
+
var Semantic, Type, TypeExpr, TypeLookup, analyze, _ref, _ref1, _ref2, _ref3,
|
1223
1223
|
__hasProp = {}.hasOwnProperty,
|
1224
1224
|
__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; },
|
1225
1225
|
__slice = [].slice;
|
@@ -1311,243 +1311,244 @@ Gibbon.Type = Type = (function(_super) {
|
|
1311
1311
|
|
1312
1312
|
})(Union);
|
1313
1313
|
|
1314
|
-
|
1315
|
-
|
1316
|
-
TypeExpr = (function(_super) {
|
1317
|
-
__extends(TypeExpr, _super);
|
1314
|
+
Gibbon.TypeExpr = TypeExpr = (function(_super) {
|
1315
|
+
__extends(TypeExpr, _super);
|
1318
1316
|
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1317
|
+
function TypeExpr() {
|
1318
|
+
_ref3 = TypeExpr.__super__.constructor.apply(this, arguments);
|
1319
|
+
return _ref3;
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
TypeExpr.types({
|
1323
|
+
expr: ['expr'],
|
1324
|
+
variable: ['name'],
|
1325
|
+
query: ['input', 'scope', 'query'],
|
1326
|
+
destructure: ['constraint', 'name', 'argnum'],
|
1327
|
+
"native": ['id'],
|
1328
|
+
param: ['name', 'constraints'],
|
1329
|
+
error: ['type', 'args'],
|
1330
|
+
any: []
|
1331
|
+
});
|
1323
1332
|
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
+
TypeExpr.prototype.realize = function() {
|
1334
|
+
return this.cases({
|
1335
|
+
"native": function(id) {
|
1336
|
+
return Type.entity(id);
|
1337
|
+
},
|
1338
|
+
param: function(name, args) {
|
1339
|
+
var arg;
|
1340
|
+
return Type[name].apply(Type, (function() {
|
1341
|
+
var _i, _len, _results;
|
1342
|
+
_results = [];
|
1343
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
1344
|
+
arg = args[_i];
|
1345
|
+
_results.push(arg.realize());
|
1346
|
+
}
|
1347
|
+
return _results;
|
1348
|
+
})());
|
1349
|
+
},
|
1350
|
+
other: function() {
|
1351
|
+
return Type.abstract(this);
|
1352
|
+
}
|
1333
1353
|
});
|
1354
|
+
};
|
1334
1355
|
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1356
|
+
TypeExpr.prototype.inspect = function() {
|
1357
|
+
return this.cases({
|
1358
|
+
expr: function(e) {
|
1359
|
+
return "<" + (e.inspect()) + ">";
|
1360
|
+
},
|
1361
|
+
variable: function(name) {
|
1362
|
+
return "%" + name;
|
1363
|
+
},
|
1364
|
+
query: function(input, _, query) {
|
1365
|
+
return "@" + query.type + "(" + query.name + ")[" + (input.inspect()) + "]";
|
1366
|
+
},
|
1367
|
+
destructure: function(constraint, name, argnum) {
|
1368
|
+
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
1369
|
+
},
|
1370
|
+
"native": function(id) {
|
1371
|
+
return "!" + id;
|
1372
|
+
},
|
1373
|
+
param: function(name, exprs) {
|
1374
|
+
var expr;
|
1375
|
+
if (!exprs.length) {
|
1376
|
+
return "(" + name + ")";
|
1354
1377
|
}
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
return "<" + (e.inspect()) + ">";
|
1362
|
-
},
|
1363
|
-
variable: function(name) {
|
1364
|
-
return "%" + name;
|
1365
|
-
},
|
1366
|
-
query: function(input, _, query) {
|
1367
|
-
return "@" + query.type + "(" + query.name + ")[" + (input.inspect()) + "]";
|
1368
|
-
},
|
1369
|
-
destructure: function(constraint, name, argnum) {
|
1370
|
-
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
1371
|
-
},
|
1372
|
-
"native": function(id) {
|
1373
|
-
return "!" + id;
|
1374
|
-
},
|
1375
|
-
param: function(name, exprs) {
|
1376
|
-
var expr;
|
1377
|
-
if (!exprs.length) {
|
1378
|
-
return "(" + name + ")";
|
1378
|
+
exprs = (function() {
|
1379
|
+
var _i, _len, _results;
|
1380
|
+
_results = [];
|
1381
|
+
for (_i = 0, _len = exprs.length; _i < _len; _i++) {
|
1382
|
+
expr = exprs[_i];
|
1383
|
+
_results.push(expr.inspect());
|
1379
1384
|
}
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
}
|
1387
|
-
return _results;
|
1388
|
-
})();
|
1389
|
-
return "(" + name + " " + (exprs.join(' ')) + ")";
|
1390
|
-
},
|
1391
|
-
any: function() {
|
1392
|
-
return '*';
|
1393
|
-
}
|
1394
|
-
});
|
1395
|
-
};
|
1396
|
-
|
1397
|
-
TypeExpr.prototype.equals = function(other) {
|
1398
|
-
var _this = this;
|
1399
|
-
if (this._tag !== other._tag) {
|
1400
|
-
return false;
|
1385
|
+
return _results;
|
1386
|
+
})();
|
1387
|
+
return "(" + name + " " + (exprs.join(' ')) + ")";
|
1388
|
+
},
|
1389
|
+
any: function() {
|
1390
|
+
return '*';
|
1401
1391
|
}
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
return
|
1417
|
-
}
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
return
|
1430
|
-
}
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
}
|
1435
|
-
if (argnum !== other.argnum) {
|
1392
|
+
});
|
1393
|
+
};
|
1394
|
+
|
1395
|
+
TypeExpr.prototype.equals = function(other) {
|
1396
|
+
var _this = this;
|
1397
|
+
if (this._tag !== other._tag) {
|
1398
|
+
return false;
|
1399
|
+
}
|
1400
|
+
return this.cases({
|
1401
|
+
expr: function(e) {
|
1402
|
+
return e === other.expr;
|
1403
|
+
},
|
1404
|
+
query: function(input, scope, query) {
|
1405
|
+
if (scope !== other.scope) {
|
1406
|
+
return false;
|
1407
|
+
}
|
1408
|
+
if (query !== other.query) {
|
1409
|
+
return false;
|
1410
|
+
}
|
1411
|
+
return input.equals(other.input);
|
1412
|
+
},
|
1413
|
+
"native": function(id) {
|
1414
|
+
return id === other.id;
|
1415
|
+
},
|
1416
|
+
param: function(name, constraints) {
|
1417
|
+
var constraint, i, _i, _len;
|
1418
|
+
if (name !== other.name) {
|
1419
|
+
return false;
|
1420
|
+
}
|
1421
|
+
for (i = _i = 0, _len = constraints.length; _i < _len; i = ++_i) {
|
1422
|
+
constraint = constraints[i];
|
1423
|
+
if (!constraint.equals(other.constraints[i])) {
|
1436
1424
|
return false;
|
1437
1425
|
}
|
1438
|
-
return constraint.equals(other.constraint);
|
1439
|
-
},
|
1440
|
-
other: function() {
|
1441
|
-
return _this === other;
|
1442
1426
|
}
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
r = function(ast) {
|
1449
|
-
return TypeExpr.fromAST(ast, scope);
|
1450
|
-
};
|
1451
|
-
e = TypeExpr;
|
1452
|
-
return typeAST.cases({
|
1453
|
-
concrete: function(name) {
|
1454
|
-
if (typeof Type[name] !== 'function') {
|
1455
|
-
throw new Error("unknown type " + name);
|
1456
|
-
}
|
1457
|
-
return e.param(name, []);
|
1458
|
-
},
|
1459
|
-
variable: function(name) {
|
1460
|
-
return scope.cache(name, function() {
|
1461
|
-
return e.variable(name);
|
1462
|
-
});
|
1463
|
-
},
|
1464
|
-
"native": function(id) {
|
1465
|
-
return e["native"](id);
|
1466
|
-
},
|
1467
|
-
wildcard: function() {
|
1468
|
-
return e.any();
|
1469
|
-
},
|
1470
|
-
list: function(el) {
|
1471
|
-
return e.param('list', [r(el)]);
|
1472
|
-
},
|
1473
|
-
block: function(el) {
|
1474
|
-
return e.param('block', [r(el.from), r(el.to)]);
|
1475
|
-
},
|
1476
|
-
pair: function(first, second) {
|
1477
|
-
return e.param('pair', [r(first), r(second)]);
|
1427
|
+
return true;
|
1428
|
+
},
|
1429
|
+
destructure: function(constraint, name, argnum) {
|
1430
|
+
if (name !== other.type) {
|
1431
|
+
return false;
|
1478
1432
|
}
|
1479
|
-
|
1433
|
+
if (argnum !== other.argnum) {
|
1434
|
+
return false;
|
1435
|
+
}
|
1436
|
+
return constraint.equals(other.constraint);
|
1437
|
+
},
|
1438
|
+
other: function() {
|
1439
|
+
return _this === other;
|
1440
|
+
}
|
1441
|
+
});
|
1442
|
+
};
|
1443
|
+
|
1444
|
+
TypeExpr.fromAST = function(typeAST, scope) {
|
1445
|
+
var e, r;
|
1446
|
+
r = function(ast) {
|
1447
|
+
return TypeExpr.fromAST(ast, scope);
|
1480
1448
|
};
|
1449
|
+
e = TypeExpr;
|
1450
|
+
return typeAST.cases({
|
1451
|
+
concrete: function(name) {
|
1452
|
+
if (typeof Type[name] !== 'function') {
|
1453
|
+
throw new Error("unknown type " + name);
|
1454
|
+
}
|
1455
|
+
return e.param(name, []);
|
1456
|
+
},
|
1457
|
+
variable: function(name) {
|
1458
|
+
return scope.cache(name, function() {
|
1459
|
+
return e.variable(name);
|
1460
|
+
});
|
1461
|
+
},
|
1462
|
+
"native": function(id) {
|
1463
|
+
return e["native"](id);
|
1464
|
+
},
|
1465
|
+
wildcard: function() {
|
1466
|
+
return e.any();
|
1467
|
+
},
|
1468
|
+
list: function(el) {
|
1469
|
+
return e.param('list', [r(el)]);
|
1470
|
+
},
|
1471
|
+
block: function(el) {
|
1472
|
+
return e.param('block', [r(el.from), r(el.to)]);
|
1473
|
+
},
|
1474
|
+
pair: function(first, second) {
|
1475
|
+
return e.param('pair', [r(first), r(second)]);
|
1476
|
+
}
|
1477
|
+
});
|
1478
|
+
};
|
1481
1479
|
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1480
|
+
TypeExpr.fromType = function(t) {
|
1481
|
+
var st;
|
1482
|
+
if (t._tag === 'entity') {
|
1483
|
+
return TypeExpr["native"](t.id);
|
1484
|
+
}
|
1485
|
+
return TypeExpr.param(t._tag, (function() {
|
1486
|
+
var _i, _len, _ref4, _results;
|
1487
|
+
_ref4 = t._values;
|
1488
|
+
_results = [];
|
1489
|
+
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
1490
|
+
st = _ref4[_i];
|
1491
|
+
_results.push(this.fromType(st));
|
1486
1492
|
}
|
1487
|
-
return
|
1488
|
-
|
1489
|
-
|
1490
|
-
_results = [];
|
1491
|
-
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
1492
|
-
st = _ref4[_i];
|
1493
|
-
_results.push(this.fromType(st));
|
1494
|
-
}
|
1495
|
-
return _results;
|
1496
|
-
}).call(this));
|
1497
|
-
};
|
1493
|
+
return _results;
|
1494
|
+
}).call(this));
|
1495
|
+
};
|
1498
1496
|
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1497
|
+
TypeExpr.prototype.map = function(f) {
|
1498
|
+
return this.cases({
|
1499
|
+
param: function(name, params) {
|
1500
|
+
var p;
|
1501
|
+
return TypeExpr.param(name, (function() {
|
1502
|
+
var _i, _len, _results;
|
1503
|
+
_results = [];
|
1504
|
+
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
1505
|
+
p = params[_i];
|
1506
|
+
_results.push(f(p));
|
1507
|
+
}
|
1508
|
+
return _results;
|
1509
|
+
})());
|
1510
|
+
},
|
1511
|
+
query: function(input, scope, query) {
|
1512
|
+
return TypeExpr.query(f(input), scope, query);
|
1513
|
+
},
|
1514
|
+
destructure: function(constraint, name, argnum) {
|
1515
|
+
return TypeExpr.destructure(f(constraint), name, argnum);
|
1516
|
+
},
|
1517
|
+
other: function() {
|
1518
|
+
return this;
|
1519
|
+
}
|
1520
|
+
});
|
1521
|
+
};
|
1524
1522
|
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1523
|
+
TypeExpr.prototype.mapAsync = function(f, cb) {
|
1524
|
+
return this.cases({
|
1525
|
+
param: function(name, params) {
|
1526
|
+
return asyncMap(params, f, function(ps) {
|
1527
|
+
return cb(TypeExpr.param(name, ps));
|
1528
|
+
});
|
1529
|
+
},
|
1530
|
+
query: function(input, scope, query) {
|
1531
|
+
return f(input, function(i) {
|
1532
|
+
return cb(TypeExpr.query(i, scope, query));
|
1533
|
+
});
|
1534
|
+
},
|
1535
|
+
destructure: function(param, name, argnum) {
|
1536
|
+
return f(param, function(p) {
|
1537
|
+
return cb(TypeExpr.destructure(p, name, argnum));
|
1538
|
+
});
|
1539
|
+
},
|
1540
|
+
other: function() {
|
1541
|
+
return cb(this);
|
1542
|
+
}
|
1543
|
+
});
|
1544
|
+
};
|
1547
1545
|
|
1548
|
-
|
1546
|
+
return TypeExpr;
|
1549
1547
|
|
1550
|
-
|
1548
|
+
})(Union);
|
1549
|
+
|
1550
|
+
analyze = Gibbon.analyze = (function() {
|
1551
|
+
var generate, solve;
|
1551
1552
|
generate = (function() {
|
1552
1553
|
var NativeContext, Scope;
|
1553
1554
|
NativeContext = (function() {
|
@@ -2027,6 +2028,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2027
2028
|
return next();
|
2028
2029
|
};
|
2029
2030
|
matchError = function() {
|
2031
|
+
DEBUG.logConstraint('!> ', lhs, rhs);
|
2030
2032
|
error('match', lhs, rhs);
|
2031
2033
|
return next();
|
2032
2034
|
};
|
@@ -2046,6 +2048,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2046
2048
|
return rhs.cases({
|
2047
2049
|
variable: swap,
|
2048
2050
|
expr: swap,
|
2051
|
+
any: swap,
|
2049
2052
|
"native": function(otherId) {
|
2050
2053
|
if (id === otherId) {
|
2051
2054
|
return skip();
|
@@ -1213,7 +1213,7 @@ parse = Gibbon.parse = (function() {
|
|
1213
1213
|
return parse;
|
1214
1214
|
})();
|
1215
1215
|
// Generated by CoffeeScript 1.6.3
|
1216
|
-
var Semantic, Type, TypeLookup, analyze, _ref, _ref1, _ref2,
|
1216
|
+
var Semantic, Type, TypeExpr, TypeLookup, analyze, _ref, _ref1, _ref2, _ref3,
|
1217
1217
|
__hasProp = {}.hasOwnProperty,
|
1218
1218
|
__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; },
|
1219
1219
|
__slice = [].slice;
|
@@ -1305,243 +1305,244 @@ Gibbon.Type = Type = (function(_super) {
|
|
1305
1305
|
|
1306
1306
|
})(Union);
|
1307
1307
|
|
1308
|
-
|
1309
|
-
|
1310
|
-
TypeExpr = (function(_super) {
|
1311
|
-
__extends(TypeExpr, _super);
|
1308
|
+
Gibbon.TypeExpr = TypeExpr = (function(_super) {
|
1309
|
+
__extends(TypeExpr, _super);
|
1312
1310
|
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1311
|
+
function TypeExpr() {
|
1312
|
+
_ref3 = TypeExpr.__super__.constructor.apply(this, arguments);
|
1313
|
+
return _ref3;
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
TypeExpr.types({
|
1317
|
+
expr: ['expr'],
|
1318
|
+
variable: ['name'],
|
1319
|
+
query: ['input', 'scope', 'query'],
|
1320
|
+
destructure: ['constraint', 'name', 'argnum'],
|
1321
|
+
"native": ['id'],
|
1322
|
+
param: ['name', 'constraints'],
|
1323
|
+
error: ['type', 'args'],
|
1324
|
+
any: []
|
1325
|
+
});
|
1317
1326
|
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
+
TypeExpr.prototype.realize = function() {
|
1328
|
+
return this.cases({
|
1329
|
+
"native": function(id) {
|
1330
|
+
return Type.entity(id);
|
1331
|
+
},
|
1332
|
+
param: function(name, args) {
|
1333
|
+
var arg;
|
1334
|
+
return Type[name].apply(Type, (function() {
|
1335
|
+
var _i, _len, _results;
|
1336
|
+
_results = [];
|
1337
|
+
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
1338
|
+
arg = args[_i];
|
1339
|
+
_results.push(arg.realize());
|
1340
|
+
}
|
1341
|
+
return _results;
|
1342
|
+
})());
|
1343
|
+
},
|
1344
|
+
other: function() {
|
1345
|
+
return Type.abstract(this);
|
1346
|
+
}
|
1327
1347
|
});
|
1348
|
+
};
|
1328
1349
|
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1350
|
+
TypeExpr.prototype.inspect = function() {
|
1351
|
+
return this.cases({
|
1352
|
+
expr: function(e) {
|
1353
|
+
return "<" + (e.inspect()) + ">";
|
1354
|
+
},
|
1355
|
+
variable: function(name) {
|
1356
|
+
return "%" + name;
|
1357
|
+
},
|
1358
|
+
query: function(input, _, query) {
|
1359
|
+
return "@" + query.type + "(" + query.name + ")[" + (input.inspect()) + "]";
|
1360
|
+
},
|
1361
|
+
destructure: function(constraint, name, argnum) {
|
1362
|
+
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
1363
|
+
},
|
1364
|
+
"native": function(id) {
|
1365
|
+
return "!" + id;
|
1366
|
+
},
|
1367
|
+
param: function(name, exprs) {
|
1368
|
+
var expr;
|
1369
|
+
if (!exprs.length) {
|
1370
|
+
return "(" + name + ")";
|
1348
1371
|
}
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
return "<" + (e.inspect()) + ">";
|
1356
|
-
},
|
1357
|
-
variable: function(name) {
|
1358
|
-
return "%" + name;
|
1359
|
-
},
|
1360
|
-
query: function(input, _, query) {
|
1361
|
-
return "@" + query.type + "(" + query.name + ")[" + (input.inspect()) + "]";
|
1362
|
-
},
|
1363
|
-
destructure: function(constraint, name, argnum) {
|
1364
|
-
return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
|
1365
|
-
},
|
1366
|
-
"native": function(id) {
|
1367
|
-
return "!" + id;
|
1368
|
-
},
|
1369
|
-
param: function(name, exprs) {
|
1370
|
-
var expr;
|
1371
|
-
if (!exprs.length) {
|
1372
|
-
return "(" + name + ")";
|
1372
|
+
exprs = (function() {
|
1373
|
+
var _i, _len, _results;
|
1374
|
+
_results = [];
|
1375
|
+
for (_i = 0, _len = exprs.length; _i < _len; _i++) {
|
1376
|
+
expr = exprs[_i];
|
1377
|
+
_results.push(expr.inspect());
|
1373
1378
|
}
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
}
|
1381
|
-
return _results;
|
1382
|
-
})();
|
1383
|
-
return "(" + name + " " + (exprs.join(' ')) + ")";
|
1384
|
-
},
|
1385
|
-
any: function() {
|
1386
|
-
return '*';
|
1387
|
-
}
|
1388
|
-
});
|
1389
|
-
};
|
1390
|
-
|
1391
|
-
TypeExpr.prototype.equals = function(other) {
|
1392
|
-
var _this = this;
|
1393
|
-
if (this._tag !== other._tag) {
|
1394
|
-
return false;
|
1379
|
+
return _results;
|
1380
|
+
})();
|
1381
|
+
return "(" + name + " " + (exprs.join(' ')) + ")";
|
1382
|
+
},
|
1383
|
+
any: function() {
|
1384
|
+
return '*';
|
1395
1385
|
}
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
return
|
1411
|
-
}
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
return
|
1424
|
-
}
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
}
|
1429
|
-
if (argnum !== other.argnum) {
|
1386
|
+
});
|
1387
|
+
};
|
1388
|
+
|
1389
|
+
TypeExpr.prototype.equals = function(other) {
|
1390
|
+
var _this = this;
|
1391
|
+
if (this._tag !== other._tag) {
|
1392
|
+
return false;
|
1393
|
+
}
|
1394
|
+
return this.cases({
|
1395
|
+
expr: function(e) {
|
1396
|
+
return e === other.expr;
|
1397
|
+
},
|
1398
|
+
query: function(input, scope, query) {
|
1399
|
+
if (scope !== other.scope) {
|
1400
|
+
return false;
|
1401
|
+
}
|
1402
|
+
if (query !== other.query) {
|
1403
|
+
return false;
|
1404
|
+
}
|
1405
|
+
return input.equals(other.input);
|
1406
|
+
},
|
1407
|
+
"native": function(id) {
|
1408
|
+
return id === other.id;
|
1409
|
+
},
|
1410
|
+
param: function(name, constraints) {
|
1411
|
+
var constraint, i, _i, _len;
|
1412
|
+
if (name !== other.name) {
|
1413
|
+
return false;
|
1414
|
+
}
|
1415
|
+
for (i = _i = 0, _len = constraints.length; _i < _len; i = ++_i) {
|
1416
|
+
constraint = constraints[i];
|
1417
|
+
if (!constraint.equals(other.constraints[i])) {
|
1430
1418
|
return false;
|
1431
1419
|
}
|
1432
|
-
return constraint.equals(other.constraint);
|
1433
|
-
},
|
1434
|
-
other: function() {
|
1435
|
-
return _this === other;
|
1436
1420
|
}
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
r = function(ast) {
|
1443
|
-
return TypeExpr.fromAST(ast, scope);
|
1444
|
-
};
|
1445
|
-
e = TypeExpr;
|
1446
|
-
return typeAST.cases({
|
1447
|
-
concrete: function(name) {
|
1448
|
-
if (typeof Type[name] !== 'function') {
|
1449
|
-
throw new Error("unknown type " + name);
|
1450
|
-
}
|
1451
|
-
return e.param(name, []);
|
1452
|
-
},
|
1453
|
-
variable: function(name) {
|
1454
|
-
return scope.cache(name, function() {
|
1455
|
-
return e.variable(name);
|
1456
|
-
});
|
1457
|
-
},
|
1458
|
-
"native": function(id) {
|
1459
|
-
return e["native"](id);
|
1460
|
-
},
|
1461
|
-
wildcard: function() {
|
1462
|
-
return e.any();
|
1463
|
-
},
|
1464
|
-
list: function(el) {
|
1465
|
-
return e.param('list', [r(el)]);
|
1466
|
-
},
|
1467
|
-
block: function(el) {
|
1468
|
-
return e.param('block', [r(el.from), r(el.to)]);
|
1469
|
-
},
|
1470
|
-
pair: function(first, second) {
|
1471
|
-
return e.param('pair', [r(first), r(second)]);
|
1421
|
+
return true;
|
1422
|
+
},
|
1423
|
+
destructure: function(constraint, name, argnum) {
|
1424
|
+
if (name !== other.type) {
|
1425
|
+
return false;
|
1472
1426
|
}
|
1473
|
-
|
1427
|
+
if (argnum !== other.argnum) {
|
1428
|
+
return false;
|
1429
|
+
}
|
1430
|
+
return constraint.equals(other.constraint);
|
1431
|
+
},
|
1432
|
+
other: function() {
|
1433
|
+
return _this === other;
|
1434
|
+
}
|
1435
|
+
});
|
1436
|
+
};
|
1437
|
+
|
1438
|
+
TypeExpr.fromAST = function(typeAST, scope) {
|
1439
|
+
var e, r;
|
1440
|
+
r = function(ast) {
|
1441
|
+
return TypeExpr.fromAST(ast, scope);
|
1474
1442
|
};
|
1443
|
+
e = TypeExpr;
|
1444
|
+
return typeAST.cases({
|
1445
|
+
concrete: function(name) {
|
1446
|
+
if (typeof Type[name] !== 'function') {
|
1447
|
+
throw new Error("unknown type " + name);
|
1448
|
+
}
|
1449
|
+
return e.param(name, []);
|
1450
|
+
},
|
1451
|
+
variable: function(name) {
|
1452
|
+
return scope.cache(name, function() {
|
1453
|
+
return e.variable(name);
|
1454
|
+
});
|
1455
|
+
},
|
1456
|
+
"native": function(id) {
|
1457
|
+
return e["native"](id);
|
1458
|
+
},
|
1459
|
+
wildcard: function() {
|
1460
|
+
return e.any();
|
1461
|
+
},
|
1462
|
+
list: function(el) {
|
1463
|
+
return e.param('list', [r(el)]);
|
1464
|
+
},
|
1465
|
+
block: function(el) {
|
1466
|
+
return e.param('block', [r(el.from), r(el.to)]);
|
1467
|
+
},
|
1468
|
+
pair: function(first, second) {
|
1469
|
+
return e.param('pair', [r(first), r(second)]);
|
1470
|
+
}
|
1471
|
+
});
|
1472
|
+
};
|
1475
1473
|
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1474
|
+
TypeExpr.fromType = function(t) {
|
1475
|
+
var st;
|
1476
|
+
if (t._tag === 'entity') {
|
1477
|
+
return TypeExpr["native"](t.id);
|
1478
|
+
}
|
1479
|
+
return TypeExpr.param(t._tag, (function() {
|
1480
|
+
var _i, _len, _ref4, _results;
|
1481
|
+
_ref4 = t._values;
|
1482
|
+
_results = [];
|
1483
|
+
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
1484
|
+
st = _ref4[_i];
|
1485
|
+
_results.push(this.fromType(st));
|
1480
1486
|
}
|
1481
|
-
return
|
1482
|
-
|
1483
|
-
|
1484
|
-
_results = [];
|
1485
|
-
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
|
1486
|
-
st = _ref4[_i];
|
1487
|
-
_results.push(this.fromType(st));
|
1488
|
-
}
|
1489
|
-
return _results;
|
1490
|
-
}).call(this));
|
1491
|
-
};
|
1487
|
+
return _results;
|
1488
|
+
}).call(this));
|
1489
|
+
};
|
1492
1490
|
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1491
|
+
TypeExpr.prototype.map = function(f) {
|
1492
|
+
return this.cases({
|
1493
|
+
param: function(name, params) {
|
1494
|
+
var p;
|
1495
|
+
return TypeExpr.param(name, (function() {
|
1496
|
+
var _i, _len, _results;
|
1497
|
+
_results = [];
|
1498
|
+
for (_i = 0, _len = params.length; _i < _len; _i++) {
|
1499
|
+
p = params[_i];
|
1500
|
+
_results.push(f(p));
|
1501
|
+
}
|
1502
|
+
return _results;
|
1503
|
+
})());
|
1504
|
+
},
|
1505
|
+
query: function(input, scope, query) {
|
1506
|
+
return TypeExpr.query(f(input), scope, query);
|
1507
|
+
},
|
1508
|
+
destructure: function(constraint, name, argnum) {
|
1509
|
+
return TypeExpr.destructure(f(constraint), name, argnum);
|
1510
|
+
},
|
1511
|
+
other: function() {
|
1512
|
+
return this;
|
1513
|
+
}
|
1514
|
+
});
|
1515
|
+
};
|
1518
1516
|
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1517
|
+
TypeExpr.prototype.mapAsync = function(f, cb) {
|
1518
|
+
return this.cases({
|
1519
|
+
param: function(name, params) {
|
1520
|
+
return asyncMap(params, f, function(ps) {
|
1521
|
+
return cb(TypeExpr.param(name, ps));
|
1522
|
+
});
|
1523
|
+
},
|
1524
|
+
query: function(input, scope, query) {
|
1525
|
+
return f(input, function(i) {
|
1526
|
+
return cb(TypeExpr.query(i, scope, query));
|
1527
|
+
});
|
1528
|
+
},
|
1529
|
+
destructure: function(param, name, argnum) {
|
1530
|
+
return f(param, function(p) {
|
1531
|
+
return cb(TypeExpr.destructure(p, name, argnum));
|
1532
|
+
});
|
1533
|
+
},
|
1534
|
+
other: function() {
|
1535
|
+
return cb(this);
|
1536
|
+
}
|
1537
|
+
});
|
1538
|
+
};
|
1539
|
+
|
1540
|
+
return TypeExpr;
|
1541
1541
|
|
1542
|
-
|
1542
|
+
})(Union);
|
1543
1543
|
|
1544
|
-
|
1544
|
+
analyze = Gibbon.analyze = (function() {
|
1545
|
+
var generate, solve;
|
1545
1546
|
generate = (function() {
|
1546
1547
|
var NativeContext, Scope;
|
1547
1548
|
NativeContext = (function() {
|
@@ -1999,6 +2000,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1999
2000
|
return next();
|
2000
2001
|
};
|
2001
2002
|
matchError = function() {
|
2003
|
+
|
2002
2004
|
error('match', lhs, rhs);
|
2003
2005
|
return next();
|
2004
2006
|
};
|
@@ -2018,6 +2020,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2018
2020
|
return rhs.cases({
|
2019
2021
|
variable: swap,
|
2020
2022
|
expr: swap,
|
2023
|
+
any: swap,
|
2021
2024
|
"native": function(otherId) {
|
2022
2025
|
if (id === otherId) {
|
2023
2026
|
return skip();
|
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.3.
|
4
|
+
version: 0.3.8
|
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-08-
|
12
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: therubyracer
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash:
|
58
|
+
hash: 2444619293848573990
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash:
|
67
|
+
hash: 2444619293848573990
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project: goodguide-gibbon
|
70
70
|
rubygems_version: 1.8.23
|