示例#1
0
        static Expression ToExpression(string condition)
        {
            var errorListener = new ErrorListener();
            var input         = new AntlrInputStream(condition);
            var lexer         = new ConditionLexer(input);
            var tokens        = new CommonTokenStream(lexer);
            var parser        = new ConditionParser(tokens);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(errorListener);

            IParseTree tree = parser.condition();

            errorListener.Validate();

            ParameterExpression parameter = Expression.Parameter(typeof(IMessage), "message");

            var testRoute = new Route(
                Guid.NewGuid().ToString(),
                "true",
                nameof(ConditionVisitorTest),
                TelemetryMessageSource.Instance,
                new HashSet <Endpoint>());

            var visitor = new ConditionVisitor(parameter, errorListener, testRoute, RouteCompilerFlags.All);

            Expression result = visitor.Visit(tree);

            errorListener.Validate();
            return(result);
        }
示例#2
0
        static IParseTree GetParseTree(Route route, ErrorListener errorListener)
        {
            var input  = new AntlrInputStream(route.Condition);
            var lexer  = new ConditionLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new ConditionParser(tokens);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(errorListener);

            return(parser.condition());
        }