Beispiel #1
0
        public EvalResult EvalCS(EvalRequest request)
        {
            var analyzer = new ReplAnalyzerCS(request.Code);

            if (!analyzer.IsCompleteSubmission())
            {
                return(EvalResult.Error(request.SessionId, "Submission is not completed!"));
            }
            var engine = ReplFactory.GetCSEngine(request.SessionId, e => {
                e.InitEngineWithAssembly(typeof(ReplService).Assembly);
            });

            return(engine.Eval(request.Code));
        }
        protected override EvalResult EvalImpl(ScmEnvironment env)
        {
            var exp = @Operator.Eval(env).Value;

            if (exp is ProcedureExpression)
            {
                var    proc = exp as ProcedureExpression;
                object ve;

                object[] mappedOperands;
                if (proc.Proc is PrimitiveProcedure)
                {
                    mappedOperands =
                        Arguments.Select(x => x.Eval(env).Value)
                        .OfType <SelfEvaluatingExpression>()
                        .Select(x => x.Value)
                        .ToArray();
                }
                else
                {
                    mappedOperands = MapValues(Arguments, env);
                }

                var applyResult = proc.Proc.Apply(mappedOperands);
                if (applyResult.Success)
                {
                    return(new SelfEvaluatingExpression(applyResult.Value).ToResult());
                }
                else
                {
                    string msg = "";
                    if (@Operator is VariableExpression)
                    {
                        string procedureName = (@Operator as VariableExpression).VariableName;
                        msg = String.Format("Error while applying procedure {0}:{1}", procedureName,
                                            Environment.NewLine);
                    }

                    return(EvalResult.Error(msg + applyResult.ErrorMessage));
                }
            }
            else if (exp is ApplicationExpression)
            {
                var application = exp as ApplicationExpression;
                return(application.Eval(env));
            }

            return(exp.ToResult());
        }
Beispiel #3
0
        public EvalResult ValidateCS(EvalRequest request)
        {
            var analyzer = new ReplAnalyzerCS(request.Code);

            if (!analyzer.IsCompleteSubmission())
            {
                return(EvalResult.Error(request.SessionId, "Submission is not completed!"));
            }
            var engine = ReplFactory.GetCSEngine(request.SessionId, e => {
                e.InitEngineWithAssembly(typeof(ReplService).Assembly);
            });
            var diagnostics = engine.Validate(request.Code, out var script, out var scriptState);
            var hasErrors   = diagnostics.Any(x => x.Severity == DiagnosticSeverity.Error || (x.Severity == DiagnosticSeverity.Warning && x.IsWarningAsError));
            var diagResult  = diagnostics.Select(x => new DiagnosticsResult(x.ToString(), x.Severity)).ToList();

            return(EvalResult.Instance(request.SessionId, string.Empty, diagResult, hasErrors));
        }