1
votes

Here is the Antlr grammar file for PLSQL.

However, it is not completely correct. For example, I have a package that starts with:

CREATE OR REPLACE PACKAGE BODY SCHEMA_NAME.PACKAGE_NAME AS

The parser generated from the preceding grammar file does not parse SCHEMA_NAME.PACKAGE_NAME as the package_name (package_name is an Antlr parser rule).

To fix this, I have changed this

package_name
    : id
    ;

To this

package_name
    : id ('.' id)?
    ;

I have also tried

package_name
    : id ('.' id_expression)?
    ;

but none of them worked. Antlr still won't include the last .PACKAGE_NAME part in the package name.

Why is this not working? How can I fix this?

1
If the rest of the rules are any indication, you actually want : id ('.' id_expression)? (though that shouldn't change what's being recognized in this case). - Jeroen Mostert
@JeroenMostert I have tried that too. That didn't work either. - Utku
I would say, it is not working because it is a port of Antlr3 grammar. And it is not finished yet. Another problem with this grammar is, that it is trying to parse PL/SQL, SQL and DDL language at once. But these grammars should use different Lexer beneath. - ibre5041

1 Answers

1
votes

Such package definition:

package_name
    : id ('.' id_expression)?
    ;

is working well with the next PL/SQL query:

CREATE OR REPLACE PACKAGE BODY SCHEMA_NAME.PACKAGE_NAME AS END;

I suppose you forgot END and semicolon at the end.

Also, if you find a bug, please add an issue or pull request to an official ANTLR grammars repository, because of this PL/SQL grammar is not completed as it has been already mentioned in comment.