goodguide-gibbon 0.14.2 → 0.14.4

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: 68b9d67850eefaf6beb8331b64d608743564a410
4
- data.tar.gz: c570344632c7b9733db5debd4a77b5a4b1bb1c1e
3
+ metadata.gz: 3c76476b765aa0f6ca14c4d781217e14e5dacf63
4
+ data.tar.gz: 804aab0497e0d6c8c87339b9efa26e754e9a9b20
5
5
  SHA512:
6
- metadata.gz: ec7c7635932a1cf02446cd449812fff7093ead9f3e97a18681edb8d0246192b71bd4ff8265fb6f2e7cafe36be602b5d995fd513930420b77ccb7b948f151892f
7
- data.tar.gz: dd413b4032913bf99b45a42862bf761c197c2a6d82727a83692b1dabaee81adf0bc0c187e35bb5d0aa768041e1ae32fe0526740c78a788cdd2da4f3e11384f69
6
+ metadata.gz: aa56fa349b68b4a1b78d03666c1bd8be4488991638fee10f8b915a5fba0ae48d0db0b15753c3acc9e2785468eaa83989744c4b4798a8b430a6f40bd1f2075ae4
7
+ data.tar.gz: 2d3cd36a052449b9fd89fe60432ec2a78edfb33380ac2f7f504c6ea43343b9219b399cba53df8c4852a2b7c1722db44b1395b769250162547110b824cb789e18
@@ -133,6 +133,10 @@ module GoodGuide
133
133
  @errors.map(&method(:semantic_error_message))
134
134
  end
135
135
 
136
+ def message
137
+ messages.join(', ')
138
+ end
139
+
136
140
  private
137
141
  def gibbon
138
142
  @context.gibbon
@@ -24,7 +24,7 @@ Parsimmon.Parser = (function() {
24
24
  index: index,
25
25
  value: value,
26
26
  furthest: -1,
27
- expected: []
27
+ expected: ''
28
28
  };
29
29
  }
30
30
 
@@ -34,24 +34,20 @@ Parsimmon.Parser = (function() {
34
34
  index: -1,
35
35
  value: null,
36
36
  furthest: index,
37
- expected: [expected]
37
+ expected: expected
38
38
  };
39
39
  }
40
40
 
