Skip to main content

A Python package for parsing Cypher queries using ANTLR4.

Project description

antlr4-cypher

antlr4-cypher is a Python package that provides the Lexer and Parser for the Cypher query language, generated using ANTLR with the command java -jar antlr-4.13.2-complete.jar -Dlanguage=Python3 -listener -visitor CypherParser.g4. The project includes the necessary grammar, lexer, and parser files, as well as empty listener and visitor classes that serve as a reference for implementing custom logic.

Installation

You can install the package using pip:

pip install antlr4-cypher

Grammar Source

The grammar files (CypherLexer.g4 and CypherParser.g4) are sourced from the ANTLR grammars-v4 repository. These files define the syntax and structure of the Cypher query language.

Usage

To use the lexer and parser in your project, you can import them as follows:

from antlr4 import InputStream, CommonTokenStream
from antlr4_cypher import CypherLexer, CypherParser

# Example input
input_query = "MATCH (n) RETURN n"

# Create a lexer and parser
input_stream = InputStream(input_query)
lexer = CypherLexer(input_stream)
token_stream = CommonTokenStream(lexer)
parser = CypherParser(token_stream)

# Parse the input
tree = parser.cypher()

# Use the tree for further processing

Custom Listeners and Visitors

The package includes empty listener and visitor classes that you can extend to implement custom logic for traversing the parse tree. For example:

from antlr4_cypher import CypherListener

class MyCypherListener(CypherListener):
    def enterMatchSt(self, ctx):
        print("Entering MATCH clause")

    def exitMatchSt(self, ctx):
        print("Exiting MATCH clause")

This README provides a basic overview of the antlr4-cypher project. For more detailed information, please refer to the source code and the ANTLR documentation.

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

antlr4_cypher-0.1.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

antlr4_cypher-0.1.0-py3-none-any.whl (41.3 kB view details)

Uploaded Python 3

File details

Details for the file antlr4_cypher-0.1.0.tar.gz.

File metadata

  • Download URL: antlr4_cypher-0.1.0.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for antlr4_cypher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cbdae87152c7eb900e8a31ed094ae3e30d11a1a3e1b7ce57cc955b6a34adeba1
MD5 49182cefbbc880d96608f43f1db0c4e2
BLAKE2b-256 90bbf57fffebf17825dc359d721f049429f29c95820789240a9a95ef5988a581

See more details on using hashes here.

Provenance

The following attestation bundles were made for antlr4_cypher-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on qi-hua/antlr4-cypher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file antlr4_cypher-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: antlr4_cypher-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 41.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for antlr4_cypher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c11a4fd205342911e0c13382e0788f299dc5443c24920e3905be6e6e6ed5b87b
MD5 6f8fa47db12b7faecb230d099f4e05c0
BLAKE2b-256 99f4c7b84090e65f762e5d25a5d3db1c49aa49f1331147c3cfe11dc709859498

See more details on using hashes here.

Provenance

The following attestation bundles were made for antlr4_cypher-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on qi-hua/antlr4-cypher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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