Class: GoodGuide::Gibbon::Context

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/goodguide/gibbon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#hash_to_ruby, #obj_to_js, #obj_to_ruby

Constructor Details

#initialize(js = {}) ⇒ Context

Returns a new instance of Context.



498
499
500
501
502
503
504
505
506
# File 'lib/goodguide/gibbon.rb', line 498

def initialize(js={})
  if js.is_a? Hash
    js = JS.new(js)
  end

  @js = js
  @defer = js[:setTimeout]
  @gibbon = js.gibbon
end

Instance Attribute Details

#gibbonObject (readonly)

Returns the value of attribute gibbon.



496
497
498
# File 'lib/goodguide/gibbon.rb', line 496

def gibbon
  @gibbon
end

#jsObject (readonly)

Returns the value of attribute js.



497
498
499
# File 'lib/goodguide/gibbon.rb', line 497

def js
  @js
end

Instance Method Details

#analyze(syntax, global_table, static_client) ⇒ Object



538
539
540
541
542
543
544
545
546
# File 'lib/goodguide/gibbon.rb', line 538

def analyze(syntax, global_table, static_client)
  syntax = obj_to_js(syntax)

  result = gibbon.analyze(syntax, global_table, static_client)

  [ obj_to_ruby(result[:errors]), obj_to_ruby(result[:semantics]) ]
rescue => e
  raise unwrap_error(e)
end

#compile(semantics) ⇒ Object



518
519
520
# File 'lib/goodguide/gibbon.rb', line 518

def compile(semantics)
  gibbon.compile(obj_to_js(semantics))
end

#compile_ruby(semantics) ⇒ Object



522
523
524
# File 'lib/goodguide/gibbon.rb', line 522

def compile_ruby(semantics)
  obj_to_ruby(gibbon.compileRuby(obj_to_js(semantics)))
end

#loggerObject



508
509
510
# File 'lib/goodguide/gibbon.rb', line 508

def logger
  js.logger
end

#parse(str) ⇒ Object



512
513
514
515
516
# File 'lib/goodguide/gibbon.rb', line 512

def parse(str)
  obj_to_ruby self.gibbon.parse(str)
rescue JSError => e
  raise ParseError.new(e.value)
end

#unwrap_error(e) ⇒ Object



527
528
529
530
531
# File 'lib/goodguide/gibbon.rb', line 527

def unwrap_error(e)
  return e unless e.respond_to?(:value) and e.value.is_a? Rhino::Ruby::Object

  e.value.unwrap
end