Skip to content

Commit b86cf7f

Browse files
Replace grammar by antlr/grammars-v4's (#73)
1 parent bd4cae5 commit b86cf7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+366633
-83052
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,5 @@ Please also have a look at our documentation sections on [usage](https://pytsql.
5656

5757
## Credits
5858

59-
Inspiration drawn from [codebuff](https://github.com/antlr/codebuff/blob/master/grammars/org/antlr/codebuff/tsql.g4).
59+
Grammar is based on [antlr4/grammars-v4](https://github.com/antlr/grammars-v4/tree/master/sql/tsql).
6060

61-
Original authors:
62-
[Alex Gonopolskiy](https://github.com/agonopol)
63-
[Kevin Klein](https://github.com/kklein)
64-
[Encho Mishinev](https://github.com/EnchoMishinevQC)

docs/source/development.rst

+13-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Add the option ``--backend=mssql-freetds`` to the test command to run the tests
5656
the ``freetds`` driver.
5757

5858

59-
Creating a grammar
59+
Grammar
6060
------------------
6161

6262
``pytsql`` relies on parsing the sql script at hand. In order to do so, it uses
@@ -66,7 +66,13 @@ and produces parsing Python code.
6666
Additionally, code generated using ``speedy-antlr-tool`` package is used to parse SQL scripts
6767
in C++ for better performance. The parsed tree is then converted into the Python equivalent.
6868

69-
If you want to adapt the grammar please have a look at ``pytsql/src/pytsql/grammar/tsql.g4``.
69+
``pytsql``'s Transact-SQL (TSQL) grammar is based on `antlr/grammars-v4 <https://github.com/antlr/grammars-v4/tree/master/sql/tsql>`_.
70+
To keep the package structure lean, ``pytql`` aims to be in sync with the reference repository and generally does not maintain its own grammar.
71+
Therefore, if you want to extend or modify the grammar please consider contributing to the external repository instead.
72+
73+
Update targets
74+
^^^^^^^^^^^^^^^^^
75+
7076
All files in ``pytsql/src/pytsql/grammar/cpp_src/antlr4-cpp-runtime`` are taken directly from
7177
the `ANTLR repository release 4.11.1
7278
<https://github.com/antlr/antlr4/tree/4.11.1/runtime/Cpp/runtime>`_
@@ -79,8 +85,11 @@ respective ``antlr`` jar file as follows:
7985

8086
::
8187

82-
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Cpp -visitor -no-listener -o cpp_src tsql.g4
83-
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Python3 -no-visitor -no-listener -o . tsql.g4
88+
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Cpp -o cpp_src TSqlLexer.g4
89+
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Cpp -visitor -no-listener -o cpp_src TSqlParser.g4
90+
91+
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Python3 -o . TSqlLexer.g4
92+
java -jar /usr/local/lib/antlr-4.9.2-complete.jar -Dlanguage=Python3 -no-visitor -no-listener -o . TSqlParser.g4
8493

8594
And then running the ``speedy-antlr-tool`` in the same directory using Python
8695

environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ dependencies:
1717
- pyodbc
1818
- speedy-antlr-tool==1.4.1
1919
- antlr4-python3-runtime==4.11.1
20+
- click

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ description = "`Pytsql` allows to run mssql sripts, typically run via GUIs, via
88
authors = [
99
{name = "Alex Gonopolskiy", email = "[email protected]"},
1010
{name = "Kevin Klein", email = "[email protected]"},
11-
{name= "Encho Mishinev", email = "[email protected]"}
11+
{name= "Encho Mishinev", email = "[email protected]"},
12+
{name= "Sven Giegerich", email = "[email protected]"}
1213
]
1314

1415
maintainers = [{name = "Kevin Klein", email = "[email protected]"}]

src/pytsql/grammar/TSqlLexer.g4

+1,286
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)