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.
@@ -860,7 +860,8 @@ Gibbon.AST = AST = (function(_super) {
860
860
  string: ['value'],
861
861
  subst: ['flow'],
862
862
  block: ['flow'],
863
- list: ['elements'],
863
+ list: ['elements', 'squish'],
864
+ defaulted: ['body', 'alternative'],
864
865
  query: ['type', 'name'],
865
866
  func: ['name', 'args'],
866
867
  pair: ['first', 'second'],
@@ -908,9 +909,11 @@ Gibbon.AST = AST = (function(_super) {
908
909
  block: function(flow) {
909
910
  return "{ " + (flow.inspect()) + " }";
910
911
  },
911
- list: function(els) {
912
- var el;
913
- return "[ " + (((function() {
912
+ list: function(els, squish) {
913
+ var close, el, open;
914
+ open = squish ? '[*' : '[';
915
+ close = squish ? '*]' : ']';
916
+ return "" + open + " " + (((function() {
914
917
  var _i, _len, _results;
915
918
  _results = [];
916
919
  for (_i = 0, _len = els.length; _i < _len; _i++) {
@@ -918,7 +921,10 @@ Gibbon.AST = AST = (function(_super) {
918
921
  _results.push(el.inspect());
919
922
  }
920
923
  return _results;
921
- })()).join(', ')) + " ]";
924
+ })()).join(', ')) + " " + close;
925
+ },
926
+ defaulted: function(body, alt) {
927
+ return "" + (body.inspect()) + " | " + (alt.inspect());
922
928
  },
923
929
  func: function(name, args) {
924
930
  var arg;
@@ -1008,52 +1014,51 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
1008
1014
  })(Union);
1009
1015
 
1010
1016
  parse = Gibbon.parse = (function() {
1011
- 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, query, queryExpr, question, rbrace, rbrack, regex, rparen, signature, simpleType, singletonFlow, str, string, stringExpr, substExpr, succeed, tassign, type, typeVar, variable, whitespace, wildType, wildcard;
1012
- string = Parsimmon.string, regex = Parsimmon.regex, succeed = Parsimmon.succeed, fail = Parsimmon.fail;
1013
- Parsimmon.Parser.prototype.expected = function(message) {
1014
- var _this = this;
1015
- return Parsimmon.Parser(function(stream, i, onSuccess) {
1016
- return _this._(stream, i, onSuccess, function(newStream, _, defMessage) {
1017
- var at;
1018
- at = stream.slice(0, 10) || 'EOF';
1019
- throw new Error("Parse Error: expected " + (message || defMessage) + " (at '" + at + "')");
1020
- });
1021
- });
1017
+ 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;
1018
+ tag = function(name, parser) {
1019
+ return parser.tag(name);
1022
1020
  };
1023
- Parsimmon.Parser.prototype.named = function(name) {
1021
+ Parsimmon.Parser.prototype.tag = function(name) {
1024
1022
  var _this = this;
1025
1023
  return Parsimmon.Parser(function(stream, i, onSuccess, onFailure) {
1026
- return _this._(stream, i, onSuccess, function() {
1027
- return onFailure(stream, i, name);
1024
+ return _this._(stream, i, onSuccess, function(stream, newI, expected) {
1025
+ return onFailure(stream, newI, name);
1028
1026
  });
1029
1027
  });
1030
1028
  };
1031
- whitespace = regex(/^[\n\s]+/);
1029
+ string = Parsimmon.string, regex = Parsimmon.regex, succeed = Parsimmon.succeed, fail = Parsimmon.fail;
1030
+ whitespace = regex(/^[ \t]*/);
1031
+ blankLines = regex(/^[\n\s]+/);
1032
1032
  comment = regex(/^#.*?(\n|$)/);
1033
- ignore = (whitespace.or(comment)).many();
1033
+ lines = (blankLines.or(comment)).many();
1034
1034
  lexeme = function(p) {
1035
- return p.skip(ignore);
1035
+ return p.skip(whitespace);
1036
1036
  };
1037
- identifier = regex(/^[a-z][\w-]*[?]?/i);
1038
- arrow = lexeme(string('->'));
1039
- define = lexeme(string(':='));
1040
- pair = lexeme(string(':'));
1041
- lbrace = lexeme(string('{'));
1037
+ multiline = function(p) {
1038
+ return p.skip(lines);
1039
+ };
1040
+ identifier = tag('an identifier', regex(/^[a-z][\w-]*[?]?/i));
1041
+ arrow = multiline(string('->'));
1042
+ define = multiline(string(':='));
1043
+ pair = multiline(string(':'));
1044
+ lbrace = multiline(string('{'));
1042
1045
  rbrace = lexeme(string('}'));
1043
- lbrack = lexeme(string('['));
1046
+ lbrack = multiline(string('['));
1044
1047
  rbrack = lexeme(string(']'));
1045
- lparen = lexeme(string('('));
1048
+ lparen = multiline(string('('));
1046
1049
  rparen = lexeme(string(')'));
1047
1050
  comma = lexeme(string(','));
1048
- question = lexeme(string('?'));
1049
- query = lexeme(string('.').then(identifier.expected()));
1050
- accessor = lexeme(string('@').then(identifier.expected()));
1051
+ defaulted = multiline(string('|'));
1052
+ lsplat = multiline(string('[*'));
1053
+ rsplat = lexeme(string('*]'));
1054
+ query = lexeme(string('.').then(identifier));
1055
+ accessor = lexeme(string('@').then(identifier));
1051
1056
  name = lexeme(identifier);
1052
- str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'").expected()));
1053
- fraction = lexeme(regex(/^\d+\/\d+/));
1054
- decimal = lexeme(regex(/^\d+\.\d+/));
1055
- percent = lexeme(regex(/^\d+%/));
1056
- integer = lexeme(regex(/^\d+/));
1057
+ str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'")));
1058
+ fraction = tag('a fraction', lexeme(regex(/^\d+\/\d+/)));
1059
+ decimal = tag('a decimal', lexeme(regex(/^\d+\.\d+/)));
1060
+ percent = tag('a percentage', lexeme(regex(/^\d+%/)));
1061
+ integer = tag('a number', lexeme(regex(/^\d+/)));
1057
1062
  label = lexeme(identifier.skip(string(':')));
1058
1063
  labelVal = lexeme(regex(/^[^\n]*/));
1059
1064
  variable = lexeme(string('%').then(identifier));
@@ -1086,25 +1091,25 @@ parse = Gibbon.parse = (function() {
1086
1091
  });
1087
1092
  numericExpr = percentExpr.or(decimalExpr.or(fractionExpr.or(integerExpr)));
1088
1093
  parenFlow = lparen.then(function() {
1089
- return flow.expected().skip(rparen.expected());
1094
+ return flow.skip(rparen);
1090
1095
  });
1091
1096
  substExpr = parenFlow.map(function(fl) {
1092
1097
  return AST.subst(fl);
1093
1098
  });
1094
1099
  listExpr = lbrack.then(function() {
1095
- return flow.skip(comma).many().then(function(els) {
1096
- return flow.or(succeed(null)).then(function(final) {
1097
- if (final) {
1098
- els.push(final);
1099
- }
1100
- return rbrack.expected().result(AST.list(els));
1101
- });
1100
+ return commaSepFlows.then(function(els) {
1101
+ return rbrack.result(AST.list(els, false));
1102
+ });
1103
+ });
1104
+ squishListExpr = lsplat.then(function() {
1105
+ return commaSepFlows.then(function(els) {
1106
+ return rsplat.result(AST.list(els, true));
1102
1107
  });
1103
1108
  });
1104
1109
  blockExpr = lbrace.then(function() {
1105
- return flow.skip(rbrace.expected());
1110
+ return flow.skip(rbrace);
1106
1111
  }).map(AST.block);
1107
- expr = queryExpr.or(accessorExpr.or(substExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))));
1112
+ expr = tag('an expr', queryExpr.or(accessorExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))))));
1108
1113
  singletonFlow = expr.map(function(e) {
1109
1114
  return AST.flow(e, null);
1110
1115
  });
@@ -1113,7 +1118,7 @@ parse = Gibbon.parse = (function() {
1113
1118
  return AST.func(funcName, args);
1114
1119
  });
1115
1120
  });
1116
- component = expr.or(func);
1121
+ component = multiline(expr.or(func));
1117
1122
  nonPairedFlow = component.then(function(first) {
1118
1123
  return arrow.then(component).many().map(function(rest) {
1119
1124
  var comp, cursor, _i, _len;
@@ -1125,34 +1130,47 @@ parse = Gibbon.parse = (function() {
1125
1130
  return cursor;
1126
1131
  });
1127
1132
  });
1128
- flow = nonPairedFlow.then(function(first) {
1129
- return pair.then(flow).map(function(second) {
1133
+ nonDefaultedFlow = nonPairedFlow.then(function(first) {
1134
+ return pair.then(nonDefaultedFlow).map(function(second) {
1130
1135
  return AST.flow(AST.pair(first, second), null);
1131
1136
  }).or(succeed(first));
1132
1137
  });
1138
+ flow = tag('a flow', nonDefaultedFlow.then(function(body) {
1139
+ return defaulted.then(flow).map(function(alternative) {
1140
+ return AST.flow(AST.defaulted(body, alternative), null);
1141
+ }).or(succeed(body));
1142
+ }));
1143
+ commaSepFlows = flow.skip(comma.or(succeed(null)).then(lines)).many().then(function(els) {
1144
+ return flow.or(succeed(null)).map(function(final) {
1145
+ if (final) {
1146
+ els.push(final);
1147
+ }
1148
+ return els;
1149
+ });
1150
+ });
1133
1151
  metadata = label.then(function(key) {
1134
1152
  return labelVal.map(function(text) {
1135
1153
  return AST.metadata(key, text);
1136
1154
  });
1137
1155
  });
1138
- definition = metadata.many().then(function(md) {
1156
+ definition = tag('a definition', metadata.many().then(function(md) {
1139
1157
  return name.then(function(n) {
1140
- return define.then(innerFrame.expected()).map(function(fl) {
1158
+ return define.then(innerFrame).map(function(fl) {
1141
1159
  return AST.definition(md, n, fl);
1142
1160
  });
1143
1161
  });
1144
- });
1162
+ }));
1145
1163
  frame = definition.many().then(function(defs) {
1146
- return flow.expected().map(function(fl) {
1164
+ return flow.map(function(fl) {
1147
1165
  return AST.frame(defs, fl);
1148
1166
  });
1149
1167
  });
1150
- parenFrame = lparen.then(frame).skip(rparen.expected());
1168
+ parenFrame = lparen.then(frame).skip(rparen.then(lines));
1151
1169
  freeFrame = flow.map(function(fl) {
1152
1170
  return AST.frame([], fl);
1153
1171
  });
1154
1172
  innerFrame = parenFrame.or(freeFrame);
1155
- program = ignore.then(frame);
1173
+ program = lines.then(frame);
1156
1174
  tassign = lexeme(string('='));
1157
1175
  bang = lexeme(string('!'));
1158
1176
  nativeId = lexeme(regex(/^\w+/));
@@ -1164,27 +1182,27 @@ parse = Gibbon.parse = (function() {
1164
1182
  });
1165
1183
  wildType = wildcard.result(TypeAST.wildcard());
1166
1184
  listType = lbrack.then(function() {
1167
- return type.skip(rbrack.expected()).map(function(t) {
1185
+ return type.skip(rbrack).map(function(t) {
1168
1186
  return TypeAST.list(t);
1169
1187
  });
1170
1188
  });
1171
1189
  parenType = lparen.then(function() {
1172
- return type.skip(rparen.expected());
1190
+ return type.skip(rparen);
1173
1191
  });
1174
1192
  blockType = lbrace.then(function() {
1175
- return arrowType.skip(rbrace.expected()).map(function(t) {
1193
+ return arrowType.skip(rbrace).map(function(t) {
1176
1194
  return TypeAST.block(t);
1177
1195
  });
1178
1196
  });
1179
1197
  nativeType = bang.then(nativeId).map(TypeAST["native"]);
1180
- simpleType = (typeVar.or(wildType.or(listType.or(parenType.or(blockType.or(concrete.or(nativeType))))))).named('a simple type');
1198
+ simpleType = typeVar.or(wildType.or(listType.or(parenType.or(blockType.or(concrete.or(nativeType))))));
1181
1199
  type = simpleType.then(function(first) {
1182
- return pair.then(type.expected()).map(function(second) {
1200
+ return pair.then(type).map(function(second) {
1183
1201
  return TypeAST.pair(first, second);
1184
1202
  }).or(succeed(first));
1185
1203
  });
1186
1204
  arrowType = type.then(function(first) {
1187
- return arrow.then(type.expected()).map(function(second) {
1205
+ return arrow.then(type).map(function(second) {
1188
1206
  return TypeAST.arrow(first, second);
1189
1207
  });
1190
1208
  });
@@ -1195,7 +1213,7 @@ parse = Gibbon.parse = (function() {
1195
1213
  });
1196
1214
  });
1197
1215
  });
1198
- fullSignature = ignore.then(signature);
1216
+ fullSignature = lines.then(signature);
1199
1217
  isString = function(s) {
1200
1218
  return typeof s === 'string' || s instanceof String;
1201
1219
  };
@@ -1239,10 +1257,11 @@ Gibbon.Semantic = Semantic = (function(_super) {
1239
1257
  localAccessor: ['name'],
1240
1258
  pair: ['first', 'second'],
1241
1259
  block: ['body'],
1242
- list: ['elements'],
1260
+ list: ['elements', 'squish'],
1243
1261
  flow: ['type', 'head', 'tail'],
1244
1262
  func: ['name', 'args'],
1245
- subst: ['flow']
1263
+ subst: ['flow'],
1264
+ defaulted: ['body', 'alternative']
1246
1265
  });
1247
1266
 
1248
1267
  return Semantic;
@@ -1725,6 +1744,12 @@ analyze = Gibbon.analyze = (function() {
1725
1744
  input = TypeExpr.variable('.input');
1726
1745
  push(TypeExpr.expr(flow), TypeExpr.param('block', [input, TypeExpr.expr(subFlow)]));
1727
1746
  return _this.analyzeFlow(subFlow, input, push);
1747
+ },
1748
+ defaulted: function(body, alt) {
1749
+ push(TypeExpr.expr(body), TypeExpr.expr(alt));
1750
+ push(TypeExpr.expr(flow), TypeExpr.expr(alt));
1751
+ _this.analyzeFlow(body, global, push);
1752
+ return _this.analyzeFlow(alt, global, push);
1728
1753
  }
1729
1754
  });
1730
1755
  };
@@ -1950,7 +1975,7 @@ analyze = Gibbon.analyze = (function() {
1950
1975
  block: function(flow) {
1951
1976
  return Semantic.block(toSemanticTree(flow));
1952
1977
  },
1953
- list: function(elements) {
1978
+ list: function(elements, squish) {
1954
1979
  var e;
1955
1980
  return Semantic.list((function() {
1956
1981
  var _i, _len, _results;
@@ -1960,7 +1985,10 @@ analyze = Gibbon.analyze = (function() {
1960
1985
  _results.push(toSemanticTree(e));
1961
1986
  }
1962
1987
  return _results;
1963
- })());
1988
+ })(), squish);
1989
+ },
1990
+ defaulted: function(body, alt) {
1991
+ return Semantic.defaulted(toSemanticTree(body), toSemanticTree(alt));
1964
1992
  },
1965
1993
  integer: function() {
1966
1994
  return Semantic.literal(this);
@@ -2122,7 +2150,7 @@ analyze = Gibbon.analyze = (function() {
2122
2150
  };
2123
2151
  })();
2124
2152
  // Generated by CoffeeScript 1.6.3
2125
- var Dependency, Promise, Value, eval_, _ref, _ref1,
2153
+ var Dependency, Failure, Promise, Value, eval_, _ref, _ref1, _ref2,
2126
2154
  __hasProp = {}.hasOwnProperty,
2127
2155
  __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; },
2128
2156
  __slice = [].slice;
@@ -2365,6 +2393,23 @@ Promise = (function() {
2365
2393
  });
2366
2394
  };
2367
2395
 
2396
+ Promise.prototype.rescue = function(fn) {
2397
+ var _this = this;
2398
+ return new Promise(function(fail, cb) {
2399
+ var rescue;
2400
+ rescue = function(failure) {
2401
+ return fn(failure).depends([Dependency.failure(failure)]).force(fail, cb);
2402
+ };
2403
+ return _this.force(rescue, cb);
2404
+ });
2405
+ };
2406
+
2407
+ Promise.prototype.or = function(other) {
2408
+ return this.rescue(function(_) {
2409
+ return other;
2410
+ });
2411
+ };
2412
+
2368
2413
  Promise.prototype.depends = function(deps) {
2369
2414
  var _this = this;
2370
2415
  return new Promise(function(fail, cc) {
@@ -2469,21 +2514,65 @@ Promise = (function() {
2469
2514
 
2470
2515
  })();
2471
2516
 
2472
- Dependency = (function(_super) {
2517
+ Gibbon.Failure = Failure = (function(_super) {
2518
+ __extends(Failure, _super);
2519
+
2520
+ function Failure() {
2521
+ _ref1 = Failure.__super__.constructor.apply(this, arguments);
2522
+ return _ref1;
2523
+ }
2524
+
2525
+ Failure.types({
2526
+ query: ['id', 'annotations'],
2527
+ composite: ['failures']
2528
+ });
2529
+
2530
+ Failure.prototype.equals = function(other) {
2531
+ if (this._tag !== other._tag) {
2532
+ return false;
2533
+ }
2534
+ return this.cases({
2535
+ query: function(id, annotations) {
2536
+ if (annotations !== other.annotations) {
2537
+ return false;
2538
+ }
2539
+ if (id !== other.id) {
2540
+ return false;
2541
+ }
2542
+ },
2543
+ composite: function(failures) {
2544
+ var failure, i, _i, _len;
2545
+ for (i = _i = 0, _len = failures.length; _i < _len; i = ++_i) {
2546
+ failure = failures[i];
2547
+ if (!failure.equals(other.failures[i])) {
2548
+ return false;
2549
+ }
2550
+ }
2551
+ return true;
2552
+ }
2553
+ });
2554
+ };
2555
+
2556
+ return Failure;
2557
+
2558
+ })(Union);
2559
+
2560
+ Gibbon.Dependency = Dependency = (function(_super) {
2473
2561
  __extends(Dependency, _super);
2474
2562
 
2475
2563
  function Dependency() {
2476
- _ref1 = Dependency.__super__.constructor.apply(this, arguments);
2477
- return _ref1;
2564
+ _ref2 = Dependency.__super__.constructor.apply(this, arguments);
2565
+ return _ref2;
2478
2566
  }
2479
2567
 
2480
2568
  Dependency.types({
2481
2569
  query: ['entity', 'query'],
2482
- lexical: ['key']
2570
+ lexical: ['key'],
2571
+ failure: ['failure']
2483
2572
  });
2484
2573
 
2485
2574
  Dependency.prototype.equals = function(other) {
2486
- if (this.tag !== other.tag) {
2575
+ if (this._tag !== other._tag) {
2487
2576
  return false;
2488
2577
  }
2489
2578
  return this.cases({
@@ -2498,6 +2587,9 @@ Dependency = (function(_super) {
2498
2587
  },
2499
2588
  lexical: function(key) {
2500
2589
  return key === other.key;
2590
+ },
2591
+ failure: function(failure) {
2592
+ return failure.equals(other.failure);
2501
2593
  }
2502
2594
  });
2503
2595
  };
@@ -2509,6 +2601,9 @@ Dependency = (function(_super) {
2509
2601
  },
2510
2602
  lexical: function(definition) {
2511
2603
  return "@" + definition.name;
2604
+ },
2605
+ failure: function(failure) {
2606
+ return "!";
2512
2607
  }
2513
2608
  });
2514
2609
  };
@@ -2595,9 +2690,9 @@ eval_ = Gibbon["eval"] = (function() {
2595
2690
  eSecond = evalFlow(second, global);
2596
2691
  return Promise.unit(Value.pair(eFirst, eSecond));
2597
2692
  },
2598
- list: function(elements) {
2599
- var e;
2600
- elements = (function() {
2693
+ list: function(elements, squished) {
2694
+ var e, list;
2695
+ list = Promise.unit(Value.list((function() {
2601
2696
  var _i, _len, _results;
2602
2697
  _results = [];
2603
2698
  for (_i = 0, _len = elements.length; _i < _len; _i++) {
@@ -2605,13 +2700,20 @@ eval_ = Gibbon["eval"] = (function() {
2605
2700
  _results.push(evalFlow(e, global));
2606
2701
  }
2607
2702
  return _results;
2608
- })();
2609
- return Promise.unit(Value.list(elements));
2703
+ })()));
2704
+ if (squished) {
2705
+ return stdlib.squish.impl(list);
2706
+ } else {
2707
+ return list;
2708
+ }
2610
2709
  },
2611
2710
  block: function(body) {
2612
2711
  return Promise.unit(Value.block(function(inputPromise) {
2613
2712
  return evalFlow(body, inputPromise);
2614
2713
  }));
2714
+ },
2715
+ defaulted: function(body, alt) {
2716
+ return evalFlow(body, global).or(evalFlow(alt, global));
2615
2717
  }
2616
2718
  });
2617
2719
  };
@@ -2620,10 +2722,10 @@ eval_ = Gibbon["eval"] = (function() {
2620
2722
  });
2621
2723
  };
2622
2724
  return function(semantics, table, id, client, finish) {
2623
- var entity, key, onFailure, onSuccess, _i, _len, _ref2;
2624
- _ref2 = semantics.keys();
2625
- for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
2626
- key = _ref2[_i];
2725
+ var entity, key, onFailure, onSuccess, _i, _len, _ref3;
2726
+ _ref3 = semantics.keys();
2727
+ for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
2728
+ key = _ref3[_i];
2627
2729
  semantics.modify(key, function(val) {
2628
2730
  if (val instanceof Semantic) {
2629
2731
  return val;
@@ -2645,12 +2747,40 @@ eval_ = Gibbon["eval"] = (function() {
2645
2747
  var stdlib;
2646
2748
 
2647
2749
  stdlib = Gibbon.stdlib = (function() {
2648
- var combine, iter, unit, vFalse, vTrue;
2750
+ var allBooleans, anyBooleans, combine, iter, unit, vFalse, vTrue;
2649
2751
  unit = Promise.unit;
2650
2752
  iter = Promise.iter;
2651
2753
  combine = Promise.combine;
2652
2754
  vTrue = Value.boolean(true);
2653
2755
  vFalse = Value.boolean(false);
2756
+ anyBooleans = function(promises) {
2757
+ var out, step;
2758
+ step = function(cond, next) {
2759
+ if (cond.value) {
2760
+ return unit(vTrue);
2761
+ } else {
2762
+ return next();
2763
+ }
2764
+ };
2765
+ out = function() {
2766
+ return unit(vFalse);
2767
+ };
2768
+ return iter(promises, step, out);
2769
+ };
2770
+ allBooleans = function(promises) {
2771
+ var out, step;
2772
+ step = function(cond, next) {
2773
+ if (cond.value) {
2774
+ return next();
2775
+ } else {
2776
+ return unit(vFalse);
2777
+ }
2778
+ };
2779
+ out = function() {
2780
+ return unit(vTrue);
2781
+ };
2782
+ return iter(promises, step, out);
2783
+ };
2654
2784
  return {
2655
2785
  "case": {
2656
2786
  type: parse.type('case [bool : %b] = % -> %b'),
@@ -2667,20 +2797,67 @@ stdlib = Gibbon.stdlib = (function() {
2667
2797
  });
2668
2798
  };
2669
2799
  out = function() {
2670
- throw new Error('Runtime Error: non-exhaustive cases');
2800
+ return Promise.fail('non-exhaustive cases');
2671
2801
  };
2672
2802
  return iter(list.elements, step, out);
2673
2803
  });
2674
2804
  }
2675
2805
  },
2806
+ "case-eq": {
2807
+ type: parse.type('case-eq [%a : %b] = %a -> %b'),
2808
+ impl: function(evalInput, evalList) {
2809
+ debugger;
2810
+ return combine([evalInput, evalList]).then(function(_arg) {
2811
+ var input, list, out, step;
2812
+ input = _arg[0], list = _arg[1];
2813
+ step = function(pair, next) {
2814
+ return pair.first.then(function(test) {
2815
+ return input.equals(test).then(function(vBool) {
2816
+ if (vBool.value) {
2817
+ return pair.second;
2818
+ } else {
2819
+ return next();
2820
+ }
2821
+ });
2822
+ });
2823
+ };
2824
+ out = function() {
2825
+ return Promise.fail('non-exhaustive cases');
2826
+ };
2827
+ return iter(list.elements, step, out);
2828
+ });
2829
+ }
2830
+ },
2831
+ "case-eq-default": {
2832
+ type: parse.type('case-eq-default %b [%a : %b] = %a -> %b'),
2833
+ impl: function(evalInput, evalDefault, evalList) {
2834
+ return stdlib['case-eq'].impl(evalInput, evalList).or(evalDefault);
2835
+ }
2836
+ },
2837
+ "any-true?": {
2838
+ type: parse.type('any-true? = [bool] -> bool'),
2839
+ impl: function(evalList) {
2840
+ return evalList.then(function(list) {
2841
+ return anyBooleans(list.elements);
2842
+ });
2843
+ }
2844
+ },
2845
+ "all-true?": {
2846
+ type: parse.type('all-true? = [bool] -> bool'),
2847
+ impl: function(evalList) {
2848
+ return evalList.then(function(list) {
2849
+ return allBooleans(list.elements);
2850
+ });
2851
+ }
2852
+ },
2676
2853
  "any?": {
2677
2854
  type: parse.type('any? { %a -> bool } = [%a] -> bool'),
2678
2855
  impl: function(evalList, evalBlock) {
2679
2856
  return combine([evalList, evalBlock]).then(function(_arg) {
2680
- var block, booleans, e, fn, list, out, step;
2857
+ var block, e, fn, list;
2681
2858
  list = _arg[0], block = _arg[1];
2682
2859
  fn = block.fn;
2683
- booleans = (function() {
2860
+ return anyBooleans((function() {
2684
2861
  var _i, _len, _ref, _results;
2685
2862
  _ref = list.elements;
2686
2863
  _results = [];
@@ -2689,18 +2866,7 @@ stdlib = Gibbon.stdlib = (function() {
2689
2866
  _results.push(fn(e));
2690
2867
  }
2691
2868
  return _results;
2692
- })();
2693
- step = function(cond, next) {
2694
- if (cond.value) {
2695
- return unit(vTrue);
2696
- } else {
2697
- return next();
2698
- }
2699
- };
2700
- out = function() {
2701
- return unit(vFalse);
2702
- };
2703
- return iter(booleans, step, out);
2869
+ })());
2704
2870
  });
2705
2871
  }
2706
2872
  },
@@ -2708,10 +2874,10 @@ stdlib = Gibbon.stdlib = (function() {
2708
2874
  type: parse.type('all? { %a -> bool } = [%a] -> bool'),
2709
2875
  impl: function(evalList, evalBlock) {
2710
2876
  return combine([evalList, evalBlock]).then(function(_arg) {
2711
- var block, booleans, e, fn, list, out, step;
2877
+ var block, e, fn, list;
2712
2878
  list = _arg[0], block = _arg[1];
2713
2879
  fn = block.fn;
2714
- booleans = (function() {
2880
+ return allBooleans((function() {
2715
2881
  var _i, _len, _ref, _results;
2716
2882
  _ref = list.elements;
2717
2883
  _results = [];
@@ -2720,18 +2886,30 @@ stdlib = Gibbon.stdlib = (function() {
2720
2886
  _results.push(fn(e));
2721
2887
  }
2722
2888
  return _results;
2723
- })();
2724
- step = function(cond, next) {
2725
- if (cond.value) {
2726
- return next();
2727
- } else {
2728
- return unit(vFalse);
2889
+ })());
2890
+ });
2891
+ }
2892
+ },
2893
+ "include?": {
2894
+ type: parse.type('include? %a = [%a] -> bool'),
2895
+ impl: function(evalList, evalElement) {
2896
+ debugger;
2897
+ return combine([evalElement, evalList]).then(function(_arg) {
2898
+ var booleans, el, list, p;
2899
+ el = _arg[0], list = _arg[1];
2900
+ booleans = (function() {
2901
+ var _i, _len, _ref, _results;
2902
+ _ref = list.elements;
2903
+ _results = [];
2904
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2905
+ p = _ref[_i];
2906
+ _results.push(p.then(function(x) {
2907
+ return el.equals(x);
2908
+ }));
2729
2909
  }
2730
- };
2731
- out = function() {
2732
- return trueP;
2733
- };
2734
- return Promise.iter(booleans, step, out);
2910
+ return _results;
2911
+ })();
2912
+ return anyBooleans(booleans);
2735
2913
  });
2736
2914
  }
2737
2915
  },
@@ -2771,8 +2949,7 @@ stdlib = Gibbon.stdlib = (function() {
2771
2949
  if (denominator === 0) {
2772
2950
  return Promise.fail('cannot divide by zero');
2773
2951
  }
2774
- debugger;
2775
- return Promise.unit(Value.number(numerator / denominator));
2952
+ return unit(Value.number(numerator / denominator));
2776
2953
  });
2777
2954
  });
2778
2955
  });
@@ -2875,7 +3052,42 @@ stdlib = Gibbon.stdlib = (function() {
2875
3052
  e = vals[_i];
2876
3053
  out += e.value;
2877
3054
  }
2878
- return Promise.unit(Value.number(out));
3055
+ return unit(Value.number(out));
3056
+ });
3057
+ });
3058
+ }
3059
+ },
3060
+ "case-sum": {
3061
+ type: parse.type('case-sum [bool : numeric] = % -> numeric'),
3062
+ impl: function(_, evalList) {
3063
+ return evalList.then(function(list) {
3064
+ return combine(list.elements).then(function(elements) {
3065
+ var el, numbers;
3066
+ numbers = (function() {
3067
+ var _i, _len, _results;
3068
+ _results = [];
3069
+ for (_i = 0, _len = elements.length; _i < _len; _i++) {
3070
+ el = elements[_i];
3071
+ _results.push(el.first.then(function(cond) {
3072
+ if (!cond.value) {
3073
+ return unit(0);
3074
+ }
3075
+ return el.second.map(function(v) {
3076
+ return v.value;
3077
+ });
3078
+ }));
3079
+ }
3080
+ return _results;
3081
+ })();
3082
+ return combine(numbers).then(function(nums) {
3083
+ var num, out, _i, _len;
3084
+ out = 0;
3085
+ for (_i = 0, _len = nums.length; _i < _len; _i++) {
3086
+ num = nums[_i];
3087
+ out += num;
3088
+ }
3089
+ return unit(Value.number(out));
3090
+ });
2879
3091
  });
2880
3092
  });
2881
3093
  }
@@ -2888,6 +3100,39 @@ stdlib = Gibbon.stdlib = (function() {
2888
3100
  });
2889
3101
  }
2890
3102
  },
3103
+ squish: {
3104
+ type: parse.type('squish = [%a] -> [%a]'),
3105
+ impl: function(list) {
3106
+ return list.then(function(_arg) {
3107
+ var elements, promise, wrapped;
3108
+ elements = _arg.elements;
3109
+ wrapped = (function() {
3110
+ var _i, _len, _results;
3111
+ _results = [];
3112
+ for (_i = 0, _len = elements.length; _i < _len; _i++) {
3113
+ promise = elements[_i];
3114
+ _results.push(promise.map(function(e) {
3115
+ return [e];
3116
+ }).or(unit([])));
3117
+ }
3118
+ return _results;
3119
+ })();
3120
+ return combine(wrapped).map(function(lists) {
3121
+ var e;
3122
+ return Value.list((function() {
3123
+ var _i, _len, _ref, _results;
3124
+ _ref = catLists(lists);
3125
+ _results = [];
3126
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3127
+ e = _ref[_i];
3128
+ _results.push(unit(e));
3129
+ }
3130
+ return _results;
3131
+ })());
3132
+ });
3133
+ });
3134
+ }
3135
+ },
2891
3136
  add: {
2892
3137
  type: parse.type('add numeric = numeric -> numeric'),
2893
3138
  impl: function(input, num) {
@@ -2920,6 +3165,14 @@ stdlib = Gibbon.stdlib = (function() {
2920
3165
  return unit(vTrue);
2921
3166
  }
2922
3167
  },
3168
+ not: {
3169
+ type: parse.type('not = bool -> bool'),
3170
+ impl: function(evalBool) {
3171
+ return evalBool.map(function(bool) {
3172
+ return Value.boolean(!bool.value);
3173
+ });
3174
+ }
3175
+ },
2923
3176
  gt: {
2924
3177
  type: parse.type('gt numeric = numeric -> bool'),
2925
3178
  impl: function(input, num) {
@@ -2976,15 +3229,15 @@ Gibbon.jsonConsumer = (function() {
2976
3229
  getValue = function(id, annotations, v, callback) {
2977
3230
  var entity, values;
2978
3231
  if (!tables.hasOwnProperty(annotations.table)) {
2979
- return callback(new Error("no such type " + annotations.table));
3232
+ throw new Error("no such type " + annotations.table);
2980
3233
  }
2981
3234
  values = tables[annotations.table].values;
2982
3235
  if (!values[id]) {
2983
- return callback(new Error("no entity with id " + id));
3236
+ return callback(Failure.query(id, annotations));
2984
3237
  }
2985
3238
  entity = values[id];
2986
- if (!entity.hasOwnProperty(annotations.name)) {
2987
- return callback(null, null);
3239
+ if (!(entity.hasOwnProperty(annotations.name) && (entity[annotations.name] != null))) {
3240
+ return callback(Failure.query(id, annotations));
2988
3241
  }
2989
3242
  return callback(null, v.fromJSON(entity[annotations.name]));
2990
3243
  };