Пример #1
0
        private static EvaluatorState Evaluate(string statement, string prompt)
        {
            Console.WriteLine();

            if (string.IsNullOrWhiteSpace(statement))
            {
                return(null);
            }

            VariableResolver resolver = new VariableResolver();

            var tokens = tokenizer.Tokenize(statement);
            var ast    = parser.Parse(tokens);

            var variables = resolver.Resolve(ast);

            foreach (var resolved in variables)
            {
                var nestedPrompt = $"{resolved.Key} = ";

                var stmt  = ProcessKeyEvents(nestedPrompt);
                var value = Evaluate(stmt, nestedPrompt);

                printer.Print(new Run()
                {
                    Text = "  --------", Color = RunColor.White
                });

                var existing = variables[resolved.Key];

                existing.IsSigned = value.IsSigned;
                existing.Type     = value.Type;
                existing.Value    = value.Value;
            }

            var result = evaluator.Evaluate(ast, variables, printer, context);

            return(result);
        }
Пример #2
0
 public static string ResolveValue(this TestCaseContext testCaseContext, string value)
 {
     return(VariableResolver.Resolve(value, item => testCaseContext.GetRequiredItem(item)));
 }
Пример #3
0
 public void ResolveFuncThrows(string value)
 {
     Assert.That(() => VariableResolver.Resolve(value, (key) => throw new KeyNotFoundException()), Throws.InstanceOf <KeyNotFoundException>());
 }
Пример #4
0
 public void ResolveThrows(string value)
 {
     Assert.That(() => VariableResolver.Resolve(value, (key) => _variables[key]), Throws.InstanceOf <ArgumentException>());
 }
Пример #5
0
 public string ResolveFormatSucceeds(string value)
 {
     return(VariableResolver.Resolve(value, key => _variables2[key]));
 }
Пример #6
0
 public static string Resolve(this IItemsHolder pipelineContext, string value)
 {
     return(VariableResolver.Resolve(value, (key) => pipelineContext.GetRequiredItem(key)));
 }