goodguide-gibbon 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,8 +24,39 @@ module GoodGuide
24
24
  def initialize(errors)
25
25
  @errors = errors
26
26
  end
27
+
28
+ def messages
29
+ @errors.map(&method(:semantic_error_message))
30
+ end
31
+
32
+ private
33
+ def semantic_error_message(e)
34
+ case e['_tag']
35
+ when 'match'
36
+ lhs = e['lhs'].inspect
37
+ rhs = e['rhs'].inspect
38
+ "could not match #{lhs} with #{rhs}"
39
+ when 'destructure'
40
+ type = e['type'].inspect
41
+ "could not destructure #{type}"
42
+ when 'lookup'
43
+ query_name = e['query']['name']
44
+ query_type = e['query']['type']
45
+ query = "@#{query_type}(#{query_name})"
46
+ id = e['id']
47
+ error = e['error']
48
+ "error analyzing #{query} on #{id}: #{error}"
49
+ when 'circular'
50
+ chain = e['crumbs'].join(' -> ')
51
+ "circular dependency: #{chain}"
52
+ else
53
+ raise "unknown error type #{e['_tag']}"
54
+ end
55
+ end
27
56
  end
28
57
 
58
+ class QueryError < StandardError; end
59
+
29
60
  class RuntimeError < StandardError; end
30
61
 
31
62
  class Program
@@ -99,8 +130,8 @@ module GoodGuide
99
130
  cb = args.pop
100
131
  err, val = begin
101
132
  [nil, send(method, *args)]
102
- # rescue => e
103
- # [e.to_s, nil]
133
+ rescue QueryError => e
134
+ [e.to_s, nil]
104
135
  end
105
136
 
106
137
  cb.call(err, val)
@@ -109,6 +140,10 @@ module GoodGuide
109
140
  end
110
141
 
111
142
  class StaticClient < AbstractClient
143
+ def query_error!(*a)
144
+ raise QueryError.new(*a)
145
+ end
146
+
112
147
  def analyze_query(input_id, query, t)
113
148
  query_impl = get_query(query.type)
114
149
  analysis = instance_exec(input_id, query.name, t, &query_impl)
@@ -1,7 +1,7 @@
1
1
  module GoodGuide
2
2
  module Gibbon
3
3
  def self.version
4
- '0.3.0'
4
+ '0.3.1'
5
5
  end
6
6
  end
7
7
  end
