analyze-lexer-modes
Analyze ANTLR4 lexer modes: list defined modes, rules, entry/exit points, and detect issues like undefined or unreachable modes. Helps debug mode transitions and understand tokenization context.
Instructions
Analyze lexer mode structure in ANTLR4 grammars.
When to use: Understanding mode-based tokenization, debugging mode transitions, documenting mode structure.
Lexer modes allow context-sensitive tokenization by switching between different sets of lexer rules. Common use cases:
String interpolation (switching modes inside strings)
Nested comments
Template parsing
Context-specific keywords
Features:
Lists all defined modes with their rules
Identifies mode entry points (pushMode actions)
Identifies mode exit points (popMode actions)
Detects common issues (undefined modes, unreachable modes, popMode in DEFAULT_MODE)
Returns:
modes: List of modes with their rules and line numbers
entryPoints: Rules that push to each mode
exitPoints: Rules that pop from each mode
issues: Problems detected (undefined modes, empty modes, etc.)
Example usage: from_file: "MyLexer.g4"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| grammar_content | No | The ANTLR4 grammar file content |