goodguide-gibbon 0.3.8 → 0.4.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.dev.js +371 -118
- data/vendor/gibbon/lib/gibbon.browser.js +371 -118
- data/vendor/gibbon/package.json +1 -1
- metadata +9 -14
@@ -854,7 +854,8 @@ Gibbon.AST = AST = (function(_super) {
|
|
854
854
|
string: ['value'],
|
855
855
|
subst: ['flow'],
|
856
856
|
block: ['flow'],
|
857
|
-
list: ['elements'],
|
857
|
+
list: ['elements', 'squish'],
|
858
|
+
defaulted: ['body', 'alternative'],
|
858
859
|
query: ['type', 'name'],
|
859
860
|
func: ['name', 'args'],
|
860
861
|
pair: ['first', 'second'],
|
@@ -902,9 +903,11 @@ Gibbon.AST = AST = (function(_super) {
|
|
902
903
|
block: function(flow) {
|
903
904
|
return "{ " + (flow.inspect()) + " }";
|
904
905
|
},
|
905
|
-
list: function(els) {
|
906
|
-
var el;
|
907
|
-
|
906
|
+
list: function(els, squish) {
|
907
|
+
var close, el, open;
|
908
|
+
open = squish ? '[*' : '[';
|
909
|
+
close = squish ? '*]' : ']';
|
910
|
+
return "" + open + " " + (((function() {
|
908
911
|
var _i, _len, _results;
|
909
912
|
_results = [];
|
910
913
|
for (_i = 0, _len = els.length; _i < _len; _i++) {
|
@@ -912,7 +915,10 @@ Gibbon.AST = AST = (function(_super) {
|
|
912
915
|
_results.push(el.inspect());
|
913
916
|
}
|
914
917
|
return _results;
|
915
|
-
})()).join(', ')) + "
|
918
|
+
})()).join(', ')) + " " + close;
|
919
|
+
},
|
920
|
+
defaulted: function(body, alt) {
|
921
|
+
return "" + (body.inspect()) + " | " + (alt.inspect());
|
916
922
|
},
|
917
923
|
func: function(name, args) {
|
918
924
|
var arg;
|
@@ -1002,52 +1008,51 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
|
|
1002
1008
|
})(Union);
|
1003
1009
|
|
1004
1010
|
parse = Gibbon.parse = (function() {
|
1005
|
-
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,
|
1006
|
-
|
1007
|
-
|
1008
|
-
var _this = this;
|
1009
|
-
return Parsimmon.Parser(function(stream, i, onSuccess) {
|
1010
|
-
return _this._(stream, i, onSuccess, function(newStream, _, defMessage) {
|
1011
|
-
var at;
|
1012
|
-
at = stream.slice(0, 10) || 'EOF';
|
1013
|
-
throw new Error("Parse Error: expected " + (message || defMessage) + " (at '" + at + "')");
|
1014
|
-
});
|
1015
|
-
});
|
1011
|
+
var accessor, accessorExpr, arrow, arrowType, assertString, bang, blankLines, blockExpr, blockType, comma, commaSepFlows, comment, component, concrete, decimal, decimalExpr, defaulted, define, definition, expr, fail, flow, fraction, fractionExpr, frame, freeFrame, fullSignature, func, funcPlaceholder, identifier, innerFrame, integer, integerExpr, isString, label, labelVal, lbrace, lbrack, lexeme, lines, listExpr, listType, lparen, lsplat, metadata, multiline, name, nativeId, nativeType, nonDefaultedFlow, nonPairedFlow, numericExpr, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, queryExpr, rbrace, rbrack, regex, rparen, rsplat, signature, simpleType, singletonFlow, squishListExpr, str, string, stringExpr, substExpr, succeed, tag, tassign, type, typeVar, variable, whitespace, wildType, wildcard;
|
1012
|
+
tag = function(name, parser) {
|
1013
|
+
return parser.tag(name);
|
1016
1014
|
};
|
1017
|
-
Parsimmon.Parser.prototype.
|
1015
|
+
Parsimmon.Parser.prototype.tag = function(name) {
|
1018
1016
|
var _this = this;
|
1019
1017
|
return Parsimmon.Parser(function(stream, i, onSuccess, onFailure) {
|
1020
|
-
return _this._(stream, i, onSuccess, function() {
|
1021
|
-
return onFailure(stream,
|
1018
|
+
return _this._(stream, i, onSuccess, function(stream, newI, expected) {
|
1019
|
+
return onFailure(stream, newI, name);
|
1022
1020
|
});
|
1023
1021
|
});
|
1024
1022
|
};
|
1025
|
-
|
1023
|
+
string = Parsimmon.string, regex = Parsimmon.regex, succeed = Parsimmon.succeed, fail = Parsimmon.fail;
|
1024
|
+
whitespace = regex(/^[ \t]*/);
|
1025
|
+
blankLines = regex(/^[\n\s]+/);
|
1026
1026
|
comment = regex(/^#.*?(\n|$)/);
|
1027
|
-
|
1027
|
+
lines = (blankLines.or(comment)).many();
|
1028
1028
|
lexeme = function(p) {
|
1029
|
-
return p.skip(
|
1029
|
+
return p.skip(whitespace);
|
1030
1030
|
};
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1031
|
+
multiline = function(p) {
|
1032
|
+
return p.skip(lines);
|
1033
|
+
};
|
1034
|
+
identifier = tag('an identifier', regex(/^[a-z][\w-]*[?]?/i));
|
1035
|
+
arrow = multiline(string('->'));
|
1036
|
+
define = multiline(string(':='));
|
1037
|
+
pair = multiline(string(':'));
|
1038
|
+
lbrace = multiline(string('{'));
|
1036
1039
|
rbrace = lexeme(string('}'));
|
1037
|
-
lbrack =
|
1040
|
+
lbrack = multiline(string('['));
|
1038
1041
|
rbrack = lexeme(string(']'));
|
1039
|
-
lparen =
|
1042
|
+
lparen = multiline(string('('));
|
1040
1043
|
rparen = lexeme(string(')'));
|
1041
1044
|
comma = lexeme(string(','));
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
+
defaulted = multiline(string('|'));
|
1046
|
+
lsplat = multiline(string('[*'));
|
1047
|
+
rsplat = lexeme(string('*]'));
|
1048
|
+
query = lexeme(string('.').then(identifier));
|
1049
|
+
accessor = lexeme(string('@').then(identifier));
|
1045
1050
|
name = lexeme(identifier);
|
1046
|
-
str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'")
|
1047
|
-
fraction = lexeme(regex(/^\d+\/\d+/));
|
1048
|
-
decimal = lexeme(regex(/^\d+\.\d+/));
|
1049
|
-
percent = lexeme(regex(/^\d+%/));
|
1050
|
-
integer = lexeme(regex(/^\d+/));
|
1051
|
+
str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'")));
|
1052
|
+
fraction = tag('a fraction', lexeme(regex(/^\d+\/\d+/)));
|
1053
|
+
decimal = tag('a decimal', lexeme(regex(/^\d+\.\d+/)));
|
1054
|
+
percent = tag('a percentage', lexeme(regex(/^\d+%/)));
|
1055
|
+
integer = tag('a number', lexeme(regex(/^\d+/)));
|
1051
1056
|
label = lexeme(identifier.skip(string(':')));
|
1052
1057
|
labelVal = lexeme(regex(/^[^\n]*/));
|
1053
1058
|
variable = lexeme(string('%').then(identifier));
|
@@ -1080,25 +1085,25 @@ parse = Gibbon.parse = (function() {
|
|
1080
1085
|
});
|
1081
1086
|
numericExpr = percentExpr.or(decimalExpr.or(fractionExpr.or(integerExpr)));
|
1082
1087
|
parenFlow = lparen.then(function() {
|
1083
|
-
return flow.
|
1088
|
+
return flow.skip(rparen);
|
1084
1089
|
});
|
1085
1090
|
substExpr = parenFlow.map(function(fl) {
|
1086
1091
|
return AST.subst(fl);
|
1087
1092
|
});
|
1088
1093
|
listExpr = lbrack.then(function() {
|
1089
|
-
return
|
1090
|
-
return
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1094
|
+
return commaSepFlows.then(function(els) {
|
1095
|
+
return rbrack.result(AST.list(els, false));
|
1096
|
+
});
|
1097
|
+
});
|
1098
|
+
squishListExpr = lsplat.then(function() {
|
1099
|
+
return commaSepFlows.then(function(els) {
|
1100
|
+
return rsplat.result(AST.list(els, true));
|
1096
1101
|
});
|
1097
1102
|
});
|
1098
1103
|
blockExpr = lbrace.then(function() {
|
1099
|
-
return flow.skip(rbrace
|
1104
|
+
return flow.skip(rbrace);
|
1100
1105
|
}).map(AST.block);
|
1101
|
-
expr = queryExpr.or(accessorExpr.or(substExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))));
|
1106
|
+
expr = tag('an expr', queryExpr.or(accessorExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))))));
|
1102
1107
|
singletonFlow = expr.map(function(e) {
|
1103
1108
|
return AST.flow(e, null);
|
1104
1109
|
});
|
@@ -1107,7 +1112,7 @@ parse = Gibbon.parse = (function() {
|
|
1107
1112
|
return AST.func(funcName, args);
|
1108
1113
|
});
|
1109
1114
|
});
|
1110
|
-
component = expr.or(func);
|
1115
|
+
component = multiline(expr.or(func));
|
1111
1116
|
nonPairedFlow = component.then(function(first) {
|
1112
1117
|
return arrow.then(component).many().map(function(rest) {
|
1113
1118
|
var comp, cursor, _i, _len;
|
@@ -1119,34 +1124,47 @@ parse = Gibbon.parse = (function() {
|
|
1119
1124
|
return cursor;
|
1120
1125
|
});
|
1121
1126
|
});
|
1122
|
-
|
1123
|
-
return pair.then(
|
1127
|
+
nonDefaultedFlow = nonPairedFlow.then(function(first) {
|
1128
|
+
return pair.then(nonDefaultedFlow).map(function(second) {
|
1124
1129
|
return AST.flow(AST.pair(first, second), null);
|
1125
1130
|
}).or(succeed(first));
|
1126
1131
|
});
|
1132
|
+
flow = tag('a flow', nonDefaultedFlow.then(function(body) {
|
1133
|
+
return defaulted.then(flow).map(function(alternative) {
|
1134
|
+
return AST.flow(AST.defaulted(body, alternative), null);
|
1135
|
+
}).or(succeed(body));
|
1136
|
+
}));
|
1137
|
+
commaSepFlows = flow.skip(comma.or(succeed(null)).then(lines)).many().then(function(els) {
|
1138
|
+
return flow.or(succeed(null)).map(function(final) {
|
1139
|
+
if (final) {
|
1140
|
+
els.push(final);
|
1141
|
+
}
|
1142
|
+
return els;
|
1143
|
+
});
|
1144
|
+
});
|
1127
1145
|
metadata = label.then(function(key) {
|
1128
1146
|
return labelVal.map(function(text) {
|
1129
1147
|
return AST.metadata(key, text);
|
1130
1148
|
});
|
1131
1149
|
});
|
1132
|
-
definition = metadata.many().then(function(md) {
|
1150
|
+
definition = tag('a definition', metadata.many().then(function(md) {
|
1133
1151
|
return name.then(function(n) {
|
1134
|
-
return define.then(innerFrame
|
1152
|
+
return define.then(innerFrame).map(function(fl) {
|
1135
1153
|
return AST.definition(md, n, fl);
|
1136
1154
|
});
|
1137
1155
|
});
|
1138
|
-
});
|
1156
|
+
}));
|
1139
1157
|
frame = definition.many().then(function(defs) {
|
1140
|
-
return flow.
|
1158
|
+
return flow.map(function(fl) {
|
1141
1159
|
return AST.frame(defs, fl);
|
1142
1160
|
});
|
1143
1161
|
});
|
1144
|
-
parenFrame = lparen.then(frame).skip(rparen.
|
1162
|
+
parenFrame = lparen.then(frame).skip(rparen.then(lines));
|
1145
1163
|
freeFrame = flow.map(function(fl) {
|
1146
1164
|
return AST.frame([], fl);
|
1147
1165
|
});
|
1148
1166
|
innerFrame = parenFrame.or(freeFrame);
|
1149
|
-
program =
|
1167
|
+
program = lines.then(frame);
|
1150
1168
|
tassign = lexeme(string('='));
|
1151
1169
|
bang = lexeme(string('!'));
|
1152
1170
|
nativeId = lexeme(regex(/^\w+/));
|
@@ -1158,27 +1176,27 @@ parse = Gibbon.parse = (function() {
|
|
1158
1176
|
});
|
1159
1177
|
wildType = wildcard.result(TypeAST.wildcard());
|
1160
1178
|
listType = lbrack.then(function() {
|
1161
|
-
return type.skip(rbrack
|
1179
|
+
return type.skip(rbrack).map(function(t) {
|
1162
1180
|
return TypeAST.list(t);
|
1163
1181
|
});
|
1164
1182
|
});
|
1165
1183
|
parenType = lparen.then(function() {
|
1166
|
-
return type.skip(rparen
|
1184
|
+
return type.skip(rparen);
|
1167
1185
|
});
|
1168
1186
|
blockType = lbrace.then(function() {
|
1169
|
-
return arrowType.skip(rbrace
|
1187
|
+
return arrowType.skip(rbrace).map(function(t) {
|
1170
1188
|
return TypeAST.block(t);
|
1171
1189
|
});
|
1172
1190
|
});
|
1173
1191
|
nativeType = bang.then(nativeId).map(TypeAST["native"]);
|
1174
|
-
simpleType =
|
1192
|
+
simpleType = typeVar.or(wildType.or(listType.or(parenType.or(blockType.or(concrete.or(nativeType))))));
|
1175
1193
|
type = simpleType.then(function(first) {
|
1176
|
-
return pair.then(type
|
1194
|
+
return pair.then(type).map(function(second) {
|
1177
1195
|
return TypeAST.pair(first, second);
|
1178
1196
|
}).or(succeed(first));
|
1179
1197
|
});
|
1180
1198
|
arrowType = type.then(function(first) {
|
1181
|
-
return arrow.then(type
|
1199
|
+
return arrow.then(type).map(function(second) {
|
1182
1200
|
return TypeAST.arrow(first, second);
|
1183
1201
|
});
|
1184
1202
|
});
|
@@ -1189,7 +1207,7 @@ parse = Gibbon.parse = (function() {
|
|
1189
1207
|
});
|
1190
1208
|
});
|
1191
1209
|
});
|
1192
|
-
fullSignature =
|
1210
|
+
fullSignature = lines.then(signature);
|
1193
1211
|
isString = function(s) {
|
1194
1212
|
return typeof s === 'string' || s instanceof String;
|
1195
1213
|
};
|
@@ -1233,10 +1251,11 @@ Gibbon.Semantic = Semantic = (function(_super) {
|
|
1233
1251
|
localAccessor: ['name'],
|
1234
1252
|
pair: ['first', 'second'],
|
1235
1253
|
block: ['body'],
|
1236
|
-
list: ['elements'],
|
1254
|
+
list: ['elements', 'squish'],
|
1237
1255
|
flow: ['type', 'head', 'tail'],
|
1238
1256
|
func: ['name', 'args'],
|
1239
|
-
subst: ['flow']
|
1257
|
+
subst: ['flow'],
|
1258
|
+
defaulted: ['body', 'alternative']
|
1240
1259
|
});
|
1241
1260
|
|
1242
1261
|
return Semantic;
|
@@ -1719,6 +1738,12 @@ analyze = Gibbon.analyze = (function() {
|
|
1719
1738
|
input = TypeExpr.variable('.input');
|
1720
1739
|
push(TypeExpr.expr(flow), TypeExpr.param('block', [input, TypeExpr.expr(subFlow)]));
|
1721
1740
|
return _this.analyzeFlow(subFlow, input, push);
|
1741
|
+
},
|
1742
|
+
defaulted: function(body, alt) {
|
1743
|
+
push(TypeExpr.expr(body), TypeExpr.expr(alt));
|
1744
|
+
push(TypeExpr.expr(flow), TypeExpr.expr(alt));
|
1745
|
+
_this.analyzeFlow(body, global, push);
|
1746
|
+
return _this.analyzeFlow(alt, global, push);
|
1722
1747
|
}
|
1723
1748
|
});
|
1724
1749
|
};
|
@@ -1926,7 +1951,7 @@ analyze = Gibbon.analyze = (function() {
|
|
1926
1951
|
block: function(flow) {
|
1927
1952
|
return Semantic.block(toSemanticTree(flow));
|
1928
1953
|
},
|
1929
|
-
list: function(elements) {
|
1954
|
+
list: function(elements, squish) {
|
1930
1955
|
var e;
|
1931
1956
|
return Semantic.list((function() {
|
1932
1957
|
var _i, _len, _results;
|
@@ -1936,7 +1961,10 @@ analyze = Gibbon.analyze = (function() {
|
|
1936
1961
|
_results.push(toSemanticTree(e));
|
1937
1962
|
}
|
1938
1963
|
return _results;
|
1939
|
-
})());
|
1964
|
+
})(), squish);
|
1965
|
+
},
|
1966
|
+
defaulted: function(body, alt) {
|
1967
|
+
return Semantic.defaulted(toSemanticTree(body), toSemanticTree(alt));
|
1940
1968
|
},
|
1941
1969
|
integer: function() {
|
1942
1970
|
return Semantic.literal(this);
|
@@ -2094,7 +2122,7 @@ analyze = Gibbon.analyze = (function() {
|
|
2094
2122
|
};
|
2095
2123
|
})();
|
2096
2124
|
// Generated by CoffeeScript 1.6.3
|
2097
|
-
var Dependency, Promise, Value, eval_, _ref, _ref1,
|
2125
|
+
var Dependency, Failure, Promise, Value, eval_, _ref, _ref1, _ref2,
|
2098
2126
|
__hasProp = {}.hasOwnProperty,
|
2099
2127
|
__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; },
|
2100
2128
|
__slice = [].slice;
|
@@ -2337,6 +2365,23 @@ Promise = (function() {
|
|
2337
2365
|
});
|
2338
2366
|
};
|
2339
2367
|
|
2368
|
+
Promise.prototype.rescue = function(fn) {
|
2369
|
+
var _this = this;
|
2370
|
+
return new Promise(function(fail, cb) {
|
2371
|
+
var rescue;
|
2372
|
+
rescue = function(failure) {
|
2373
|
+
return fn(failure).depends([Dependency.failure(failure)]).force(fail, cb);
|
2374
|
+
};
|
2375
|
+
return _this.force(rescue, cb);
|
2376
|
+
});
|
2377
|
+
};
|
2378
|
+
|
2379
|
+
Promise.prototype.or = function(other) {
|
2380
|
+
return this.rescue(function(_) {
|
2381
|
+
return other;
|
2382
|
+
});
|
2383
|
+
};
|
2384
|
+
|
2340
2385
|
Promise.prototype.depends = function(deps) {
|
2341
2386
|
var _this = this;
|
2342
2387
|
return new Promise(function(fail, cc) {
|
@@ -2441,21 +2486,65 @@ Promise = (function() {
|
|
2441
2486
|
|
2442
2487
|
})();
|
2443
2488
|
|
2444
|
-
|
2489
|
+
Gibbon.Failure = Failure = (function(_super) {
|
2490
|
+
__extends(Failure, _super);
|
2491
|
+
|
2492
|
+
function Failure() {
|
2493
|
+
_ref1 = Failure.__super__.constructor.apply(this, arguments);
|
2494
|
+
return _ref1;
|
2495
|
+
}
|
2496
|
+
|
2497
|
+
Failure.types({
|
2498
|
+
query: ['id', 'annotations'],
|
2499
|
+
composite: ['failures']
|
2500
|
+
});
|
2501
|
+
|
2502
|
+
Failure.prototype.equals = function(other) {
|
2503
|
+
if (this._tag !== other._tag) {
|
2504
|
+
return false;
|
2505
|
+
}
|
2506
|
+
return this.cases({
|
2507
|
+
query: function(id, annotations) {
|
2508
|
+
if (annotations !== other.annotations) {
|
2509
|
+
return false;
|
2510
|
+
}
|
2511
|
+
if (id !== other.id) {
|
2512
|
+
return false;
|
2513
|
+
}
|
2514
|
+
},
|
2515
|
+
composite: function(failures) {
|
2516
|
+
var failure, i, _i, _len;
|
2517
|
+
for (i = _i = 0, _len = failures.length; _i < _len; i = ++_i) {
|
2518
|
+
failure = failures[i];
|
2519
|
+
if (!failure.equals(other.failures[i])) {
|
2520
|
+
return false;
|
2521
|
+
}
|
2522
|
+
}
|
2523
|
+
return true;
|
2524
|
+
}
|
2525
|
+
});
|
2526
|
+
};
|
2527
|
+
|
2528
|
+
return Failure;
|
2529
|
+
|
2530
|
+
})(Union);
|
2531
|
+
|
2532
|
+
Gibbon.Dependency = Dependency = (function(_super) {
|
2445
2533
|
__extends(Dependency, _super);
|
2446
2534
|
|
2447
2535
|
function Dependency() {
|
2448
|
-
|
2449
|
-
return
|
2536
|
+
_ref2 = Dependency.__super__.constructor.apply(this, arguments);
|
2537
|
+
return _ref2;
|
2450
2538
|
}
|
2451
2539
|
|
2452
2540
|
Dependency.types({
|
2453
2541
|
query: ['entity', 'query'],
|
2454
|
-
lexical: ['key']
|
2542
|
+
lexical: ['key'],
|
2543
|
+
failure: ['failure']
|
2455
2544
|
});
|
2456
2545
|
|
2457
2546
|
Dependency.prototype.equals = function(other) {
|
2458
|
-
if (this.
|
2547
|
+
if (this._tag !== other._tag) {
|
2459
2548
|
return false;
|
2460
2549
|
}
|
2461
2550
|
return this.cases({
|
@@ -2470,6 +2559,9 @@ Dependency = (function(_super) {
|
|
2470
2559
|
},
|
2471
2560
|
lexical: function(key) {
|
2472
2561
|
return key === other.key;
|
2562
|
+
},
|
2563
|
+
failure: function(failure) {
|
2564
|
+
return failure.equals(other.failure);
|
2473
2565
|
}
|
2474
2566
|
});
|
2475
2567
|
};
|
@@ -2481,6 +2573,9 @@ Dependency = (function(_super) {
|
|
2481
2573
|
},
|
2482
2574
|
lexical: function(definition) {
|
2483
2575
|
return "@" + definition.name;
|
2576
|
+
},
|
2577
|
+
failure: function(failure) {
|
2578
|
+
return "!";
|
2484
2579
|
}
|
2485
2580
|
});
|
2486
2581
|
};
|
@@ -2567,9 +2662,9 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2567
2662
|
eSecond = evalFlow(second, global);
|
2568
2663
|
return Promise.unit(Value.pair(eFirst, eSecond));
|
2569
2664
|
},
|
2570
|
-
list: function(elements) {
|
2571
|
-
var e;
|
2572
|
-
|
2665
|
+
list: function(elements, squished) {
|
2666
|
+
var e, list;
|
2667
|
+
list = Promise.unit(Value.list((function() {
|
2573
2668
|
var _i, _len, _results;
|
2574
2669
|
_results = [];
|
2575
2670
|
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
@@ -2577,13 +2672,20 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2577
2672
|
_results.push(evalFlow(e, global));
|
2578
2673
|
}
|
2579
2674
|
return _results;
|
2580
|
-
})();
|
2581
|
-
|
2675
|
+
})()));
|
2676
|
+
if (squished) {
|
2677
|
+
return stdlib.squish.impl(list);
|
2678
|
+
} else {
|
2679
|
+
return list;
|
2680
|
+
}
|
2582
2681
|
},
|
2583
2682
|
block: function(body) {
|
2584
2683
|
return Promise.unit(Value.block(function(inputPromise) {
|
2585
2684
|
return evalFlow(body, inputPromise);
|
2586
2685
|
}));
|
2686
|
+
},
|
2687
|
+
defaulted: function(body, alt) {
|
2688
|
+
return evalFlow(body, global).or(evalFlow(alt, global));
|
2587
2689
|
}
|
2588
2690
|
});
|
2589
2691
|
};
|
@@ -2592,10 +2694,10 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2592
2694
|
});
|
2593
2695
|
};
|
2594
2696
|
return function(semantics, table, id, client, finish) {
|
2595
|
-
var entity, key, onFailure, onSuccess, _i, _len,
|
2596
|
-
|
2597
|
-
for (_i = 0, _len =
|
2598
|
-
key =
|
2697
|
+
var entity, key, onFailure, onSuccess, _i, _len, _ref3;
|
2698
|
+
_ref3 = semantics.keys();
|
2699
|
+
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
|
2700
|
+
key = _ref3[_i];
|
2599
2701
|
semantics.modify(key, function(val) {
|
2600
2702
|
if (val instanceof Semantic) {
|
2601
2703
|
return val;
|
@@ -2617,12 +2719,40 @@ eval_ = Gibbon["eval"] = (function() {
|
|
2617
2719
|
var stdlib;
|
2618
2720
|
|
2619
2721
|
stdlib = Gibbon.stdlib = (function() {
|
2620
|
-
var combine, iter, unit, vFalse, vTrue;
|
2722
|
+
var allBooleans, anyBooleans, combine, iter, unit, vFalse, vTrue;
|
2621
2723
|
unit = Promise.unit;
|
2622
2724
|
iter = Promise.iter;
|
2623
2725
|
combine = Promise.combine;
|
2624
2726
|
vTrue = Value.boolean(true);
|
2625
2727
|
vFalse = Value.boolean(false);
|
2728
|
+
anyBooleans = function(promises) {
|
2729
|
+
var out, step;
|
2730
|
+
step = function(cond, next) {
|
2731
|
+
if (cond.value) {
|
2732
|
+
return unit(vTrue);
|
2733
|
+
} else {
|
2734
|
+
return next();
|
2735
|
+
}
|
2736
|
+
};
|
2737
|
+
out = function() {
|
2738
|
+
return unit(vFalse);
|
2739
|
+
};
|
2740
|
+
return iter(promises, step, out);
|
2741
|
+
};
|
2742
|
+
allBooleans = function(promises) {
|
2743
|
+
var out, step;
|
2744
|
+
step = function(cond, next) {
|
2745
|
+
if (cond.value) {
|
2746
|
+
return next();
|
2747
|
+
} else {
|
2748
|
+
return unit(vFalse);
|
2749
|
+
}
|
2750
|
+
};
|
2751
|
+
out = function() {
|
2752
|
+
return unit(vTrue);
|
2753
|
+
};
|
2754
|
+
return iter(promises, step, out);
|
2755
|
+
};
|
2626
2756
|
return {
|
2627
2757
|
"case": {
|
2628
2758
|
type: parse.type('case [bool : %b] = % -> %b'),
|
@@ -2639,20 +2769,67 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2639
2769
|
});
|
2640
2770
|
};
|
2641
2771
|
out = function() {
|
2642
|
-
|
2772
|
+
return Promise.fail('non-exhaustive cases');
|
2643
2773
|
};
|
2644
2774
|
return iter(list.elements, step, out);
|
2645
2775
|
});
|
2646
2776
|
}
|
2647
2777
|
},
|
2778
|
+
"case-eq": {
|
2779
|
+
type: parse.type('case-eq [%a : %b] = %a -> %b'),
|
2780
|
+
impl: function(evalInput, evalList) {
|
2781
|
+
debugger;
|
2782
|
+
return combine([evalInput, evalList]).then(function(_arg) {
|
2783
|
+
var input, list, out, step;
|
2784
|
+
input = _arg[0], list = _arg[1];
|
2785
|
+
step = function(pair, next) {
|
2786
|
+
return pair.first.then(function(test) {
|
2787
|
+
return input.equals(test).then(function(vBool) {
|
2788
|
+
if (vBool.value) {
|
2789
|
+
return pair.second;
|
2790
|
+
} else {
|
2791
|
+
return next();
|
2792
|
+
}
|
2793
|
+
});
|
2794
|
+
});
|
2795
|
+
};
|
2796
|
+
out = function() {
|
2797
|
+
return Promise.fail('non-exhaustive cases');
|
2798
|
+
};
|
2799
|
+
return iter(list.elements, step, out);
|
2800
|
+
});
|
2801
|
+
}
|
2802
|
+
},
|
2803
|
+
"case-eq-default": {
|
2804
|
+
type: parse.type('case-eq-default %b [%a : %b] = %a -> %b'),
|
2805
|
+
impl: function(evalInput, evalDefault, evalList) {
|
2806
|
+
return stdlib['case-eq'].impl(evalInput, evalList).or(evalDefault);
|
2807
|
+
}
|
2808
|
+
},
|
2809
|
+
"any-true?": {
|
2810
|
+
type: parse.type('any-true? = [bool] -> bool'),
|
2811
|
+
impl: function(evalList) {
|
2812
|
+
return evalList.then(function(list) {
|
2813
|
+
return anyBooleans(list.elements);
|
2814
|
+
});
|
2815
|
+
}
|
2816
|
+
},
|
2817
|
+
"all-true?": {
|
2818
|
+
type: parse.type('all-true? = [bool] -> bool'),
|
2819
|
+
impl: function(evalList) {
|
2820
|
+
return evalList.then(function(list) {
|
2821
|
+
return allBooleans(list.elements);
|
2822
|
+
});
|
2823
|
+
}
|
2824
|
+
},
|
2648
2825
|
"any?": {
|
2649
2826
|
type: parse.type('any? { %a -> bool } = [%a] -> bool'),
|
2650
2827
|
impl: function(evalList, evalBlock) {
|
2651
2828
|
return combine([evalList, evalBlock]).then(function(_arg) {
|
2652
|
-
var block,
|
2829
|
+
var block, e, fn, list;
|
2653
2830
|
list = _arg[0], block = _arg[1];
|
2654
2831
|
fn = block.fn;
|
2655
|
-
|
2832
|
+
return anyBooleans((function() {
|
2656
2833
|
var _i, _len, _ref, _results;
|
2657
2834
|
_ref = list.elements;
|
2658
2835
|
_results = [];
|
@@ -2661,18 +2838,7 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2661
2838
|
_results.push(fn(e));
|
2662
2839
|
}
|
2663
2840
|
return _results;
|
2664
|
-
})();
|
2665
|
-
step = function(cond, next) {
|
2666
|
-
if (cond.value) {
|
2667
|
-
return unit(vTrue);
|
2668
|
-
} else {
|
2669
|
-
return next();
|
2670
|
-
}
|
2671
|
-
};
|
2672
|
-
out = function() {
|
2673
|
-
return unit(vFalse);
|
2674
|
-
};
|
2675
|
-
return iter(booleans, step, out);
|
2841
|
+
})());
|
2676
2842
|
});
|
2677
2843
|
}
|
2678
2844
|
},
|
@@ -2680,10 +2846,10 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2680
2846
|
type: parse.type('all? { %a -> bool } = [%a] -> bool'),
|
2681
2847
|
impl: function(evalList, evalBlock) {
|
2682
2848
|
return combine([evalList, evalBlock]).then(function(_arg) {
|
2683
|
-
var block,
|
2849
|
+
var block, e, fn, list;
|
2684
2850
|
list = _arg[0], block = _arg[1];
|
2685
2851
|
fn = block.fn;
|
2686
|
-
|
2852
|
+
return allBooleans((function() {
|
2687
2853
|
var _i, _len, _ref, _results;
|
2688
2854
|
_ref = list.elements;
|
2689
2855
|
_results = [];
|
@@ -2692,18 +2858,30 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2692
2858
|
_results.push(fn(e));
|
2693
2859
|
}
|
2694
2860
|
return _results;
|
2695
|
-
})();
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
2861
|
+
})());
|
2862
|
+
});
|
2863
|
+
}
|
2864
|
+
},
|
2865
|
+
"include?": {
|
2866
|
+
type: parse.type('include? %a = [%a] -> bool'),
|
2867
|
+
impl: function(evalList, evalElement) {
|
2868
|
+
debugger;
|
2869
|
+
return combine([evalElement, evalList]).then(function(_arg) {
|
2870
|
+
var booleans, el, list, p;
|
2871
|
+
el = _arg[0], list = _arg[1];
|
2872
|
+
booleans = (function() {
|
2873
|
+
var _i, _len, _ref, _results;
|
2874
|
+
_ref = list.elements;
|
2875
|
+
_results = [];
|
2876
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
2877
|
+
p = _ref[_i];
|
2878
|
+
_results.push(p.then(function(x) {
|
2879
|
+
return el.equals(x);
|
2880
|
+
}));
|
2701
2881
|
}
|
2702
|
-
|
2703
|
-
|
2704
|
-
|
2705
|
-
};
|
2706
|
-
return Promise.iter(booleans, step, out);
|
2882
|
+
return _results;
|
2883
|
+
})();
|
2884
|
+
return anyBooleans(booleans);
|
2707
2885
|
});
|
2708
2886
|
}
|
2709
2887
|
},
|
@@ -2743,8 +2921,7 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2743
2921
|
if (denominator === 0) {
|
2744
2922
|
return Promise.fail('cannot divide by zero');
|
2745
2923
|
}
|
2746
|
-
|
2747
|
-
return Promise.unit(Value.number(numerator / denominator));
|
2924
|
+
return unit(Value.number(numerator / denominator));
|
2748
2925
|
});
|
2749
2926
|
});
|
2750
2927
|
});
|
@@ -2847,7 +3024,42 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2847
3024
|
e = vals[_i];
|
2848
3025
|
out += e.value;
|
2849
3026
|
}
|
2850
|
-
return
|
3027
|
+
return unit(Value.number(out));
|
3028
|
+
});
|
3029
|
+
});
|
3030
|
+
}
|
3031
|
+
},
|
3032
|
+
"case-sum": {
|
3033
|
+
type: parse.type('case-sum [bool : numeric] = % -> numeric'),
|
3034
|
+
impl: function(_, evalList) {
|
3035
|
+
return evalList.then(function(list) {
|
3036
|
+
return combine(list.elements).then(function(elements) {
|
3037
|
+
var el, numbers;
|
3038
|
+
numbers = (function() {
|
3039
|
+
var _i, _len, _results;
|
3040
|
+
_results = [];
|
3041
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
3042
|
+
el = elements[_i];
|
3043
|
+
_results.push(el.first.then(function(cond) {
|
3044
|
+
if (!cond.value) {
|
3045
|
+
return unit(0);
|
3046
|
+
}
|
3047
|
+
return el.second.map(function(v) {
|
3048
|
+
return v.value;
|
3049
|
+
});
|
3050
|
+
}));
|
3051
|
+
}
|
3052
|
+
return _results;
|
3053
|
+
})();
|
3054
|
+
return combine(numbers).then(function(nums) {
|
3055
|
+
var num, out, _i, _len;
|
3056
|
+
out = 0;
|
3057
|
+
for (_i = 0, _len = nums.length; _i < _len; _i++) {
|
3058
|
+
num = nums[_i];
|
3059
|
+
out += num;
|
3060
|
+
}
|
3061
|
+
return unit(Value.number(out));
|
3062
|
+
});
|
2851
3063
|
});
|
2852
3064
|
});
|
2853
3065
|
}
|
@@ -2860,6 +3072,39 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2860
3072
|
});
|
2861
3073
|
}
|
2862
3074
|
},
|
3075
|
+
squish: {
|
3076
|
+
type: parse.type('squish = [%a] -> [%a]'),
|
3077
|
+
impl: function(list) {
|
3078
|
+
return list.then(function(_arg) {
|
3079
|
+
var elements, promise, wrapped;
|
3080
|
+
elements = _arg.elements;
|
3081
|
+
wrapped = (function() {
|
3082
|
+
var _i, _len, _results;
|
3083
|
+
_results = [];
|
3084
|
+
for (_i = 0, _len = elements.length; _i < _len; _i++) {
|
3085
|
+
promise = elements[_i];
|
3086
|
+
_results.push(promise.map(function(e) {
|
3087
|
+
return [e];
|
3088
|
+
}).or(unit([])));
|
3089
|
+
}
|
3090
|
+
return _results;
|
3091
|
+
})();
|
3092
|
+
return combine(wrapped).map(function(lists) {
|
3093
|
+
var e;
|
3094
|
+
return Value.list((function() {
|
3095
|
+
var _i, _len, _ref, _results;
|
3096
|
+
_ref = catLists(lists);
|
3097
|
+
_results = [];
|
3098
|
+
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
3099
|
+
e = _ref[_i];
|
3100
|
+
_results.push(unit(e));
|
3101
|
+
}
|
3102
|
+
return _results;
|
3103
|
+
})());
|
3104
|
+
});
|
3105
|
+
});
|
3106
|
+
}
|
3107
|
+
},
|
2863
3108
|
add: {
|
2864
3109
|
type: parse.type('add numeric = numeric -> numeric'),
|
2865
3110
|
impl: function(input, num) {
|
@@ -2892,6 +3137,14 @@ stdlib = Gibbon.stdlib = (function() {
|
|
2892
3137
|
return unit(vTrue);
|
2893
3138
|
}
|
2894
3139
|
},
|
3140
|
+
not: {
|
3141
|
+
type: parse.type('not = bool -> bool'),
|
3142
|
+
impl: function(evalBool) {
|
3143
|
+
return evalBool.map(function(bool) {
|
3144
|
+
return Value.boolean(!bool.value);
|
3145
|
+
});
|
3146
|
+
}
|
3147
|
+
},
|
2895
3148
|
gt: {
|
2896
3149
|
type: parse.type('gt numeric = numeric -> bool'),
|
2897
3150
|
impl: function(input, num) {
|
@@ -2948,15 +3201,15 @@ Gibbon.jsonConsumer = (function() {
|
|
2948
3201
|
getValue = function(id, annotations, v, callback) {
|
2949
3202
|
var entity, values;
|
2950
3203
|
if (!tables.hasOwnProperty(annotations.table)) {
|
2951
|
-
|
3204
|
+
throw new Error("no such type " + annotations.table);
|
2952
3205
|
}
|
2953
3206
|
values = tables[annotations.table].values;
|
2954
3207
|
if (!values[id]) {
|
2955
|
-
return callback(
|
3208
|
+
return callback(Failure.query(id, annotations));
|
2956
3209
|
}
|
2957
3210
|
entity = values[id];
|
2958
|
-
if (!entity.hasOwnProperty(annotations.name)) {
|
2959
|
-
return callback(
|
3211
|
+
if (!(entity.hasOwnProperty(annotations.name) && (entity[annotations.name] != null))) {
|
3212
|
+
return callback(Failure.query(id, annotations));
|
2960
3213
|
}
|
2961
3214
|
return callback(null, v.fromJSON(entity[annotations.name]));
|
2962
3215
|
};
|