@@ -1500,7 +1500,8 @@ Gibbon.TypeLookup = TypeLookup = (function(_super) {
1500
1500
 
1501
1501
  TypeLookup.types({
1502
1502
  response: ['analysis'],
1503
- local: ['name']
1503
+ local: ['name'],
1504
+ error: ['error']
1504
1505
  });
1505
1506
 
1506
1507
  return TypeLookup;
@@ -1781,9 +1782,10 @@ analyze = Gibbon.analyze = (function() {
1781
1782
  NativeContext.prototype.query = function(id, query, cb) {
1782
1783
  return this.externalLookup.call(null, id, query, TypeAST, function(err, analysis) {
1783
1784
  if (err) {
1784
- throw err;
1785
+ return cb(TypeLookup.error(err));
1786
+ } else {
1787
+ return cb(TypeLookup.response(analysis));
1785
1788
  }
1786
- return cb(TypeLookup.response(analysis));
1787
1789
  });
1788
1790
  };
1789
1791
 
@@ -1978,9 +1980,8 @@ analyze = Gibbon.analyze = (function() {
1978
1980
 
1979
1981
  TypeError.types({
1980
1982
  match: ['lhs', 'rhs'],
1981
- infinite: ['type'],
1982
1983
  destructure: ['type'],
1983
- access: ['type'],
1984
+ lookup: ['query', 'id', 'error'],
1984
1985
  circular: ['crumbs']
1985
1986
  });
1986
1987
 
@@ -2085,6 +2086,9 @@ analyze = Gibbon.analyze = (function() {
2085
2086
  return scope.lookup(id, query, function(lookup) {
2086
2087
  dependencies.push(lookup);
2087
2088
  return lookup.cases({
2089
+ error: function(e) {
2090
+ return cb(error('lookup', query, id, e));
2091
+ },
2088
2092
  response: function(analysis) {
2089
2093
  semanticAccessors.set(query, Semantic.query(analysis.annotations));
2090
2094
  return cb(TypeExpr.fromAST(analysis.type));
@@ -2854,7 +2858,7 @@ eval_ = Gibbon["eval"] = (function() {
2854
2858
  // Generated by CoffeeScript 1.6.3
2855
2859
  Gibbon.jsonConsumer = (function() {
2856
2860
  return function(tables) {
2857
- var getType, getValue;
2861
+ var analyzeList, getType, getValue, lists;
2858
2862
  getType = function(id, accessorName, t, callback) {
2859
2863
  var fields;
2860
2864
  if (!tables.hasOwnProperty(id)) {
@@ -2887,11 +2891,30 @@ Gibbon.jsonConsumer = (function() {
2887
2891
  }
2888
2892
  return callback(null, entity[annotations.name]);
2889
2893
  };
2894
+ lists = tables._lists || {};
2895
+ analyzeList = function(id, listName, t, callback) {
2896
+ var list;
2897
+ if (!lists.hasOwnProperty(listName)) {
2898
+ callback(new Error("unkown list `" + listName + "'"));
2899
+ }
2900
+ list = lists[listName];
2901
+ if (id !== list.type) {
2902
+ callback(new Error("wrong type " + id + " for list `" + listName + "'"));
2903
+ }
2904
+ return callback(null, {
2905
+ type: t.concrete('bool'),
2906
+ annotations: {
2907
+ list: listName
2908
+ }
2909
+ });
2910
+ };
2890
2911
  return {
2891
2912
  analyzeQuery: function(id, query, t, callback) {
2892
2913
  switch (query.type) {
2893
2914
  case 'access':
2894
2915
  return getType(id, query.name, t, callback);
2916
+ case 'on':
2917
+ return analyzeList(id, query.name, t, callback);
2895
2918
  default:
2896
2919
  return callback(new Error("unknown query `" + query.type + "'"));
2897
2920
  }
@@ -1494,7 +1494,8 @@ Gibbon.TypeLookup = TypeLookup = (function(_super) {
1494
1494
 
1495
1495
  TypeLookup.types({
1496
1496
  response: ['analysis'],
1497
- local: ['name']
1497
+ local: ['name'],
1498
+ error: ['error']
1498
1499
  });
1499
1500
 
1500
1501
  return TypeLookup;
@@ -1775,9 +1776,10 @@ analyze = Gibbon.analyze = (function() {
1775
1776
  NativeContext.prototype.query = function(id, query, cb) {
1776
1777
  return this.externalLookup.call(null, id, query, TypeAST, function(err, analysis) {
1777
1778
  if (err) {
1778
- throw err;
1779
+ return cb(TypeLookup.error(err));
1780
+ } else {
1781
+ return cb(TypeLookup.response(analysis));
1779
1782
  }
1780
- return cb(TypeLookup.response(analysis));
1781
1783
  });
1782
1784
  };
1783
1785
 
@@ -1972,9 +1974,8 @@ analyze = Gibbon.analyze = (function() {
1972
1974
 
1973
1975
  TypeError.types({
1974
1976
  match: ['lhs', 'rhs'],
1975
- infinite: ['type'],
1976
1977
  destructure: ['type'],
1977
- access: ['type'],
1978
+ lookup: ['query', 'id', 'error'],
1978
1979
  circular: ['crumbs']
1979
1980
  });
1980
1981
 
@@ -2065,6 +2066,9 @@ analyze = Gibbon.analyze = (function() {
2065
2066
  return scope.lookup(id, query, function(lookup) {
2066
2067
  dependencies.push(lookup);
2067
2068
  return lookup.cases({
2069
+ error: function(e) {
2070
+ return cb(error('lookup', query, id, e));
2071
+ },
2068
2072
  response: function(analysis) {
2069
2073
  semanticAccessors.set(query, Semantic.query(analysis.annotations));
2070
2074
  return cb(TypeExpr.fromAST(analysis.type));
@@ -2826,7 +2830,7 @@ eval_ = Gibbon["eval"] = (function() {
2826
2830
  // Generated by CoffeeScript 1.6.3
2827
2831
  Gibbon.jsonConsumer = (function() {
2828
2832
  return function(tables) {
2829
- var getType, getValue;
2833
+ var analyzeList, getType, getValue, lists;
2830
2834
  getType = function(id, accessorName, t, callback) {
2831
2835
  var fields;
2832
2836
  if (!tables.hasOwnProperty(id)) {
@@ -2859,11 +2863,30 @@ Gibbon.jsonConsumer = (function() {
2859
2863
  }
2860
2864
  return callback(null, entity[annotations.name]);
2861
2865
  };
2866
+ lists = tables._lists || {};
2867
+ analyzeList = function(id, listName, t, callback) {
2868
+ var list;
2869
+ if (!lists.hasOwnProperty(listName)) {
2870
+ callback(new Error("unkown list `" + listName + "'"));
2871
+ }
2872
+ list = lists[listName];
2873
+ if (id !== list.type) {
2874
+ callback(new Error("wrong type " + id + " for list `" + listName + "'"));
2875
+ }
2876
+ return callback(null, {
2877
+ type: t.concrete('bool'),
2878
+ annotations: {
2879
+ list: listName
2880
+ }
2881
+ });
2882
+ };
2862
2883
  return {
2863
2884
  analyzeQuery: function(id, query, t, callback) {
2864
2885
  switch (query.type) {
2865
2886
  case 'access':
2866
2887
  return getType(id, query.name, t, callback);
2888
+ case 'on':
2889
+ return analyzeList(id, query.name, t, callback);
2867
2890
  default:
2868
2891
  return callback(new Error("unknown query `" + query.type + "'"));
2869
2892
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goodguide-gibbon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,21 +12,21 @@ cert_chain: []
12
12
  date: 2013-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- type: :runtime
16
15
  name: therubyracer
17
- prerelease: false
18
- requirement: !ruby/object:Gem::Requirement
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ none: false
19
18
  requirements:
20
19
  - - ! '>='
21
20
  - !ruby/object:Gem::Version
22
21
  version: '0'
22
+ requirement: !ruby/object:Gem::Requirement
23
23
  none: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
24
  requirements:
26
25
  - - ! '>='
27
26
  - !ruby/object:Gem::Version
28
27
  version: '0'
29
- none: false
28
+ type: :runtime
29
+ prerelease: false
30
30
  description: Run and analyze gibbon code from ruby or a browser (via a ruby app).
31
31
  email:
32
32
  - jjmadkisson@gmail.com
@@ -48,17 +48,23 @@ rdoc_options: []
48
48
  require_paths:
49
49
  - lib
50
50
  required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
51
52
  requirements:
52
53
  - - ! '>='
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
- none: false
56
+ hash: -2075265121022310565
57
+ segments:
58
+ - 0
56
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
57
61
  requirements:
58
62
  - - ! '>='
59
63
  - !ruby/object:Gem::Version
60
64
  version: '0'
61
- none: false
65
+ hash: -2075265121022310565
66
+ segments:
67
+ - 0
62
68
  requirements: []
63
69
  rubyforge_project: goodguide-gibbon
64
70
  rubygems_version: 1.8.23
@@ -66,4 +72,3 @@ signing_key:
66
72
  specification_version: 3
67
73
  summary: Ruby bindings for the gibbon data language
68
74
  test_files: []
69
- has_rdoc: