private LambdaExpression ParseActionExpression(Rule_actionContext context, IEnumerable <ParameterExpression> parameters)
 {
     using (_parserContext.PushScope())
     {
         var expressionParser = new ExpressionParser(_parserContext);
         var block            = expressionParser.Visit(context.statement_list());
         var lambda           = Expression.Lambda(block, parameters);
         return(lambda);
     }
 }
Esempio n. 2
0
        public override void EnterRule_action(Rule_actionContext context)
        {
            var contextParameter = Expression.Parameter(typeof(IContext), "context");
            var parameters       = new List <ParameterExpression> {
                contextParameter
            };

            parameters.AddRange(_parserContext.Scope.Values);

            using (_parserContext.PushScope())
            {
                var expressionParser = new ExpressionParser(_parserContext);
                var block            = expressionParser.Visit(context.statement_list());
                var lambda           = Expression.Lambda(block, parameters);
                _actionGroupBuilder.DslAction(_actionGroupBuilder.Declarations, lambda);
            }
        }
        public override void EnterRule_action(Rule_actionContext context)
        {
            var contextParameter = Expression.Parameter(typeof(IContext), "Context");
            var parameters       = new List <ParameterExpression> {
                contextParameter
            };

            parameters.AddRange(_parserContext.Scope.Declarations);

            using (_parserContext.PushScope())
            {
                _parserContext.Scope.Declare(contextParameter);

                var lambda = ParseActionExpression(context, parameters);
                _actionGroupBuilder.DslAction(_parserContext.Scope.Declarations, lambda);
            }
        }