analyze-grammar
Extract the complete structure of ANTLR4 grammar files, including rules, dependencies, imports, and validation issues. Supports multi-file grammars with automatic import resolution.
Instructions
Analyze an ANTLR4 grammar file and extract its complete structure.
When to use: First step when exploring an unfamiliar grammar, understanding architecture, or extracting metadata.
Multi-file support: Set load_imports=true to automatically resolve and analyze imported grammars.
Example usage: from_file: "examples/MyGrammar.g4"
Multi-file example: from_file: "PaloAlto_rulebase.g4" base_path: "/path/to/grammars" load_imports: true
Returns:
Grammar name and type (parser/lexer/combined)
All parser rules with definitions and line numbers
All lexer rules with patterns
Rule references and dependencies (which rules reference which)
Import declarations
Grammar options
Validation issues (undefined rules, unused rules, recursion)
With load_imports=true: Includes rules from all imported grammars
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_path | No | Optional: base directory for resolving imports. Defaults to directory of from_file. | |
| from_file | No | Optional: path to a grammar file to read (overrides grammar_content). Recommended for file-based workflows. | |
| load_imports | No | Optional: if true, automatically load and merge imported grammars. Default: true. | |
| summary_only | No | Optional: if true, returns only summary statistics without full rule details. Default: false. Use this for large multi-file grammars. | |
| grammar_content | No | The content of the ANTLR4 grammar file |