find-rule-usages
Locate all references to a specific ANTLR rule with line numbers and context to assess impact before renaming or removing it. Supports imported grammars for cross-file dependency analysis.
Instructions
Find all locations where a specific rule is referenced with line numbers and context.
When to use: Before renaming/removing rules to understand impact, analyze dependencies, or trace rule usage.
Example usage: rule_name: "expression"
Returns:
Total usage count
Per-usage details: line number, rule context (which rule contains the reference)
Complete usage report
Multi-file support:
Set load_imports: true to search across imported grammars
Useful for finding cross-file dependencies
Use before:
Renaming rules (to see what will be affected)
Removing rules (to identify breaking changes)
Refactoring (to understand dependencies)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| base_path | No | Optional: base directory for resolving imports. Required for multi-file grammars. | |
| from_file | No | Optional: path to a grammar file to read | |
| rule_name | Yes | The name of the rule to find usages for (case-sensitive) | |
| load_imports | No | Optional: if true, search across imported grammars. Default: false. | |
| grammar_content | No | The ANTLR4 grammar file content |