I using the following Antlr4 PLSQL grammar files:
https://github.com/antlr/grammars-v4/tree/master/sql/plsql.
From here I downloaded as follows:
wget https://github.com/antlr/grammars-v4/blob/master/sql/plsql/Python3/PlSqlLexerBase.pywget https://github.com/antlr/grammars-v4/blob/master/sql/plsql/Python3/PlSqlParserBase.pywget https://github.com/antlr/grammars-v4/blob/master/sql/plsql/PlSqlLexer.g4wget https://github.com/antlr/grammars-v4/blob/master/sql/plsql/PlSqlParser.g4mv PlSql*g4 grammarswget https://www.antlr.org/download/antlr-4.13.1-complete.jarmv antlr-4.13.1-complete.jar libGiving me :
├── lib│ ├── antlr-4.13.1-complete.jar├── grammars1│ ├── PlSqlLexer.g4│ └── PlSqlParser.g4├── PlSqlLexer.g4├── PlSqlParser.pyWhen I then run:
java -jar ./lib/antlr-4.9.3-complete.jar -Dlanguage=Python3 grammars/*g4I get the following generated in grammars:
grammars-v4-master PlSqlLexer.interp PlSqlParserBase.py PlSqlParserListener.py __pycache__master.zip PlSqlLexer.py PlSqlParser.g4 PlSqlParser.py runPLSQL.pyPlSqlLexer.g4 PlSqlLexer.tokens PlSqlParser.interp PlSqlParser.tokensI then create the runPLSQL.py Python script :
cd grammarspython3 runPLSQL.py ../../plsql/test.sqlBut this errored with:
import pandasTraceback (most recent call last): File "/home/me/try2/grammars/runPLSQL.py", line 11, in <module> from PlSqlParserListener import PlSqlParserListener File "/home/me/try2/grammars/PlSqlParserListener.py", line 6, in <module> from PlSqlParser import PlSqlParser File "/home/me/try2/grammars/PlSqlParser.py", line 14, in <module> from PlSqlParserBase import PlSqlParserBase File "/home/me/try2/grammars/PlSqlParserBase.py", line 1, in <module> {"payload":{"allShortcutsEnabled":false,"fileTree":{"sql/plsql/Python3":{"items":[{"name":"PlSqlLexerBase.py","path":"sql/plsql/Python3/PlSqlLexerBase.py","contentType":"file"}NameError: name 'false' is not defined. Did you mean: 'False'?I had to edit the PlSqlLexerBase.py file as below to overcome this and similar errors:
- Replace
:falsewith:False - Replace
:truewith:True - Replace
:nullwith:None
But now I get this:
import pandasTraceback (most recent call last): File "/home/me/try2/grammars/runPLSQL.py", line 11, in <module> from PlSqlParserListener import PlSqlParserListener File "/home/me/try2/grammars/PlSqlParserListener.py", line 6, in <module> from PlSqlParser import PlSqlParser File "/home/me/try2/grammars/PlSqlParser.py", line 14, in <module> from PlSqlParserBase import PlSqlParserBaseImportError: cannot import name 'PlSqlParserBase' from 'PlSqlParserBase' (/home/me/try2/grammars/PlSqlParserBase.py)The PlSqlParserBase.py script starts with:
{"payload":{"allShortcutsEnabled":False,"fileTree":{"sql/plsql/Python3":{"items":[{"name":"PlSqlLexerBase.py","path":"sql/plsql/Python3/PlSqlLexerBase.py","contentType":"file"},{"name":"PlSqlParserBase.py","path":"sql/plsql/Python3/PlSqlParserBase.py","contentType":"file"}],"totalCount":2},"sql/plsql":{"items":[{"name":"CSharp","path":"sql/plsql/CSharp","contentTy......I notice it references relative pathnames, should all the paths/files exist?
The top of the runPLSQL.py script is:
import osimport pandasfrom antlr4 import InputStream, ParseTreeWalkerfrom antlr4.CommonTokenStream import CommonTokenStreamfrom pandas import DataFrame#from PlSql.grammar.PlSqlListener import PlSqlListener#from PlSql.grammar.PlSqlLexer import PlSqlLexer#from PlSql.grammar.PlSqlParser import PlSqlParserfrom PlSqlParserListener import PlSqlParserListenerfrom PlSqlLexer import PlSqlLexerfrom PlSqlParser import PlSqlParserfrom tabulate import tabulateclass SQLParser(PlSqlListener):