validate-grammar
Validates ANTLR4 grammar syntax and identifies common issues like undefined rules, left recursion, and naming violations, returning detailed diagnostics with severity and line numbers.
Instructions
Validate ANTLR4 grammar syntax and detect common issues.
When to use: After making changes to verify correctness, or to diagnose problems in an existing grammar.
Example usage: from_file: "MyGrammar.g4"
Detects:
Undefined rule references (rules used but not defined)
Unused rules (defined but never referenced)
Direct left recursion issues
Fragment rule misuse
Naming convention violations
Returns: List of issues with severity (error/warning/info), descriptions, line numbers, and affected rule names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_path | No | Optional: base directory for resolving imports and tokenVocab. Required for multi-file grammars. | |
| from_file | No | Optional: path to a grammar file to read | |
| max_issues | No | Optional: maximum number of issues to return. Default: 100. Use 0 for unlimited. | |
| load_imports | No | Optional: if true, automatically load imported grammars and lexer vocabulary. Default: true. | |
| grammar_content | No | The content of the ANTLR4 grammar file |