Ejemplo n.º 1
0
        public BooleanExpression ParseFilter(string text, out IReadOnlyList <SqlParserError> errors)
        {
            ICharStream stream = CharStreams.fromstring(text);

            stream = new CaseChangingCharStream(stream);

            ITokenSource   lexer  = new KoraliumLexer(stream);
            ITokenStream   tokens = new CommonTokenStream(lexer);
            KoraliumParser parser = new KoraliumParser(tokens)
            {
                BuildParseTree = true
            };

            var errorsListener = new AntlrErrorListener();

            parser.AddErrorListener(errorsListener);

            var booleanExpression = parser.boolean_expression();

            errors = errorsListener.Errors;

            if (errors.Count > 0)
            {
                return(null);
            }

            var visitor = new AntlrVisitor();

            var result = visitor.Visit(booleanExpression) as BooleanExpression;

            return(result);
        }
Ejemplo n.º 2
0
        public StatementList Parse(string text, out IReadOnlyList <SqlParserError> errors)
        {
            ICharStream stream = CharStreams.fromstring(text);

            stream = new CaseChangingCharStream(stream);

            ITokenSource   lexer  = new KoraliumLexer(stream);
            ITokenStream   tokens = new CommonTokenStream(lexer);
            KoraliumParser parser = new KoraliumParser(tokens)
            {
                BuildParseTree = true
            };

            var errorsListener = new AntlrErrorListener();

            parser.AddErrorListener(errorsListener);

            var stmnt = parser.statements_list();

            errors = errorsListener.Errors;

            if (errors.Count > 0)
            {
                return(new StatementList());
            }

            var visitor = new AntlrVisitor();

            var statements = visitor.Visit(stmnt) as List <Statement>;

            return(new StatementList()
            {
                Statements = statements
            });
        }