--
-- Copyright (c) 2012 Kevin Wellwood
-- All rights reserved.
--
-- This source code is distributed under the Modified BSD License. For terms and
-- conditions, see license.txt.
--
with Objects; use Objects;
with Scripting.Parsers; use Scripting.Parsers;
with Tokens.Scanners; use Tokens.Scanners;
package Scripting.Evaluators is
-- An Evaluator can parse and evaluate scripts and expressions. Currently
-- only expressions are supported for evaluation. Symbols and functions in
-- expressions are resolved by an object implementing the Evaluation_Node
-- 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;
pragma Postcondition( Create_Evaluator'Result /= null );
-- Evaluates the text of 'expression' and returns 'result'. Specify
-- 'evalNode' to evaluate symbols and functions 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. If an error occurs while evaluating symbols or functions
-- with the evaluation node, Evaluation_Exception will be raised.
function Evaluate_Expression( this : not null access Evaluator'Class;
expression : String;
evalNode : A_Evaluation_Node ) return Value_Ptr;
-- Evaluates a script in 'text', using 'resolver' and 'func_eval' as
-- necessary to resolve variable names and evaluate functions. A script is
-- simply a list of statements terminated by semicolons. If a parsing error
-- occurs then Parse_Exception will be raised. If an error occurs while
-- evaluating symbols or functions with the evaluation node,
-- Evaluation_Exception will be raised.
procedure Evaluate_Script( this : not null access Evaluator'Class;
text : String;
evalNode : A_Evaluation_Node );
-- Deletes the Evaluator.
procedure Delete( this : in out A_Evaluator );
pragma Postcondition( this = null );
private
type Evaluator is new Limited_Object with
record
scanner : A_Token_Scanner := Create_Token_Scanner;
parser : A_Parser := Create_Parser;
end record;
procedure Delete( this : in out Evaluator );
end Scripting.Evaluators;