コード例 #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 void ParseJsonPath(string jsonPath, ErrorListener errorListener)
        {
            var input = new AntlrInputStream(jsonPath);

            var lexer  = new JsonPathLexer(input);
            var tokens = new CommonTokenStream(lexer);
            var parser = new JsonPathParser(tokens);

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

            parser.jsonpath();
            errorListener.Validate();
        }
コード例 #3
0
ファイル: RouteFactory.cs プロジェクト: wpxdong/iotedge
        internal void ParseRoute(string routeString, out IMessageSource messageSource, out string condition, out Endpoint endpoint)
        {
            var errorListener = new ErrorListener();
            var input         = new AntlrInputStream(routeString);
            var lexer         = new RouteLexer(input);
            var tokens        = new CommonTokenStream(lexer);
            var parser        = new RouteParser(tokens);

            parser.RemoveErrorListeners();
            parser.AddErrorListener(errorListener);
            IParseTree tree = parser.route();

            errorListener.Validate();

            var walker   = new ParseTreeWalker();
            var listener = new RouteParserListener(this.endpointFactory);

            walker.Walk(listener, tree);

            condition     = listener.Condition ?? DefaultCondition;
            messageSource = CustomMessageSource.Create(listener.Source);
            endpoint      = listener.Endpoint;
        }