Class: Campa::Evaler
- Inherits:
-
Object
- Object
- Campa::Evaler
- Defined in:
- lib/campa/evaler.rb
Overview
All the actual logic on how to evaluate the differente known forms in implemented in here.
Instance Method Summary collapse
-
#call(expression, env = {}) ⇒ Object
Returns the result of a given form evaluation.
-
#eval(reader, env = {}) ⇒ Object
Receives a Reader object and evaluate all forms returned by each #next call.
-
#initialize ⇒ Evaler
constructor
A new instance of Evaler.
Constructor Details
Instance Method Details
#call(expression, env = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/campa/evaler.rb', line 22 def call(expression, env = {}) context = self.context(env) case expression when Numeric, TrueClass, FalseClass, NilClass, String, ::Symbol, List::EMPTY expression when Symbol resolve(expression, context) when List invoke(expression, context) end end |
#eval(reader, env = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/campa/evaler.rb', line 44 def eval(reader, env = {}) context = self.context(env) result = nil while (token = reader.next) result = call(token, context) end result end |