goodguide-gibbon 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c61efe121d23db7a49c70a68f0a043a48dd8cc22
4
- data.tar.gz: 0ba5e9f089eef69f035a5890086b3584c5199212
3
+ metadata.gz: 831fea2094e21661113b50208c2e16291c8652d8
4
+ data.tar.gz: 328f433998f64337ffafaa1a544ad6d5e0328048
5
5
  SHA512:
6
- metadata.gz: 9808a033ec1fcdc705e4ddfd96b476d4537de9bcca07f0198df3d947da1fa741cc7e862c3d1a16ff7f1289acd486a2e3eb5c44c14ad13a3c8543790a60a17772
7
- data.tar.gz: 2bb8a4a01ff84e2b29fbcb97bece26eed9ad56fb767aa0d59606b2d69ebe1be83ab3eaf4c4d1cb757f18dc1556b47ebd16af621712780c2894bb6f3beaa0681a
6
+ metadata.gz: 96890a4afd8ecc4eaffae303202959bfd78332b7a655bf9bd90a39afb54a8f494d42877698f6d24bf2c9fcfa96eca002d29564b9582f1af37ba862d805817660
7
+ data.tar.gz: 311a066787d1b17e512cc54b7048e61afcf9017dff422aa4f0f94e09a7014ed143faaf954a649e499f1a0fe60fa948a1aadc578d8cebbfd7cf30bebec926060b
@@ -1,7 +1,7 @@
1
1
  module GoodGuide
2
2
  module Gibbon
3
3
  def self.version
4
- '0.8.3'
4
+ '0.9.0'
5
5
  end
6
6
  end
7
7
  end
@@ -330,7 +330,7 @@ module GoodGuide
330
330
  @last_annotations = annotations
331
331
  @last_id = id
332
332
 
333
- query = get_query(query_type) or raise "invalid query type in compiled code: #{query_type.inspect}"
333
+ query = get_query(query_type) or raise "invalid query type in compiled code: #{query_type.inspect} with annotations #{annotations.inspect}"
334
334
  instance_exec(id, annotations, &query)
335
335
  end
336
336
 
