add-lexer-mode
Add a new lexer mode declaration to ANTLR4 grammars for context-sensitive tokenization. Automatically validates the mode name and prevents duplicates, with optional insertion after a specific rule.
Instructions
Add a new lexer mode declaration to an ANTLR4 grammar.
When to use: Creating new modes for context-sensitive tokenization.
Features:
Adds "mode MODE_NAME;" declaration
Optional positioning with insert_after
Validates mode name format
Prevents duplicate mode names
Example - Add mode after specific rule: mode_name: "STRING_MODE" insert_after: "STRING" write_to_file: true
Example - Add mode at end of grammar: mode_name: "TEMPLATE_MODE" write_to_file: true
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read. Required if using write_to_file. | |
| mode_name | Yes | Name of the new mode (UPPER_CASE recommended) | |
| output_mode | No | Output format: "full", "diff", or "none" | |
| insert_after | No | Optional: Insert mode declaration after this rule name | |
| write_to_file | No | If true, writes modified grammar back to from_file | |
| grammar_content | No | The ANTLR4 grammar file content |