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.
129 130 131 132 133 |
# File 'lib/goodguide/gibbon.rb', line 129 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.
128 129 130 |
# File 'lib/goodguide/gibbon.rb', line 128 def semantics @semantics end |
#syntax ⇒ Object (readonly)
Returns the value of attribute syntax.
128 129 130 |
# File 'lib/goodguide/gibbon.rb', line 128 def syntax @syntax end |
Class Method Details
.compile(source, info = {}) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/goodguide/gibbon.rb', line 110 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
135 136 137 138 139 140 |
# File 'lib/goodguide/gibbon.rb', line 135 def as_json { syntax: @syntax, semantics: @semantics, } end |
#call(runtime_client, entity_id) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/goodguide/gibbon.rb', line 142 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 |