41
- function mergeReplies(result, last) {
41
+ function furthestBacktrackFor(result, last) {
42
42
  if (!last) return result;
43
- if (result.furthest > last.furthest) return result;
44
-
45
- var expected = (result.furthest === last.furthest)
46
- ? result.expected.concat(last.expected)
47
- : last.expected;
43
+ if (result.furthest >= last.furthest) return result;
48
44
 
49
45
  return {
50
46
  status: result.status,
51
47
  index: result.index,
52
48
  value: result.value,
53
49
  furthest: last.furthest,
54
- expected: expected
50
+ expected: last.expected
55
51
  }
56
52
  }
57
53
 
@@ -59,27 +55,20 @@ Parsimmon.Parser = (function() {
59
55
  if (!(p instanceof Parser)) throw new Error('not a parser: '+p);
60
56
  }
61
57
 
62
- function formatExpected(expected) {
63
- if (expected.length === 1) return expected[0];
64
-
65
- return 'one of ' + expected.join(', ')
66
- }
67
-
68
- function formatGot(stream, error) {
58
+ var formatError = Parsimmon.formatError = function(stream, error) {
59
+ var expected = error.expected;
69
60
  var i = error.index;
70
61
 
71
- if (i === stream.length) return ', got the end of the stream'
72
-
62
+ if (i === stream.length) {
63
+ return 'expected ' + expected + ', got the end of the string';
64
+ }
73
65
 
74
66
  var prefix = (i > 0 ? "'..." : "'");
75
67
  var suffix = (stream.length - i > 12 ? "...'" : "'");
76
-
77
- return ' at character ' + i + ', got ' + prefix + stream.slice(i, i+12) + suffix
78
- }
79
-
80
- var formatError = Parsimmon.formatError = function(stream, error) {
81
- console.log('formatError', stream, error);
82
- return 'expected ' + formatExpected(error.expected) + formatGot(stream, error)
68
+ return (
69
+ 'expected ' + expected + ' at character ' + i + ', got ' +
70
+ prefix + stream.slice(i, i+12) + suffix
71
+ );
83
72
  };
84
73
 
85
74
  _.parse = function(stream) {
@@ -105,13 +94,13 @@ Parsimmon.Parser = (function() {
105
94
  var accum = new Array(numParsers);
106
95
 
107
96
  for (var j = 0; j < numParsers; j += 1) {
108
- result = mergeReplies(parsers[j]._(stream, i), result);
97
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
109
98
  if (!result.status) return result;
110
99
  accum[j] = result.value
111
100
  i = result.index;
112
101
  }
113
102
 
114
- return mergeReplies(makeSuccess(i, accum), result);
103
+ return furthestBacktrackFor(makeSuccess(i, accum), result);
115
104
  });
116
105
  };
117
106
 
@@ -139,7 +128,7 @@ Parsimmon.Parser = (function() {
139
128
  return Parser(function(stream, i) {
140
129
  var result;
141
130
  for (var j = 0; j < parsers.length; j += 1) {
142
- result = mergeReplies(parsers[j]._(stream, i), result);
131
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
143
132
  if (result.status) return result;
144
133
  }
145
134
  return result;
@@ -183,14 +172,14 @@ Parsimmon.Parser = (function() {
183
172
  var prevResult;
184
173
 
185
174
  for (;;) {
186
- result = mergeReplies(self._(stream, i), result);
175
+ result = furthestBacktrackFor(self._(stream, i), result);
187
176
 
188
177
  if (result.status) {
189
178
  i = result.index;
190
179
  accum.push(result.value);
191
180
  }
192
181
  else {
193
- return mergeReplies(makeSuccess(i, accum), result);
182
+ return furthestBacktrackFor(makeSuccess(i, accum), result);
194
183
  }
195
184
  }
196
185
  });
@@ -228,7 +217,7 @@ Parsimmon.Parser = (function() {
228
217
 
229
218
  for (var times = 0; times < min; times += 1) {
230
219
  result = self._(stream, i);
231
- prevResult = mergeReplies(result, prevResult);
220
+ prevResult = furthestBacktrackFor(result, prevResult);
232
221
  if (result.status) {
233
222
  i = result.index;
234
223
  accum.push(result.value);
@@ -238,7 +227,7 @@ Parsimmon.Parser = (function() {
238
227
 
239
228
  for (; times < max; times += 1) {
240
229
  result = self._(stream, i);
241
- prevResult = mergeReplies(result, prevResult);
230
+ prevResult = furthestBacktrackFor(result, prevResult);
242
231
  if (result.status) {
243
232
  i = result.index;
244
233
  accum.push(result.value);
@@ -246,7 +235,7 @@ Parsimmon.Parser = (function() {
246
235
  else break;
247
236
  }
248
237
 
249
- return mergeReplies(makeSuccess(i, accum), prevResult);
238
+ return furthestBacktrackFor(makeSuccess(i, accum), prevResult);
250
239
  });
251
240
  };
252
241
 
@@ -265,7 +254,7 @@ Parsimmon.Parser = (function() {
265
254
  return Parser(function(stream, i) {
266
255
  var result = self._(stream, i);
267
256
  if (!result.status) return result;
268
- return mergeReplies(makeSuccess(result.index, fn(result.value)), result);
257
+ return furthestBacktrackFor(makeSuccess(result.index, fn(result.value)), result);
269
258
  });
270
259
  };
271
260
 
@@ -280,12 +269,7 @@ Parsimmon.Parser = (function() {
280
269
  };
281
270
 
282
271
  _.desc = function(expected) {
283
- var self = this;
284
- return Parser(function(stream, i) {
285
- var reply = self._(stream, i);
286
- if (!reply.status) reply.expected = [expected];
287
- return reply;
288
- });
272
+ return this.or(fail(expected))
289
273
  };
290
274
 
291
275
  // -*- primitive parsers -*- //
@@ -307,7 +291,6 @@ Parsimmon.Parser = (function() {
307
291
 
308
292
  var regex = Parsimmon.regex = function(re, group) {
309
293
  var anchored = RegExp('^(?:'+re.source+')', (''+re).slice((''+re).lastIndexOf('/')+1));
310
- var expected = '' + re;
311
294
  if (group == null) group = 0;
312
295
 
313
296
  return Parser(function(stream, i) {
@@ -319,7 +302,7 @@ Parsimmon.Parser = (function() {
319
302
  if (groupMatch != null) return makeSuccess(i+fullMatch.length, groupMatch);
320
303
  }
321
304
 
322
- return makeFailure(i, expected);
305
+ return makeFailure(i, re);
323
306
  });
324
307
  };
325
308
 
@@ -424,7 +407,7 @@ Parsimmon.Parser = (function() {
424
407
  var result = self._(stream, i);
425
408
  if (!result.status) return result;
426
409
  var nextParser = f(result.value);
427
- return mergeReplies(nextParser._(stream, result.index), result);
410
+ return furthestBacktrackFor(nextParser._(stream, result.index), result);
428
411
  });
429
412
  };
430
413
 
@@ -459,7 +442,7 @@ Thunk = (function() {
459
442
  inspectNative = function(o) {
460
443
  switch (typeof o) {
461
444
  case 'string':
462
- return "\"" + o + "\"";
445
+ return "'" + o + "'";
463
446
  case 'number':
464
447
  return "" + o;
465
448
  case 'boolean':
@@ -6289,7 +6272,7 @@ Value = Gibbon.Value = Value = (function(_super) {
6289
6272
  return this.cases({
6290
6273
  list: function(els) {
6291
6274
  var e;
6292
- return "(list " + (((function() {
6275
+ return "[" + (((function() {
6293
6276
  var _i, _len, _results;
6294
6277
  _results = [];
6295
6278
  for (_i = 0, _len = els.length; _i < _len; _i++) {
@@ -6297,13 +6280,34 @@ Value = Gibbon.Value = Value = (function(_super) {
6297
6280
  _results.push(e.inspect());
6298
6281
  }
6299
6282
  return _results;
6300
- })()).join(' ')) + ")";
6283
+ })()).join(', ')) + "]";
6301
6284
  },
6302
6285
  pair: function(first, second) {
6303
- return "(pair " + (first.inspect()) + " " + (second.inspect()) + ")";
6286
+ var _1, _2;
6287
+ _1 = first.cases({
6288
+ pair: (function() {
6289
+ return "(" + (first.inspect()) + ")";
6290
+ }),
6291
+ other: function() {
6292
+ return first.inspect();
6293
+ }
6294
+ });
6295
+ _2 = second.cases({
6296
+ pair: (function() {
6297
+ return "(" + (second.inspect()) + ")";
6298
+ }),
6299
+ other: function() {
6300
+ return second.inspect();
6301
+ }
6302
+ });
6303
+ return "" + _1 + " : " + _2;
6304
6304
  },
6305
6305
  entity: function(id) {
6306
- return "(entity " + id + ")";
6306
+ return "<entity " + id + ">";
6307
+ },
6308
+ string: inspectNative,
6309
+ block: function(f) {
6310
+ return "{ <block> }";
6307
6311
  },
6308
6312
  other: function() {
6309
6313
  return '' + this.asPrimitive();
@@ -24,7 +24,7 @@ Parsimmon.Parser = (function() {
24
24
  index: index,
25
25
  value: value,
26
26
  furthest: -1,
27
- expected: []
27
+ expected: ''
28
28
  };
29
29
  }
30
30
 
@@ -34,24 +34,20 @@ Parsimmon.Parser = (function() {
34
34
  index: -1,
35
35
  value: null,
36
36
  furthest: index,
37
- expected: [expected]
37
+ expected: expected
38
38
  };
39
39
  }
40
40
 
41
- function mergeReplies(result, last) {
41
+ function furthestBacktrackFor(result, last) {
42
42
  if (!last) return result;
43
- if (result.furthest > last.furthest) return result;
44
-
45
- var expected = (result.furthest === last.furthest)
46
- ? result.expected.concat(last.expected)
47
- : last.expected;
43
+ if (result.furthest >= last.furthest) return result;
48
44
 
49
45
  return {
50
46
  status: result.status,
51
47
  index: result.index,
52
48
  value: result.value,
53
49
  furthest: last.furthest,
54
- expected: expected
50
+ expected: last.expected
55
51
  }
56
52
  }
57
53
 
@@ -59,27 +55,20 @@ Parsimmon.Parser = (function() {
59
55
  if (!(p instanceof Parser)) throw new Error('not a parser: '+p);
60
56
  }
61
57
 
62
- function formatExpected(expected) {
63
- if (expected.length === 1) return expected[0];
64
-
65
- return 'one of ' + expected.join(', ')
66
- }
67
-
68
- function formatGot(stream, error) {
58
+ var formatError = Parsimmon.formatError = function(stream, error) {
59
+ var expected = error.expected;
69
60
  var i = error.index;
70
61
 
71
- if (i === stream.length) return ', got the end of the stream'
72
-
62
+ if (i === stream.length) {
63
+ return 'expected ' + expected + ', got the end of the string';
64
+ }
73
65
 
74
66
  var prefix = (i > 0 ? "'..." : "'");
75
67
  var suffix = (stream.length - i > 12 ? "...'" : "'");
76
-
77
- return ' at character ' + i + ', got ' + prefix + stream.slice(i, i+12) + suffix
78
- }
79
-
80
- var formatError = Parsimmon.formatError = function(stream, error) {
81
- console.log('formatError', stream, error);
82
- return 'expected ' + formatExpected(error.expected) + formatGot(stream, error)
68
+ return (
69
+ 'expected ' + expected + ' at character ' + i + ', got ' +
70
+ prefix + stream.slice(i, i+12) + suffix
71
+ );
83
72
  };
84
73
 
85
74
  _.parse = function(stream) {
@@ -105,13 +94,13 @@ Parsimmon.Parser = (function() {
105
94
  var accum = new Array(numParsers);
106
95
 
107
96
  for (var j = 0; j < numParsers; j += 1) {
108
- result = mergeReplies(parsers[j]._(stream, i), result);
97
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
109
98
  if (!result.status) return result;
110
99
  accum[j] = result.value
111
100
  i = result.index;
112
101
  }
113
102
 
114
- return mergeReplies(makeSuccess(i, accum), result);
103
+ return furthestBacktrackFor(makeSuccess(i, accum), result);
115
104
  });
116
105
  };
117
106
 
@@ -139,7 +128,7 @@ Parsimmon.Parser = (function() {
139
128
  return Parser(function(stream, i) {
140
129
  var result;
141
130
  for (var j = 0; j < parsers.length; j += 1) {
142
- result = mergeReplies(parsers[j]._(stream, i), result);
131
+ result = furthestBacktrackFor(parsers[j]._(stream, i), result);
143
132
  if (result.status) return result;
144
133
  }
145
134
  return result;
@@ -183,14 +172,14 @@ Parsimmon.Parser = (function() {
183
172
  var prevResult;
184
173
 
185
174
  for (;;) {
186
- result = mergeReplies(self._(stream, i), result);
175
+ result = furthestBacktrackFor(self._(stream, i), result);
187
176
 
188
177
  if (result.status) {
189
178
  i = result.index;
190
179
  accum.push(result.value);
191
180
  }
192
181
  else {
193
- return mergeReplies(makeSuccess(i, accum), result);
182
+ return furthestBacktrackFor(makeSuccess(i, accum), result);
194
183
  }
195
184
  }
196
185
  });
@@ -228,7 +217,7 @@ Parsimmon.Parser = (function() {
228
217
 
229
218
  for (var times = 0; times < min; times += 1) {
230
219
  result = self._(stream, i);
231
- prevResult = mergeReplies(result, prevResult);
220
+ prevResult = furthestBacktrackFor(result, prevResult);
232
221
  if (result.status) {
233
222
  i = result.index;
234
223
  accum.push(result.value);
@@ -238,7 +227,7 @@ Parsimmon.Parser = (function() {
238
227
 
239
228
  for (; times < max; times += 1) {
240
229
  result = self._(stream, i);
241
- prevResult = mergeReplies(result, prevResult);
230
+ prevResult = furthestBacktrackFor(result, prevResult);
242
231
  if (result.status) {
243
232
  i = result.index;
244
233
  accum.push(result.value);
@@ -246,7 +235,7 @@ Parsimmon.Parser = (function() {
246
235
  else break;
247
236
  }
248
237
 
249
- return mergeReplies(makeSuccess(i, accum), prevResult);
238
+ return furthestBacktrackFor(makeSuccess(i, accum), prevResult);
250
239
  });
251
240
  };
252
241
 
@@ -265,7 +254,7 @@ Parsimmon.Parser = (function() {
265
254
  return Parser(function(stream, i) {
266
255
  var result = self._(stream, i);
267
256
  if (!result.status) return result;
268
- return mergeReplies(makeSuccess(result.index, fn(result.value)), result);
257
+ return furthestBacktrackFor(makeSuccess(result.index, fn(result.value)), result);
269
258
  });
270
259
  };
271
260
 
@@ -280,12 +269,7 @@ Parsimmon.Parser = (function() {
280
269
  };
281
270
 
282
271
  _.desc = function(expected) {
283
- var self = this;
284
- return Parser(function(stream, i) {
285
- var reply = self._(stream, i);
286
- if (!reply.status) reply.expected = [expected];
287
- return reply;
288
- });
272
+ return this.or(fail(expected))
289
273
  };
290
274
 
291
275
  // -*- primitive parsers -*- //
@@ -307,7 +291,6 @@ Parsimmon.Parser = (function() {
307
291
 
308
292
  var regex = Parsimmon.regex = function(re, group) {
309
293
  var anchored = RegExp('^(?:'+re.source+')', (''+re).slice((''+re).lastIndexOf('/')+1));
310
- var expected = '' + re;
311
294
  if (group == null) group = 0;
312
295
 
313
296
  return Parser(function(stream, i) {
@@ -319,7 +302,7 @@ Parsimmon.Parser = (function() {
319
302
  if (groupMatch != null) return makeSuccess(i+fullMatch.length, groupMatch);
320
303
  }
321
304
 
322
- return makeFailure(i, expected);
305
+ return makeFailure(i, re);
323
306
  });
324
307
  };
325
308
 
@@ -424,7 +407,7 @@ Parsimmon.Parser = (function() {
424
407
  var result = self._(stream, i);
425
408
  if (!result.status) return result;
426
409
  var nextParser = f(result.value);
427
- return mergeReplies(nextParser._(stream, result.index), result);
410
+ return furthestBacktrackFor(nextParser._(stream, result.index), result);
428
411
  });
429
412
  };
430
413
 
@@ -459,7 +442,7 @@ Thunk = (function() {
459
442
  inspectNative = function(o) {
460
443
  switch (typeof o) {
461
444
  case 'string':
462
- return "\"" + o + "\"";
445
+ return "'" + o + "'";
463
446
  case 'number':
464
447
  return "" + o;
465
448
  case 'boolean':
@@ -6225,7 +6208,7 @@ Value = Gibbon.Value = Value = (function(_super) {
6225
6208
  return this.cases({
6226
6209
  list: function(els) {
6227
6210
  var e;
6228
- return "(list " + (((function() {
6211
+ return "[" + (((function() {
6229
6212
  var _i, _len, _results;
6230
6213
  _results = [];
6231
6214
  for (_i = 0, _len = els.length; _i < _len; _i++) {
@@ -6233,13 +6216,34 @@ Value = Gibbon.Value = Value = (function(_super) {
6233
6216
  _results.push(e.inspect());
6234
6217
  }
6235
6218
  return _results;
6236
- })()).join(' ')) + ")";
6219
+ })()).join(', ')) + "]";
6237
6220
  },
6238
6221
  pair: function(first, second) {
6239
- return "(pair " + (first.inspect()) + " " + (second.inspect()) + ")";
6222
+ var _1, _2;
6223
+ _1 = first.cases({
6224
+ pair: (function() {
6225
+ return "(" + (first.inspect()) + ")";
6226
+ }),
6227
+ other: function() {
6228
+ return first.inspect();
6229
+ }
6230
+ });
6231
+ _2 = second.cases({
6232
+ pair: (function() {
6233
+ return "(" + (second.inspect()) + ")";
6234
+ }),
6235
+ other: function() {
6236
+ return second.inspect();
6237
+ }
6238
+ });
6239
+ return "" + _1 + " : " + _2;
6240
6240
  },
6241
6241
  entity: function(id) {
6242
- return "(entity " + id + ")";
6242
+ return "<entity " + id + ">";
6243
+ },
6244
+ string: inspectNative,
6245
+ block: function(f) {
6246
+ return "{ <block> }";
6243
6247
  },
6244
6248
  other: function() {
6245
6249
  return '' + this.asPrimitive();
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gibbon",
3
- "version": "0.14.2",
3
+ "version": "0.14.4",
4
4
  "description": "A data language",
5
5
  "keywords": ["language"],
6
6
  "author": "Jeanine Adkisson <jeanine.adkisson@gmail.com>",
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.14.2
4
+ version: 0.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeanine Adkisson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-22 00:00:00.000000000 Z
11
+ date: 2016-06-22 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:
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements: []
47
47
  rubyforge_project: goodguide-gibbon
48
- rubygems_version: 2.4.5.1
48
+ rubygems_version: 2.2.2
49
49
  signing_key:
50
50
  specification_version: 4
51
51
  summary: Ruby bindings for the gibbon data language