@@ -1,14 +1,6 @@
1
1
  var Gibbon = (function(undefined) {
2
2
  var Parsimmon = (function(undefined) {
3
3
  var P = (function(prototype, ownProperty, undefined) {
4
- // helper functions that also help minification
5
- function isObject(o) { return typeof o === 'object'; }
6
- function isFunction(f) { return typeof f === 'function'; }
7
-
8
- // used to extend the prototypes of superclasses (which might not
9
- // have `.Bare`s)
10
- function SuperclassBare() {}
11
-
12
4
  return function P(_superclass /* = Object */, definition) {
13
5
  // handle the case where no superclass is given
14
6
  if (definition === undefined) {
@@ -18,69 +10,60 @@ var P = (function(prototype, ownProperty, undefined) {
18
10
 
19
11
  // C is the class to be returned.
20
12
  //
21
- // It delegates to instantiating an instance of `Bare`, so that it
22
- // will always return a new instance regardless of the calling
23
- // context.
13
+ // When called, creates and initializes an instance of C, unless
14
+ // `this` is already an instance of C, then just initializes `this`;
15
+ // either way, returns the instance of C that was initialized.
24
16
  //
25
17
  // TODO: the Chrome inspector shows all created objects as `C`
26
18
  // rather than `Object`. Setting the .name property seems to
27
19
  // have no effect. Is there a way to override this behavior?
28
20
  function C() {
29
- var self = new Bare;
30
- if (isFunction(self.init)) self.init.apply(self, arguments);
21
+ var self = this instanceof C ? this : new Bare;
22
+ self.init.apply(self, arguments);
31
23
  return self;
32
24
  }
33
25
 
34
- // C.Bare is a class with a noop constructor. Its prototype is the
35
- // same as C, so that instances of C.Bare are also instances of C.
36
- // New objects can be allocated without initialization by calling
37
- // `new MyClass.Bare`.
26
+ // C.Bare is a class with a noop constructor. Its prototype will be
27
+ // the same as C, so that instances of C.Bare are instances of C.
28
+ // `new MyClass.Bare` then creates new instances of C without
29
+ // calling .init().
38
30
  function Bare() {}
39
31
  C.Bare = Bare;
40
32
 
41
- // Set up the prototype of the new class.
42
- var _super = SuperclassBare[prototype] = _superclass[prototype];
43
- var proto = Bare[prototype] = C[prototype] = C.p = new SuperclassBare;
44
-
45
- // other variables, as a minifier optimization
46
- var extensions;
33
+ // Extend the prototype chain: first use Bare to create an
34
+ // uninitialized instance of the superclass, then set up Bare
35
+ // to create instances of this class.
36
+ var _super = Bare[prototype] = _superclass[prototype];
37
+ var proto = Bare[prototype] = C[prototype] = C.p = new Bare;
47
38
 
39
+ // pre-declaring the iteration variable for the loop below to save
40
+ // a `var` keyword after minification
41
+ var key;
48
42
 
49
43
  // set the constructor property on the prototype, for convenience
50
44
  proto.constructor = C;
51
45
 
52
- C.mixin = function(def) {
53
- Bare[prototype] = C[prototype] = P(C, def)[prototype];
54
- return C;
55
- }
46
+ C.extend = function(def) { return P(C, def); }
56
47
 
57
48
  return (C.open = function(def) {
58
- extensions = {};
59
-
60
- if (isFunction(def)) {
49
+ if (typeof def === 'function') {
61
50
  // call the defining function with all the arguments you need
62
51
  // extensions captures the return value.
63
- extensions = def.call(C, proto, _super, C, _superclass);
64
- }
65
- else if (isObject(def)) {
66
- // if you passed an object instead, we'll take it
67
- extensions = def;
52
+ def = def.call(C, proto, _super, C, _superclass);
68
53
  }
69
54
 
70
55
  // ...and extend it
71
- if (isObject(extensions)) {
72
- for (var ext in extensions) {
73
- if (ownProperty.call(extensions, ext)) {
74
- proto[ext] = extensions[ext];
56
+ if (typeof def === 'object') {
57
+ for (key in def) {
58
+ if (ownProperty.call(def, key)) {
59
+ proto[key] = def[key];
75
60
  }
76
61
  }
77
62
  }
78
63
 
79
- // if there's no init, we assume we're inheriting a non-pjs class, so
80
- // we default to applying the superclass's constructor.
81
- if (!isFunction(proto.init)) {
82
- proto.init = _superclass;
83
- }
64
+ // if no init, assume we're inheriting from a non-Pjs class, so
65
+ // default to using the superclass constructor.
66
+ if (!('init' in proto)) proto.init = _superclass;
84
67
 
85
68
  return C;
86
69
  })(definition);
@@ -159,13 +142,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
159
142
 
160
143
  // -*- primitive combinators -*- //
161
144
  _.or = function(alternative) {
162
- var self = this;
163
-
164
- return Parser(function(stream, i) {
165
- var result = self._(stream, i);
166
-
167
- return result.status ? result : furthestBacktrackFor(alternative._(stream, i), result);
168
- });
145
+ return alt([this, alternative]);
169
146
  };
170
147
 
171
148
  _.then = function(next) {
@@ -259,7 +236,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
259
236
  }
260
237
  }
261
238
 
262
- for (; times < max && result; times += 1) {
239
+ for (; times < max; times += 1) {
263
240
  result = self._(stream, i);
264
241
  prevResult = furthestBacktrackFor(result, prevResult);
265
242
  if (result.status) {
@@ -394,7 +371,18 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
394
371
 
395
372
  return furthestBacktrackFor(makeSuccess(i, accum), result);
396
373
  });
397
- }
374
+ };
375
+
376
+ var alt = Parsimmon.alt = function(parsers) {
377
+ return Parser(function(stream, i) {
378
+ var result;
379
+ for (var j = 0; j < parsers.length; j += 1) {
380
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
381
+ if (result.status) return result;
382
+ }
383
+ return result;
384
+ });
385
+ };
398
386
 
399
387
  var index = Parsimmon.index = Parser(function(stream, i) {
400
388
  return makeSuccess(i, i);
@@ -402,8 +390,9 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
402
390
 
403
391
  //- fantasyland compat
404
392
 
405
- //- Semigroup
406
- _.concat = _.then;
393
+ //- Monoid (Alternative, really)
394
+ _.concat = _.or;
395
+ _.empty = fail('empty')
407
396
 
408
397
  //- Applicative
409
398
  _.of = Parser.of = Parsimmon.of = succeed
@@ -993,6 +982,7 @@ Gibbon.AST = AST = (function(_super) {
993
982
  list: ['loc', 'elements', 'squish'],
994
983
  defaulted: ['loc', 'body', 'alternative'],
995
984
  query: ['loc', 'type', 'args'],
985
+ lexical: ['loc', 'name', 'args'],
996
986
  func: ['loc', 'name', 'args'],
997
987
  pair: ['loc', 'first', 'second'],
998
988
  flow: ['loc', 'head', 'tail'],
@@ -1034,10 +1024,15 @@ Gibbon.AST = AST = (function(_super) {
1034
1024
  query: function(_, query, args) {
1035
1025
  if (query === 'access') {
1036
1026
  return "@" + args[0];
1027
+ } else if (args.length) {
1028
+ return "@:" + query + "[" + (args.join(' ')) + "]";
1037
1029
  } else {
1038
- return "." + query + " " + (args.join(' '));
1030
+ return "@:" + query;
1039
1031
  }
1040
1032
  },
1033
+ lexical: function(_, name, args) {
1034
+ return "." + name;
1035
+ },
1041
1036
  subst: function(_, flow) {
1042
1037
  return "(" + (flow.inspect()) + ")";
1043
1038
  },
@@ -1148,7 +1143,7 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
1148
1143
  })(Variant);
1149
1144
 
1150
1145
  parse = Gibbon.parse = (function() {
1151
- var accessor, accessorExpr, arrow, arrowType, assertString, 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, lazy, lbrace, lbrack, lexeme, lines, listExpr, listType, lparen, lsplat, metadata, multiline, name, nonDefaultedFlow, nonPairedFlow, numericExpr, opt, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, queryArg, queryExpr, rbrace, rbrack, regex, rparen, rsplat, seq, signature, simpleType, singletonFlow, spanLoc, squishListExpr, str, string, stringExpr, substExpr, succeed, tag, tassign, type, typeVar, variable, whitespace, wildType, wildcard, withLoc,
1146
+ var accessor, accessorExpr, arrow, arrowType, assertString, 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, lazy, lbrace, lbrack, lexeme, lexical, lexicalExpr, lines, listExpr, listType, lparen, lsplat, metadata, multiline, name, nonDefaultedFlow, nonPairedFlow, numericExpr, opt, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, queryArg, queryExpr, rbrace, rbrack, regex, rparen, rsplat, seq, signature, simpleType, singletonFlow, spanLoc, squishListExpr, str, string, stringExpr, substExpr, succeed, tag, tassign, type, typeVar, variable, whitespace, wildType, wildcard, withLoc,
1152
1147
  _this = this;
1153
1148
  tag = function(name, parser) {
1154
1149
  return Parsimmon.Parser(function(stream, i) {
@@ -1210,9 +1205,10 @@ parse = Gibbon.parse = (function() {
1210
1205
  defaulted = multiline(string('|'));
1211
1206
  lsplat = multiline(string('[*'));
1212
1207
  rsplat = lexeme(string('*]'));
1213
- query = lexeme(string('.').then(identifier));
1208
+ query = lexeme(string('@:').then(identifier));
1214
1209
  queryArg = lexeme(regex(/^\w[\w-]*/));
1215
1210
  accessor = lexeme(string('@').then(identifier));
1211
+ lexical = lexeme(string('.').then(identifier));
1216
1212
  name = lexeme(identifier);
1217
1213
  str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'")));
1218
1214
  fraction = tag('a fraction', lexeme(regex(/^\d+\/\d+/)));
@@ -1244,10 +1240,13 @@ parse = Gibbon.parse = (function() {
1244
1240
  accessorExpr = withLoc(accessor, function(loc, name) {
1245
1241
  return AST.query(loc, 'access', [name]);
1246
1242
  });
1247
- queryExpr = seq([query, queryArg.many()]).map(function(_arg) {
1248
- var a, args, loc, q;
1249
- q = _arg[0], args = _arg[1];
1250
- loc = spanLoc(q, args[args.length - 1] || q);
1243
+ lexicalExpr = withLoc(lexical, function(loc, name) {
1244
+ return AST.lexical(loc, name, []);
1245
+ });
1246
+ queryExpr = seq([query, lbrack, queryArg.many(), rbrack]).map(function(_arg) {
1247
+ var a, args, loc, q, _;
1248
+ q = _arg[0], _ = _arg[1], args = _arg[2];
1249
+ loc = spanLoc(q, rbrack);
1251
1250
  return AST.query(loc, q.value, (function() {
1252
1251
  var _i, _len, _results;
1253
1252
  _results = [];
@@ -1290,7 +1289,7 @@ parse = Gibbon.parse = (function() {
1290
1289
  return AST.block(spanLoc(l, r), flow);
1291
1290
  });
1292
1291
  });
1293
- expr = tag('an expr', queryExpr.or(accessorExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))))));
1292
+ expr = tag('an expr', queryExpr.or(accessorExpr.or(lexicalExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr)))))))));
1294
1293
  singletonFlow = expr.map(function(e) {
1295
1294
  return AST.flow(e.loc, e, null);
1296
1295
  });
@@ -1657,6 +1656,7 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1657
1656
  expr: ['expr'],
1658
1657
  variable: ['name', 'uniq'],
1659
1658
  query: ['input', 'scope', 'query'],
1659
+ lexical: ['syntax', 'scope'],
1660
1660
  destructure: ['constraint', 'name', 'argnum'],
1661
1661
  "native": ['id'],
1662
1662
  param: ['name', 'constraints'],
@@ -1710,6 +1710,9 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1710
1710
  query: function(input, _, query) {
1711
1711
  return "" + (input.inspect()) + "[" + (query.inspect()) + "]";
1712
1712
  },
1713
+ lexical: function(syntax, scope) {
1714
+ return "." + syntax.name + ":" + (scope.key());
1715
+ },
1713
1716
  destructure: function(constraint, name, argnum) {
1714
1717
  return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
1715
1718
  },
@@ -1769,6 +1772,9 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1769
1772
  query: function(input, scope, query) {
1770
1773
  return "" + (query.inspect()) + ":" + scope.uniq + "[" + (recurse(input)) + "]";
1771
1774
  },
1775
+ lexical: function(syntax, scope) {
1776
+ return "." + (syntax.hash()) + ":" + (scope.key());
1777
+ },
1772
1778
  "native": function(id) {
1773
1779
  return "!" + id;
1774
1780
  },
@@ -1975,35 +1981,17 @@ analyze = Gibbon.analyze = (function() {
1975
1981
  };
1976
1982
 
1977
1983
  Scope.prototype.lookup = function(nativeId, query, cb) {
1978
- var lexical;
1979
- if (query.type === 'access' && nativeId === this.context.globalID) {
1980
- lexical = this.lexicalLookup(query.args[0]);
1981
- if (lexical) {
1982
- return cb(lexical);
1983
- } else {
1984
- return this.context.query(nativeId, query, cb);
1985
- }
1986
- } else {
1987
- return this.context.query(nativeId, query, cb);
1988
- }
1984
+ return this.context.query(nativeId, query, cb);
1989
1985
  };
1990
1986
 
1991
1987
  Scope.prototype.lexicalLookup = function(name) {
1992
- var local;
1993
- local = this.lookupLocal(name);
1994
- if (local) {
1995
- return local;
1996
- }
1997
- if (this.parent) {
1998
- return this.parent.lexicalLookup(name);
1999
- }
2000
- };
2001
-
2002
- Scope.prototype.lookupLocal = function(name) {
2003
- if (!this.bindings.has(name)) {
2004
- return null;
1988
+ if (this.bindings.has(name)) {
1989
+ return this.keyFor(name);
1990
+ } else {
1991
+ if (this.parent) {
1992
+ return this.parent.lexicalLookup(name);
1993
+ }
2005
1994
  }
2006
- return TypeLookup.local(this.keyFor(name));
2007
1995
  };
2008
1996
 
2009
1997
  makeKey = function(crumbs) {
@@ -2046,6 +2034,9 @@ analyze = Gibbon.analyze = (function() {
2046
2034
  input = flow.tail ? TypeExpr.expr(flow.tail) : global;
2047
2035
  return push(TypeExpr.expr(flow), TypeExpr.query(input, _this, flow.head));
2048
2036
  },
2037
+ lexical: function(_, name) {
2038
+ return push(TypeExpr.expr(flow), TypeExpr.lexical(flow.head, _this));
2039
+ },
2049
2040
  pair: function(_, first, second) {
2050
2041
  _this.analyzeFlow(first, global, push);
2051
2042
  _this.analyzeFlow(second, global, push);
@@ -2152,6 +2143,7 @@ analyze = Gibbon.analyze = (function() {
2152
2143
  match: ['lhs', 'rhs'],
2153
2144
  destructure: ['type'],
2154
2145
  lookup: ['query', 'id', 'error'],
2146
+ lexical: ['name', 'scope'],
2155
2147
  circular: ['crumbs'],
2156
2148
  func: ['node']
2157
2149
  });
@@ -2167,6 +2159,9 @@ analyze = Gibbon.analyze = (function() {
2167
2159
  lookup: function(query, id, error) {
2168
2160
  return "error looking up " + (query.inspect()) + " on " + id + ": " + error;
2169
2161
  },
2162
+ lexical: function(name, scope) {
2163
+ return "." + name + " is not defined in " + (scope.key());
2164
+ },
2170
2165
  circular: function(crumbs) {
2171
2166
  return "circular reference: " + (crumbs.join(' -> '));
2172
2167
  },
@@ -2276,6 +2271,26 @@ analyze = Gibbon.analyze = (function() {
2276
2271
  }));
2277
2272
  });
2278
2273
  },
2274
+ lexical: function(syntax, scope) {
2275
+ var lookupKey;
2276
+ lookupKey = scope.lexicalLookup(syntax.name);
2277
+ if (!lookupKey) {
2278
+ return cb(error('lexical', name, scope));
2279
+ }
2280
+ semanticAccessors.set(syntax, Semantic.localAccessor(lookupKey));
2281
+ dependencies.push(TypeLookup.local(lookupKey));
2282
+ nextCrumbs = crumbs.concat([lookupKey]);
2283
+ if (locks.get(lookupKey)) {
2284
+ return cb(error('circular', nextCrumbs));
2285
+ }
2286
+ return new Thunk(function() {
2287
+ return solveEntry(nextCrumbs, function() {
2288
+ return new Thunk(function() {
2289
+ return cb(frameTypes.get(lookupKey));
2290
+ });
2291
+ });
2292
+ });
2293
+ },
2279
2294
  query: function(input, scope, query) {
2280
2295
  return simplify(input, function(x) {
2281
2296
  return x.cases({
@@ -2292,22 +2307,6 @@ analyze = Gibbon.analyze = (function() {
2292
2307
  type: analysis.type.toSexpr()
2293
2308
  }));
2294
2309
  return cb(TypeExpr.fromType(analysis.type));
2295
- },
2296
- local: function(key) {
2297
- var localFrame;
2298
- nextCrumbs = crumbs.concat([key]);
2299
- semanticAccessors.set(query, Semantic.localAccessor(key));
2300
- if (locks.get(key)) {
2301
- return cb(error('circular', nextCrumbs));
2302
- }
2303
- localFrame = constraintMap.get(key).scope.frame;
2304
- return new Thunk(function() {
2305
- return solveEntry(nextCrumbs, function() {
2306
- return new Thunk(function() {
2307
- return cb(frameTypes.get(key));
2308
- });
2309
- });
2310
- });
2311
2310
  }
2312
2311
  });
2313
2312
  });
@@ -2348,6 +2347,9 @@ analyze = Gibbon.analyze = (function() {
2348
2347
  }
2349
2348
  return semanticAccessors.get(this);
2350
2349
  },
2350
+ lexical: function(_, name) {
2351
+ return semanticAccessors.get(this);
2352
+ },
2351
2353
  func: function(_, name, args) {
2352
2354
  var a, semArgs, solvedScope, typeScope;
2353
2355
  typeScope = this.__scope__;
@@ -2413,7 +2415,9 @@ analyze = Gibbon.analyze = (function() {
2413
2415
  });
2414
2416
  });
2415
2417
  DEBUG.log('setting key: ' + key);
2416
- semantics.set(key, toSemanticTree(frame));
2418
+ if (!errors.length) {
2419
+ semantics.set(key, toSemanticTree(frame));
2420
+ }
2417
2421
  frameTypes.set(key, solutions.get(TypeExpr.expr(frame.flow)));
2418
2422
  DEBUG.log('unlocking', key);
2419
2423
  locks.set(key, false);
@@ -5754,7 +5758,7 @@ stdlib = Gibbon.stdlib = (function() {
5754
5758
  index = index.failIf('index out of bounds', function(i) {
5755
5759
  return list.len().op2('<=', i);
5756
5760
  });
5757
- index = index.failIf('index out of bounds', function(i) {
5761
+ index = index.failIf('index must be non-negative', function(i) {
5758
5762
  return i.op2('<', ZERO);
5759
5763
  });
5760
5764
  return list.delist(index);
@@ -1,14 +1,6 @@
1
1
  var Gibbon = (function(undefined) {
2
2
  var Parsimmon = (function(undefined) {
3
3
  var P = (function(prototype, ownProperty, undefined) {
4
- // helper functions that also help minification
5
- function isObject(o) { return typeof o === 'object'; }
6
- function isFunction(f) { return typeof f === 'function'; }
7
-
8
- // used to extend the prototypes of superclasses (which might not
9
- // have `.Bare`s)
10
- function SuperclassBare() {}
11
-
12
4
  return function P(_superclass /* = Object */, definition) {
13
5
  // handle the case where no superclass is given
14
6
  if (definition === undefined) {
@@ -18,69 +10,60 @@ var P = (function(prototype, ownProperty, undefined) {
18
10
 
19
11
  // C is the class to be returned.
20
12
  //
21
- // It delegates to instantiating an instance of `Bare`, so that it
22
- // will always return a new instance regardless of the calling
23
- // context.
13
+ // When called, creates and initializes an instance of C, unless
14
+ // `this` is already an instance of C, then just initializes `this`;
15
+ // either way, returns the instance of C that was initialized.
24
16
  //
25
17
  // TODO: the Chrome inspector shows all created objects as `C`
26
18
  // rather than `Object`. Setting the .name property seems to
27
19
  // have no effect. Is there a way to override this behavior?
28
20
  function C() {
29
- var self = new Bare;
30
- if (isFunction(self.init)) self.init.apply(self, arguments);
21
+ var self = this instanceof C ? this : new Bare;
22
+ self.init.apply(self, arguments);
31
23
  return self;
32
24
  }
33
25
 
34
- // C.Bare is a class with a noop constructor. Its prototype is the
35
- // same as C, so that instances of C.Bare are also instances of C.
36
- // New objects can be allocated without initialization by calling
37
- // `new MyClass.Bare`.
26
+ // C.Bare is a class with a noop constructor. Its prototype will be
27
+ // the same as C, so that instances of C.Bare are instances of C.
28
+ // `new MyClass.Bare` then creates new instances of C without
29
+ // calling .init().
38
30
  function Bare() {}
39
31
  C.Bare = Bare;
40
32
 
41
- // Set up the prototype of the new class.
42
- var _super = SuperclassBare[prototype] = _superclass[prototype];
43
- var proto = Bare[prototype] = C[prototype] = C.p = new SuperclassBare;
44
-
45
- // other variables, as a minifier optimization
46
- var extensions;
33
+ // Extend the prototype chain: first use Bare to create an
34
+ // uninitialized instance of the superclass, then set up Bare
35
+ // to create instances of this class.
36
+ var _super = Bare[prototype] = _superclass[prototype];
37
+ var proto = Bare[prototype] = C[prototype] = C.p = new Bare;
47
38
 
39
+ // pre-declaring the iteration variable for the loop below to save
40
+ // a `var` keyword after minification
41
+ var key;
48
42
 
49
43
  // set the constructor property on the prototype, for convenience
50
44
  proto.constructor = C;
51
45
 
52
- C.mixin = function(def) {
53
- Bare[prototype] = C[prototype] = P(C, def)[prototype];
54
- return C;
55
- }
46
+ C.extend = function(def) { return P(C, def); }
56
47
 
57
48
  return (C.open = function(def) {
58
- extensions = {};
59
-
60
- if (isFunction(def)) {
49
+ if (typeof def === 'function') {
61
50
  // call the defining function with all the arguments you need
62
51
  // extensions captures the return value.
63
- extensions = def.call(C, proto, _super, C, _superclass);
64
- }
65
- else if (isObject(def)) {
66
- // if you passed an object instead, we'll take it
67
- extensions = def;
52
+ def = def.call(C, proto, _super, C, _superclass);
68
53
  }
69
54
 
70
55
  // ...and extend it
71
- if (isObject(extensions)) {
72
- for (var ext in extensions) {
73
- if (ownProperty.call(extensions, ext)) {
74
- proto[ext] = extensions[ext];
56
+ if (typeof def === 'object') {
57
+ for (key in def) {
58
+ if (ownProperty.call(def, key)) {
59
+ proto[key] = def[key];
75
60
  }
76
61
  }
77
62
  }
78
63
 
79
- // if there's no init, we assume we're inheriting a non-pjs class, so
80
- // we default to applying the superclass's constructor.
81
- if (!isFunction(proto.init)) {
82
- proto.init = _superclass;
83
- }
64
+ // if no init, assume we're inheriting from a non-Pjs class, so
65
+ // default to using the superclass constructor.
66
+ if (!('init' in proto)) proto.init = _superclass;
84
67
 
85
68
  return C;
86
69
  })(definition);
@@ -159,13 +142,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
159
142
 
160
143
  // -*- primitive combinators -*- //
161
144
  _.or = function(alternative) {
162
- var self = this;
163
-
164
- return Parser(function(stream, i) {
165
- var result = self._(stream, i);
166
-
167
- return result.status ? result : furthestBacktrackFor(alternative._(stream, i), result);
168
- });
145
+ return alt([this, alternative]);
169
146
  };
170
147
 
171
148
  _.then = function(next) {
@@ -259,7 +236,7 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
259
236
  }
260
237
  }
261
238
 
262
- for (; times < max && result; times += 1) {
239
+ for (; times < max; times += 1) {
263
240
  result = self._(stream, i);
264
241
  prevResult = furthestBacktrackFor(result, prevResult);
265
242
  if (result.status) {
@@ -394,7 +371,18 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
394
371
 
395
372
  return furthestBacktrackFor(makeSuccess(i, accum), result);
396
373
  });
397
- }
374
+ };
375
+
376
+ var alt = Parsimmon.alt = function(parsers) {
377
+ return Parser(function(stream, i) {
378
+ var result;
379
+ for (var j = 0; j < parsers.length; j += 1) {
380
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
381
+ if (result.status) return result;
382
+ }
383
+ return result;
384
+ });
385
+ };
398
386
 
399
387
  var index = Parsimmon.index = Parser(function(stream, i) {
400
388
  return makeSuccess(i, i);
@@ -402,8 +390,9 @@ Parsimmon.Parser = P(function(_, _super, Parser) {
402
390
 
403
391
  //- fantasyland compat
404
392
 
405
- //- Semigroup
406
- _.concat = _.then;
393
+ //- Monoid (Alternative, really)
394
+ _.concat = _.or;
395
+ _.empty = fail('empty')
407
396
 
408
397
  //- Applicative
409
398
  _.of = Parser.of = Parsimmon.of = succeed
@@ -983,6 +972,7 @@ Gibbon.AST = AST = (function(_super) {
983
972
  list: ['loc', 'elements', 'squish'],
984
973
  defaulted: ['loc', 'body', 'alternative'],
985
974
  query: ['loc', 'type', 'args'],
975
+ lexical: ['loc', 'name', 'args'],
986
976
  func: ['loc', 'name', 'args'],
987
977
  pair: ['loc', 'first', 'second'],
988
978
  flow: ['loc', 'head', 'tail'],
@@ -1024,10 +1014,15 @@ Gibbon.AST = AST = (function(_super) {
1024
1014
  query: function(_, query, args) {
1025
1015
  if (query === 'access') {
1026
1016
  return "@" + args[0];
1017
+ } else if (args.length) {
1018
+ return "@:" + query + "[" + (args.join(' ')) + "]";
1027
1019
  } else {
1028
- return "." + query + " " + (args.join(' '));
1020
+ return "@:" + query;
1029
1021
  }
1030
1022
  },
1023
+ lexical: function(_, name, args) {
1024
+ return "." + name;
1025
+ },
1031
1026
  subst: function(_, flow) {
1032
1027
  return "(" + (flow.inspect()) + ")";
1033
1028
  },
@@ -1138,7 +1133,7 @@ Gibbon.TypeAST = TypeAST = (function(_super) {
1138
1133
  })(Variant);
1139
1134
 
1140
1135
  parse = Gibbon.parse = (function() {
1141
- var accessor, accessorExpr, arrow, arrowType, assertString, 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, lazy, lbrace, lbrack, lexeme, lines, listExpr, listType, lparen, lsplat, metadata, multiline, name, nonDefaultedFlow, nonPairedFlow, numericExpr, opt, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, queryArg, queryExpr, rbrace, rbrack, regex, rparen, rsplat, seq, signature, simpleType, singletonFlow, spanLoc, squishListExpr, str, string, stringExpr, substExpr, succeed, tag, tassign, type, typeVar, variable, whitespace, wildType, wildcard, withLoc,
1136
+ var accessor, accessorExpr, arrow, arrowType, assertString, 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, lazy, lbrace, lbrack, lexeme, lexical, lexicalExpr, lines, listExpr, listType, lparen, lsplat, metadata, multiline, name, nonDefaultedFlow, nonPairedFlow, numericExpr, opt, pair, parenFlow, parenFrame, parenType, percent, percentExpr, program, query, queryArg, queryExpr, rbrace, rbrack, regex, rparen, rsplat, seq, signature, simpleType, singletonFlow, spanLoc, squishListExpr, str, string, stringExpr, substExpr, succeed, tag, tassign, type, typeVar, variable, whitespace, wildType, wildcard, withLoc,
1142
1137
  _this = this;
1143
1138
  tag = function(name, parser) {
1144
1139
  return Parsimmon.Parser(function(stream, i) {
@@ -1200,9 +1195,10 @@ parse = Gibbon.parse = (function() {
1200
1195
  defaulted = multiline(string('|'));
1201
1196
  lsplat = multiline(string('[*'));
1202
1197
  rsplat = lexeme(string('*]'));
1203
- query = lexeme(string('.').then(identifier));
1198
+ query = lexeme(string('@:').then(identifier));
1204
1199
  queryArg = lexeme(regex(/^\w[\w-]*/));
1205
1200
  accessor = lexeme(string('@').then(identifier));
1201
+ lexical = lexeme(string('.').then(identifier));
1206
1202
  name = lexeme(identifier);
1207
1203
  str = lexeme(string("'").then(regex(/^[^']*/)).skip(string("'")));
1208
1204
  fraction = tag('a fraction', lexeme(regex(/^\d+\/\d+/)));
@@ -1234,10 +1230,13 @@ parse = Gibbon.parse = (function() {
1234
1230
  accessorExpr = withLoc(accessor, function(loc, name) {
1235
1231
  return AST.query(loc, 'access', [name]);
1236
1232
  });
1237
- queryExpr = seq([query, queryArg.many()]).map(function(_arg) {
1238
- var a, args, loc, q;
1239
- q = _arg[0], args = _arg[1];
1240
- loc = spanLoc(q, args[args.length - 1] || q);
1233
+ lexicalExpr = withLoc(lexical, function(loc, name) {
1234
+ return AST.lexical(loc, name, []);
1235
+ });
1236
+ queryExpr = seq([query, lbrack, queryArg.many(), rbrack]).map(function(_arg) {
1237
+ var a, args, loc, q, _;
1238
+ q = _arg[0], _ = _arg[1], args = _arg[2];
1239
+ loc = spanLoc(q, rbrack);
1241
1240
  return AST.query(loc, q.value, (function() {
1242
1241
  var _i, _len, _results;
1243
1242
  _results = [];
@@ -1280,7 +1279,7 @@ parse = Gibbon.parse = (function() {
1280
1279
  return AST.block(spanLoc(l, r), flow);
1281
1280
  });
1282
1281
  });
1283
- expr = tag('an expr', queryExpr.or(accessorExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr))))))));
1282
+ expr = tag('an expr', queryExpr.or(accessorExpr.or(lexicalExpr.or(substExpr.or(squishListExpr.or(listExpr.or(stringExpr.or(blockExpr.or(numericExpr)))))))));
1284
1283
  singletonFlow = expr.map(function(e) {
1285
1284
  return AST.flow(e.loc, e, null);
1286
1285
  });
@@ -1647,6 +1646,7 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1647
1646
  expr: ['expr'],
1648
1647
  variable: ['name', 'uniq'],
1649
1648
  query: ['input', 'scope', 'query'],
1649
+ lexical: ['syntax', 'scope'],
1650
1650
  destructure: ['constraint', 'name', 'argnum'],
1651
1651
  "native": ['id'],
1652
1652
  param: ['name', 'constraints'],
@@ -1700,6 +1700,9 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1700
1700
  query: function(input, _, query) {
1701
1701
  return "" + (input.inspect()) + "[" + (query.inspect()) + "]";
1702
1702
  },
1703
+ lexical: function(syntax, scope) {
1704
+ return "." + syntax.name + ":" + (scope.key());
1705
+ },
1703
1706
  destructure: function(constraint, name, argnum) {
1704
1707
  return "" + (constraint.inspect()) + "/" + name + "[" + argnum + "]";
1705
1708
  },
@@ -1759,6 +1762,9 @@ Gibbon.TypeExpr = TypeExpr = (function(_super) {
1759
1762
  query: function(input, scope, query) {
1760
1763
  return "" + (query.inspect()) + ":" + scope.uniq + "[" + (recurse(input)) + "]";
1761
1764
  },
1765
+ lexical: function(syntax, scope) {
1766
+ return "." + (syntax.hash()) + ":" + (scope.key());
1767
+ },
1762
1768
  "native": function(id) {
1763
1769
  return "!" + id;
1764
1770
  },
@@ -1961,35 +1967,17 @@ analyze = Gibbon.analyze = (function() {
1961
1967
  };
1962
1968
 
1963
1969
  Scope.prototype.lookup = function(nativeId, query, cb) {
1964
- var lexical;
1965
- if (query.type === 'access' && nativeId === this.context.globalID) {
1966
- lexical = this.lexicalLookup(query.args[0]);
1967
- if (lexical) {
1968
- return cb(lexical);
1969
- } else {
1970
- return this.context.query(nativeId, query, cb);
1971
- }
1972
- } else {
1973
- return this.context.query(nativeId, query, cb);
1974
- }
1970
+ return this.context.query(nativeId, query, cb);
1975
1971
  };
1976
1972
 
1977
1973
  Scope.prototype.lexicalLookup = function(name) {
1978
- var local;
1979
- local = this.lookupLocal(name);
1980
- if (local) {
1981
- return local;
1982
- }
1983
- if (this.parent) {
1984
- return this.parent.lexicalLookup(name);
1985
- }
1986
- };
1987
-
1988
- Scope.prototype.lookupLocal = function(name) {
1989
- if (!this.bindings.has(name)) {
1990
- return null;
1974
+ if (this.bindings.has(name)) {
1975
+ return this.keyFor(name);
1976
+ } else {
1977
+ if (this.parent) {
1978
+ return this.parent.lexicalLookup(name);
1979
+ }
1991
1980
  }
1992
- return TypeLookup.local(this.keyFor(name));
1993
1981
  };
1994
1982
 
1995
1983
  makeKey = function(crumbs) {
@@ -2032,6 +2020,9 @@ analyze = Gibbon.analyze = (function() {
2032
2020
  input = flow.tail ? TypeExpr.expr(flow.tail) : global;
2033
2021
  return push(TypeExpr.expr(flow), TypeExpr.query(input, _this, flow.head));
2034
2022
  },
2023
+ lexical: function(_, name) {
2024
+ return push(TypeExpr.expr(flow), TypeExpr.lexical(flow.head, _this));
2025
+ },
2035
2026
  pair: function(_, first, second) {
2036
2027
  _this.analyzeFlow(first, global, push);
2037
2028
  _this.analyzeFlow(second, global, push);
@@ -2138,6 +2129,7 @@ analyze = Gibbon.analyze = (function() {
2138
2129
  match: ['lhs', 'rhs'],
2139
2130
  destructure: ['type'],
2140
2131
  lookup: ['query', 'id', 'error'],
2132
+ lexical: ['name', 'scope'],
2141
2133
  circular: ['crumbs'],
2142
2134
  func: ['node']
2143
2135
  });
@@ -2153,6 +2145,9 @@ analyze = Gibbon.analyze = (function() {
2153
2145
  lookup: function(query, id, error) {
2154
2146
  return "error looking up " + (query.inspect()) + " on " + id + ": " + error;
2155
2147
  },
2148
+ lexical: function(name, scope) {
2149
+ return "." + name + " is not defined in " + (scope.key());
2150
+ },
2156
2151
  circular: function(crumbs) {
2157
2152
  return "circular reference: " + (crumbs.join(' -> '));
2158
2153
  },
@@ -2248,6 +2243,26 @@ analyze = Gibbon.analyze = (function() {
2248
2243
  }));
2249
2244
  });
2250
2245
  },
2246
+ lexical: function(syntax, scope) {
2247
+ var lookupKey;
2248
+ lookupKey = scope.lexicalLookup(syntax.name);
2249
+ if (!lookupKey) {
2250
+ return cb(error('lexical', name, scope));
2251
+ }
2252
+ semanticAccessors.set(syntax, Semantic.localAccessor(lookupKey));
2253
+ dependencies.push(TypeLookup.local(lookupKey));
2254
+ nextCrumbs = crumbs.concat([lookupKey]);
2255
+ if (locks.get(lookupKey)) {
2256
+ return cb(error('circular', nextCrumbs));
2257
+ }
2258
+ return new Thunk(function() {
2259
+ return solveEntry(nextCrumbs, function() {
2260
+ return new Thunk(function() {
2261
+ return cb(frameTypes.get(lookupKey));
2262
+ });
2263
+ });
2264
+ });
2265
+ },
2251
2266
  query: function(input, scope, query) {
2252
2267
  return simplify(input, function(x) {
2253
2268
  return x.cases({
@@ -2264,22 +2279,6 @@ analyze = Gibbon.analyze = (function() {
2264
2279
  type: analysis.type.toSexpr()
2265
2280
  }));
2266
2281
  return cb(TypeExpr.fromType(analysis.type));
2267
- },
2268
- local: function(key) {
2269
- var localFrame;
2270
- nextCrumbs = crumbs.concat([key]);
2271
- semanticAccessors.set(query, Semantic.localAccessor(key));
2272
- if (locks.get(key)) {
2273
- return cb(error('circular', nextCrumbs));
2274
- }
2275
- localFrame = constraintMap.get(key).scope.frame;
2276
- return new Thunk(function() {
2277
- return solveEntry(nextCrumbs, function() {
2278
- return new Thunk(function() {
2279
- return cb(frameTypes.get(key));
2280
- });
2281
- });
2282
- });
2283
2282
  }
2284
2283
  });
2285
2284
  });
@@ -2320,6 +2319,9 @@ analyze = Gibbon.analyze = (function() {
2320
2319
  }
2321
2320
  return semanticAccessors.get(this);
2322
2321
  },
2322
+ lexical: function(_, name) {
2323
+ return semanticAccessors.get(this);
2324
+ },
2323
2325
  func: function(_, name, args) {
2324
2326
  var a, semArgs, solvedScope, typeScope;
2325
2327
  typeScope = this.__scope__;
@@ -2381,7 +2383,9 @@ analyze = Gibbon.analyze = (function() {
2381
2383
  };
2382
2384
 
2383
2385
 
2384
- semantics.set(key, toSemanticTree(frame));
2386
+ if (!errors.length) {
2387
+ semantics.set(key, toSemanticTree(frame));
2388
+ }
2385
2389
  frameTypes.set(key, solutions.get(TypeExpr.expr(frame.flow)));
2386
2390
 
2387
2391
  locks.set(key, false);
@@ -5714,7 +5718,7 @@ stdlib = Gibbon.stdlib = (function() {
5714
5718
  index = index.failIf('index out of bounds', function(i) {
5715
5719
  return list.len().op2('<=', i);
5716
5720
  });
5717
- index = index.failIf('index out of bounds', function(i) {
5721
+ index = index.failIf('index must be non-negative', function(i) {
5718
5722
  return i.op2('<', ZERO);
5719
5723
  });
5720
5724
  return list.delist(index);
@@ -16,7 +16,7 @@
16
16
  "node-inspector": "0.2.x"
17
17
  },
18
18
  "dependencies": {
19
- "parsimmon": "0.2.0",
19
+ "parsimmon": "0.2.x",
20
20
  "falafel": "0.2.x"
21
21
  },
22
22
  "scripts": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodguide-gibbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Run and analyze gibbon code from ruby or a browser (via a ruby app).
14
14
  email:
@@ -50,4 +50,3 @@ signing_key:
50
50
  specification_version: 4
51
51
  summary: Ruby bindings for the gibbon data language
52
52
  test_files: []
53
- has_rdoc: