Пример #1
0
        public static Expression <Func <T1, T2> > Apply <T1, T2, T3>(this Expression <Func <T1, T2, T3> > expression, T1 value)
        {
            var visitor = new SampleVisitor(expression.Parameters[0], Expression.Constant(value, typeof(T1)));

            var result = Expression.Lambda <Func <T1, T2> >(
                visitor.Visit(expression.Body),
                expression.Parameters.Skip(1)
                );

            return(result);
        }
Пример #2
0
        public ScopeContext RunCode(string code)
        {
            var logger = NullLogger.Instance;

            var inputStream       = new AntlrInputStream(code);
            var speakLexer        = new SimpleGrammarLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(speakLexer);
            var parser            = new SimpleGrammarParser(commonTokenStream);

            parser.AddErrorListener(new EL());

            var chatContext = parser.calc();

            var visitor = new SampleVisitor(logger);

            visitor.Visit(chatContext);

            return(visitor.ReturnResult);
        }
Пример #3
0
        public void ExecuteCode()
        {
            var inputStream       = new AntlrInputStream(_code);
            var speakLexer        = new SimpleGrammarLexer(inputStream);
            var commonTokenStream = new CommonTokenStream(speakLexer);
            var parser            = new SimpleGrammarParser(commonTokenStream);

            parser.AddErrorListener(new EL(_logger));

            var chatContext = parser.calc();

            var visitor = new SampleVisitor(_logger);

            try
            {
                visitor.Visit(chatContext);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            _logger.LogDebug(visitor.ReturnResult.Value?.ToString() ?? "");
        }