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.



149
150
151
152
153
# File 'lib/goodguide/gibbon.rb', line 149

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.



148
149
150
# File 'lib/goodguide/gibbon.rb', line 148

def semantics
  @semantics
end

#syntaxObject (readonly)

Returns the value of attribute syntax.



148
149
150
# File 'lib/goodguide/gibbon.rb', line 148

def syntax
  @syntax
end

Class Method Details

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

Raises:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/goodguide/gibbon.rb', line 130

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



155
156
157
158
159
160
# File 'lib/goodguide/gibbon.rb', line 155

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

#call(runtime_client, entity_id) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
# File 'lib/goodguide/gibbon.rb', line 162

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

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

  raise error if error
  values
end