goodguide-gibbon 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6149450d065a995f3529ce090e46660c767b3528
4
- data.tar.gz: dc185cb13befd7689de9ab2529e87d4c76ef0a55
3
+ metadata.gz: c8b34db5c0525825c475f7d18109f8ffc5518e53
4
+ data.tar.gz: 9db9f664a974da99e90ad45855d9d42b91656a1d
5
5
  SHA512:
6
- metadata.gz: 35a60f8887b78d4b9c17991671e7c75b5fc312ba525357baf56ffaec5429a40ada1fe8534d4d119429366e813a32f77170a134464167f95fce7149c25e6e0b1c
7
- data.tar.gz: 111d9117a247e4961f1b0e4904454ecc4023162a89c54340f62a99b8e07e580279d16bd0bd5aaf091895ce8d083de726917434aaf1408ce256c95ba0bb7821e0
6
+ metadata.gz: 271a7ede66936d1e02e5eaf6852f8c78948fc4b989d6c4bc377ee1c34bde960ccbb16253db765e8e51595c1434639d0c1392181df31a137f05d6ca6ee55ef683
7
+ data.tar.gz: bf95e7975d0abec0c15131733ec04a38471f7c05d505d2aac0631081f774c65601d9efee3dd8de2f6d4caa26c87252c0033ce482e1ae4f332f0849f63d1533a0
@@ -173,6 +173,17 @@ module GoodGuide
173
173
  end
174
174
  end
175
175
 
176
+ class ParseError < SemanticError
177
+ attr_reader :message
178
+ def initialize(message)
179
+ @message = message.to_s
180
+ end
181
+
182
+ def messages
183
+ [message]
184
+ end
185
+ end
186
+
176
187
  class GibbonError < StandardError
177
188
  def to_js(gibbon)
178
189
  raise "abstract"
@@ -351,7 +362,17 @@ module GoodGuide
351
362
  end
352
363
 
353
364
  def to_js(gibbon)
354
- { :analyzeQuery => proc_for(gibbon, :analyze_query) }
365
+ analyze_proc = proc do |*args|
366
+ args.shift unless defined?(JRUBY_VERSION)
367
+
368
+ begin
369
+ { :success => true, :analysis => analyze_query(*args) }
370
+ rescue GibbonError => e
371
+ { :success => false, :error => e.to_js(gibbon) }
372
+ end
373
+ end
374
+
375
+ { :analyzeQuery => analyze_proc }
355
376
  end
356
377
  end
357
378
 
@@ -450,10 +471,6 @@ module GoodGuide
450
471
  def add_dependency!(key, dep)
451
472
  (@dependencies[key] ||= []) << dep
452
473
  end
453
-
454
- def to_js(gibbon)
455
- { :performQuery => proc_for(gibbon, :perform_query) }
456
- end
457
474
  end
458
475
 
459
476
  class Context
@@ -478,7 +495,7 @@ module GoodGuide
478
495
  def parse(str)
479
496
  obj_to_ruby self.gibbon.parse(str)
480
497
  rescue JSError => e
481
- raise SemanticError.new([{'_tag' => 'parse', 'message' => e.value}], self)
498
+ raise ParseError.new(e.value)
482
499
  end
483
500
 
484
501
  def compile(semantics)
@@ -489,39 +506,26 @@ module GoodGuide
489
506
  obj_to_ruby(gibbon.compileRuby(obj_to_js(semantics)))
490
507
  end
491
508
 
492
- def analyze(syntax, global_table, static_client)
493
- syntax = obj_to_js(syntax)
509
+ if defined?(JRUBY_VERSION)
510
+ def unwrap_error(e)
511
+ return e unless e.respond_to?(:value) and e.value.is_a? Rhino::Ruby::Object
494
512
 
495
- out = capture do |&callback|
496
- gibbon.analyze(syntax, global_table, static_client, callback)
513
+ e.value.unwrap
514
+ end
515
+ else
516
+ def unwrap_error(e)
517
+ e
497
518
  end
498
-
499
- obj_to_ruby(out)
500
519
  end
501
520
 
502
- private
503
- def capture(&b)
504
- callback_args = nil
505
- call_count = 0
506
-
507
- b.call do |*args|
508
- # Rhino doesn't get "this", but V8 does.
509
- args.shift unless defined?(JRUBY_VERSION)
510
-
511
- call_count += 1
512
-
513
- if call_count >= 2
514
- first = callback_args.inspect
515
- second = args.inspect
516
- raise "gibbon: callback called twice with #{first} and #{second}"
517
- end
518
-
519
- callback_args = args
520
- end
521
+ def analyze(syntax, global_table, static_client)
522
+ syntax = obj_to_js(syntax)
521
523
 
522
- raise "gibbon: callback never called" unless call_count >= 1
524
+ result = gibbon.analyze(syntax, global_table, static_client)
523
525
 
524
- callback_args
526
+ [ obj_to_ruby(result[:errors]), obj_to_ruby(result[:semantics]) ]
527
+ rescue => e
528
+ raise unwrap_error(e)
525
529
  end
526
530
  end
527
531