Class: GoodGuide::Gibbon::Program

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info = {}) ⇒ Program

Returns a new instance of Program.



82
83
84
85
86
# File 'lib/goodguide/gibbon.rb', line 82

def initialize(info={})
  @syntax = info[:syntax]
  @semantics = info[:semantics]
  @context = info[:context] || Context.new
end

Instance Attribute Details

#semanticsObject (readonly)

Returns the value of attribute semantics.



81
82
83
# File 'lib/goodguide/gibbon.rb', line 81

def semantics
  @semantics
end

#syntaxObject (readonly)

Returns the value of attribute syntax.



81
82
83
# File 'lib/goodguide/gibbon.rb', line 81

def syntax
  @syntax
end

Class Method Details

.compile(source, info = {}) ⇒ Object

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/goodguide/gibbon.rb', line 63

def self.compile(source, info={})
  client = info[:client] || raise('please pass a static client')
  global = info[:global] || raise('please pass a global table id')

  context = info[:context] || Context.new

  syntax = context.parse(source)
  semantics, errors = context.analyze(syntax, global, client.to_js)

  raise SemanticError.new(errors) if errors

  Program.new(
    :syntax => syntax,
    :semantics => semantics,
    :context => context,
  )
end

Instance Method Details

#as_jsonObject



88
89
90
91
92
93
# File 'lib/goodguide/gibbon.rb', line 88

def as_json
  {
    syntax: @syntax,
    semantics: @semantics,
  }
end

#call(runtime_client, entity_id) ⇒ Object

Raises:



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/goodguide/gibbon.rb', line 95

def call(runtime_client, entity_id)
  # TODO
  context = Context.new

  values, error = context.eval_gibbon(
    self.semantics, entity_id, runtime_client.to_js
  )

  raise RuntimeError.new(error) if error
  values
end