Antlr PLSQL, How to get positions of expressions

53 Views Asked by At

I want to use the antlr PLSQL parser to manipulate my sql code that comes from Oracle Forms.

Therefore I created all needed Java classes and now have this Main code that works fine:

CharStream charStream = CharStreams.fromString("CREATE FUNCTION totalCustomers \r\n"
                + "RETURN number IS \r\n"
                + "   total number(2) := 0; \r\n"
                + "BEGIN \r\n"
                + "   SELECT count(*) into total \r\n"
                + "   FROM customers; \r\n"
                + "   RETURN total; \r\n"
                + "END; ");

PlSqlLexer plSqlLexer = new PlSqlLexer(charStream2);
        
CommonTokenStream commonTokenStream = new CommonTokenStream(plSqlLexer);
        
PlSqlParser plSqlParser = new PlSqlParser(commonTokenStream);

PlSqlParser.Create_function_bodyContext sql_scriptContext = plSqlParser.create_function_body();

I can get the number of Syntax errors and the child nodes of the parse tree. But i wonder how to get specific positions (Character positions) of certain expressions.

I cant find anything about that in the internet, but I know that antlr is able to do this.

Does anybody know something about that?

I looked at all methods that the PLSQLParser offers, but none of them seems like they are helping me.

0

There are 0 best solutions below