Skip to main content

A comprehensive static analysis linter for ANTLR v4 grammar files

Project description

ANTLR v4 Grammar Linter

A comprehensive static analysis linter for ANTLR v4 grammar files (.g4) that identifies common issues, enforces best practices, and improves grammar quality and maintainability.

Features

  • 24 Built-in Rules across 8 categories
  • Configurable Rule Severity and thresholds
  • Multiple Output Formats (JSON, XML, text, SARIF)
  • Auto-fixing capabilities for deterministic issues
  • CLI and Programmatic APIs
  • IDE Integration ready

Installation

pip install antlr-v4-linter

Quick Start

# Lint a single grammar file
antlr-lint MyGrammar.g4

# Lint multiple files
antlr-lint src/**/*.g4

# Custom configuration
antlr-lint --config antlr-lint.json MyGrammar.g4

# JSON output
antlr-lint --format json MyGrammar.g4

Rule Categories

  1. Syntax and Structure (S001-S003)
  2. Naming and Convention (N001-N003)
  3. Labeling and Organization (L001-L003)
  4. Complexity and Maintainability (C001-C003)
  5. Token and Lexer (T001-T003)
  6. Error Handling (E001-E002)
  7. Performance (P001-P002)
  8. Documentation (D001-D002)

Configuration

Create an antlr-lint.json file:

{
  "rules": {
    "S001": { "enabled": true, "severity": "error" },
    "N001": { "enabled": true, "severity": "error" },
    "C001": { 
      "enabled": true, 
      "severity": "warning",
      "thresholds": {
        "maxAlternatives": 10,
        "maxNestingDepth": 5,
        "maxTokens": 50
      }
    }
  },
  "excludePatterns": ["*.generated.g4"],
  "outputFormat": "text"
}

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/
isort src/ tests/

# Type checking
mypy src/

License

MIT License

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_v4_linter-0.1.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

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

antlr_v4_linter-0.1.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: antlr_v4_linter-0.1.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for antlr_v4_linter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 efc8d80ce5bc3dbd5643a2d022d246d27421d329f1912c5919f5fdd14b0696d1
MD5 1c2257c7240130ebcfbbbccb9ad002bb
BLAKE2b-256 3a7c80747e0d87dd58772a4aabb6cb93df96191bf651a43f1ad807f31a0147e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for antlr_v4_linter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b91cccb168bc8a039b4931d9c5af4846d4d87864ed4360e5edf1b93280948167
MD5 af8164ba4b9054e6123b0a22b0a16886
BLAKE2b-256 514e4e86297684cf4b381ace2815f47184985d7d6fd0f3a8d10bab8071664705

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