Ejemplo n.º 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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
0
        public static void ProcessRepl(ReplEngineBase engine, Guid sessionId)
        {
            StringBuilder inputString = null;

            while (inputString == null || inputString.ToString().ToLower().TrimEnd() != "exit")
            {
beginOfTheLoop:
                _console.WriteInfo("> ");
                bool isSubmissionCompleted = false;
                inputString = new StringBuilder("");

                //Read
                do
                {
                    inputString.AppendLine(_console.In.ReadLine());
                    if (inputString.ToString().Trim() == "#reset")
                    {
                        engine.Reset(typeof(Program).Assembly);
                        goto beginOfTheLoop;
                    }
                    else if (inputString.ToString().Trim() == "#replay")
                    {
                        engine.ReplayAll();
                        goto beginOfTheLoop;
                    }
                    var analyzer = new ReplAnalyzerCS(inputString.ToString());
                    isSubmissionCompleted = analyzer.IsCompleteSubmission();
                    if (!isSubmissionCompleted)
                    {
                        _console.WriteInfo(".\t");
                    }
                    var compilation = (engine as ReplEngineCS)
                                      .GetAndContinueScriptSession(inputString.ToString())
                                      .Item1
                                      .GetCompilation();
                } while (!isSubmissionCompleted);

                //Eval
                var evalResult = engine.Eval(inputString.ToString());

                //Print
                if (evalResult == null)
                {
                    continue;
                }

                if (!evalResult.HasError && !evalResult.HasWarnings)
                {
                    if (!string.IsNullOrEmpty(evalResult.ToString()))
                    {
                        _console.Out.WriteLine(evalResult);
                    }
                }

                foreach (var d in evalResult.Diagnostics)
                {
                    switch (d.Severity)
                    {
                    case DiagnosticSeverity.Error:
                        _console.WriteErrorLine(d.Message as Object);
                        break;

                    case DiagnosticSeverity.Warning:
                        _console.WriteWarningLine(d.Message as Object);
                        break;

                    default:
                        _console.WriteLineInfo(d.Message as Object);
                        break;
                    }
                }
            }
        }