Beispiel #1
0
        /// <summary>
        /// Parses one single Expression-Block
        /// </summary>
        /// <param name="expression">the target expression to execute</param>
        /// <param name="implicitContext">implicit context that is used for the interpreter-session that is used for the codeblock</param>
        /// <param name="scopeInitializer">an initializer that can be used to provide special methods and values to the initial scope</param>
        /// <returns>the evaluation result</returns>
        public static object ParseBlock(string expression, object implicitContext, InitializeScopeVariables scopeInitializer = null)
        {
            ScriptVisitor visitor;

            using (var session = InterpreterBuffer.GetReplInstance(implicitContext, scopeInitializer, out visitor))
            {
                return(ParseBlock(expression, session));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Parses one single Expression
        /// </summary>
        /// <param name="expression">the target expression to execute</param>
        /// <param name="variables">the initial variables that are provided to the expression</param>
        /// <param name="scopeInitializer">an initializer that can be used to provide special methods and values to the initial scope</param>
        /// <returns>the evaluation result</returns>
        public static object Parse(string expression, IDictionary <string, object> variables, InitializeScopeVariables scopeInitializer = null)
        {
            ScriptVisitor visitor;

            using (var session = InterpreterBuffer.GetReplInstance(variables, scopeInitializer, out visitor))
            {
                return(Parse(expression, session));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Excecutes a Script
        /// </summary>
        /// <param name="variables">the initial variables for the script</param>
        /// <param name="prepareVariables">a callback that will be used in order to initialize lazy-evaluation variable values</param>
        /// <returns>the return value that was generated by the script</returns>
        public TOutput Execute(IDictionary <string, object> variables, InitializeScopeVariables prepareVariables)
        {
            ScriptVisitor            visitor;
            InitializeScopeVariables dff = prepareVariables ??
                                           (a =>
            {
                DefaultCallbacks.PrepareDefaultCallbacks(a.Scope, a.ReplSession);
            });
            InitializeScopeVariables newInitializer = args =>
            {
                PreparePowerCalls(args.Scope, prepareVariables, args.Visitor);
                dff(args);
            };

            using (var session = InterpreterBuffer.GetReplInstance(variables, newInitializer, out visitor))
            {
                // todo: reactivate
                return(Execute(session));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Begins a repl - session
        /// </summary>
        /// <param name="baseValues">the base values that are used for the current session</param>
        /// <param name="scopePreparer">a callback that is used to prepare the repl session variables</param>
        /// <returns>a value that can be used to end this repl - session</returns>
        public static IDisposable BeginRepl(IDictionary <string, object> baseValues, InitializeScopeVariables scopePreparer)
        {
            ScriptVisitor visitor;

            return(InterpreterBuffer.GetReplInstance(baseValues, scopePreparer, out visitor));
        }