with Expressions.Parsers; use Expressions.Parsers;
with Tokens.Scanners; use Tokens.Scanners;
package Expressions.Evaluators is
-- An Evaluator can parse and evaluate scripts and expressions. Currently
-- only expressions are supported for evaluation. Symbols in expressions
-- are resolved by an object implementing the Symbol_Resolver interface.
-- The Evaluator can be reused to perform multiple evaluations on different
-- input and it is recommended that objects not be created and deleted for
-- every evaluation, to limit overhead.
type Evaluator is new Limited_Object with private;
type A_Evaluator is access all Evaluator'Class;
-- Creates a new Evaluator to evaluate text script/expressions.
function Create_Evaluator return A_Evaluator;
-- Evaluates the text of 'expression' and returns 'result'. Specify
-- 'resolver' to resolve symbols by name during evaluation. If the
-- expression couldn't be evaluated due to a runtime error, null will be
-- returned. (For example, a variable couldn't be resolved or a value type
-- mismatch occured.) If a parsing error occurs then Parse_Exception will be
-- raised.
procedure Evaluate( this : not null access Evaluator'Class;
expression : String;
resolver : A_Symbol_Resolver;
result : in out A_Value );
-- Deletes the Evaluator.
procedure Delete( this : in out A_Evaluator );
private
type Evaluator is new Limited_Object with
record
scanner : A_Token_Scanner := Create_Token_Scanner;
parser : A_Expression_Parser := Create_Expression_Parser;
end record;
procedure Delete( this : in out Evaluator );
end Expressions.Evaluators;