move-rule-to-mode
Relocate a lexer rule to a specified mode within an ANTLR4 grammar to fix misplacements and reorganize grammar structure.
Instructions
Move an existing lexer rule to a different mode.
When to use: Reorganizing lexer rules, fixing mode placement, refactoring grammar structure.
Features:
Moves lexer rules between modes
Preserves rule definition exactly
Validates source rule exists and is a lexer rule
Validates target mode exists
Example - Move rule to STRING_MODE: rule_name: "STRING_CONTENT" target_mode: "STRING_MODE" write_to_file: true
Note: Parser rules cannot be moved to modes (they don't have mode context).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"rule_name": "<rule_name>",
"target_mode": "<target_mode>"
},
"name": "move-rule-to-mode"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| rule_name | Yes | Name of the lexer rule to move | |
| output_mode | No | Output format: "full", "diff", or "none" | |
| target_mode | Yes | Name of the mode to move the rule to | |
| write_to_file | No | If true, writes modified grammar back to from_file | |
| grammar_content | No | The ANTLR4 grammar file content |