Skip to main content

A transact sql parser, written in Antlr4

Project description

antlr-tsql

Build Status PyPI version

Development

ANTLR requires Java, so we suggest you use Docker when building grammars. The Makefile contains directives to clean, build, test and deploy the ANTLR grammar. It does not run Docker itself, so run make inside Docker.

# Build the docker container
docker build -t antlr_tsql .

# Run the container to build the python and js grammars
# Write parser files to local file system through volume mounting
docker run -it -v ${PWD}:/usr/src/app antlr_tsql make build

Now that the Python parsing files are available, you can install them with pip:

pip install -r requirements.txt
pip install -e .

And parse SQL code in Python:

from antlr_tsql import ast
ast.parse("SELECT a from b")

If you're actively developing on the ANLTR grammar or the tree shaping, it's a good idea to set up the AST viewer locally so you can immediately see the impact of your changes in a visual way.

  • Clone the ast-viewer repo and build the Docker image according to the instructions.
  • Spin up a docker container that volume mounts the Python package, symlink-installs the package and runs the server on port 3000:
docker run -it \
  -u root \
  -v ~/workspace/antlr-tsql:/app/app/antlr-tsql \
  -p 3000:3000 \
  ast-viewer \
  /bin/bash -c "echo 'Install development requirements in development:' \
    && pip install --no-deps -e app/antlr-tsql \
    && python3 run.py"

When simultaneously developing other packages, volume mount and install those too:

docker run -it \
  -u root \
  -v ~/workspace/antlr-ast:/app/app/antlr-ast \
  -v ~/workspace/antlr-plsql:/app/app/antlr-plsql \
  -v ~/workspace/antlr-tsql:/app/app/antlr-tsql \
  -p 3000:3000 \
  ast-viewer \
  /bin/bash -c "echo 'Install development requirements in development:' \
    && pip install --no-deps -e app/antlr-ast \
    && pip install --no-deps -e app/antlr-plsql \
    && pip install --no-deps -e app/antlr-tsql \
    && python3 run.py"
  • If you update the tree shaping logic in this repo, the app will auto-update.
  • If you change the grammar, you will have to first rebuild the grammar (with the antlr_tsql docker image) and restart the ast-viewer container.

Run tests

docker build -t antlr_tsql .
docker run -t antlr_tsql make build test

Travis deployment

  • Builds the Docker image.
  • Runs the Docker image to build the grammar and run the unit tests.
  • Deploys the resulting python and js files to PyPi when a new release is made, so they can be installed easily.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

antlr-tsql-0.11.0.tar.gz (246.8 kB view details)

Uploaded Source

File details

Details for the file antlr-tsql-0.11.0.tar.gz.

File metadata

  • Download URL: antlr-tsql-0.11.0.tar.gz
  • Upload date:
  • Size: 246.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6

File hashes

Hashes for antlr-tsql-0.11.0.tar.gz
Algorithm Hash digest
SHA256 f36da3d04b7812fb18155ecae900c434be769e82831e5a2b6e02947eaefc4f5f
MD5 80fb1094a9c77bc52a171012ace3fe1d
BLAKE2b-256 330f527f8d3a87ac6a31d6c2c8f00efaa21f4c15cc5ac29c554f17c8c891befb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page