Exemple #1
0
        public static T Parse(string query, IExpressionBuilder <T> expressionBuilder)
        {
            var lexer         = new RsqlLexer(new AntlrInputStream(query));
            var tokenStream   = new CommonTokenStream(lexer);
            var rsqlParser    = new RsqlParser(tokenStream);
            var tree          = rsqlParser.expression();
            var rsqlStatement = new RsqlExpressionVisitor <T>(expressionBuilder).Visit(tree);

            return(rsqlStatement);
        }
Exemple #2
0
        public static Expression <Func <T, bool> > GetRsqlPredicate <T>(string?rsql, ComparisonBuilder comparisonBuilder)
        {
            comparisonBuilder = comparisonBuilder ?? throw new ArgumentNullException(nameof(comparisonBuilder));
            if (string.IsNullOrWhiteSpace(rsql))
            {
                throw new ArgumentNullException(nameof(rsql));
            }

            var antlrInputStream  = new AntlrInputStream(rsql);
            var lexer             = new RsqlLexer(antlrInputStream);
            var commonTokenStream = new CommonTokenStream(lexer);
            var parser            = new RsqlParser(commonTokenStream);
            var visitor           = new RsqlVisitor <T>(comparisonBuilder);
            var predicate         = visitor.Visit(parser.start());

            return(predicate);
        }