Class: GoodGuide::Gibbon::Program
- Inherits:
-
Object
- Object
- GoodGuide::Gibbon::Program
- Defined in:
- lib/goodguide/gibbon.rb
Instance Attribute Summary collapse
-
#semantics ⇒ Object
readonly
Returns the value of attribute semantics.
-
#syntax ⇒ Object
readonly
Returns the value of attribute syntax.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #call(runtime_client, entity_id) ⇒ Object
-
#initialize(info = {}) ⇒ Program
constructor
A new instance of Program.
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
#semantics ⇒ Object (readonly)
Returns the value of attribute semantics.
81 82 83 |
# File 'lib/goodguide/gibbon.rb', line 81 def semantics @semantics end |
#syntax ⇒ Object (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
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_json ⇒ Object
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
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 |