move-rule
Move an existing rule to a new position relative to another rule to reorganize ANTLR4 grammars, group related rules, or fix rule order while preserving formatting and comments.
Instructions
Move an existing rule to a new position relative to another rule.
When to use: Reorganizing grammar, grouping related rules, fixing rule order.
Use cases:
Move related rules together for better organization
Position rules before/after their dependencies
Group similar functionality
Manual rule ordering (alternative to sort-rules)
Features:
Preserves rule formatting (multi-line, comments)
Maintains blank lines between rules
Validates both rule and anchor exist
Detects if rule is already in target position
Example usage:
Move expr rule before term rule: rule_name: "expr" position: "before" anchor_rule: "term"
Move NUMBER token after PLUS token: rule_name: "NUMBER" position: "after" anchor_rule: "PLUS" write_to_file: true
Note: This moves EXISTING rules. To insert NEW rules at specific positions, use add-parser-rule or add-lexer-rule with insert_before/insert_after.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| position | Yes | Move rule before or after the anchor rule | |
| from_file | No | Optional: path to a grammar file to read | |
| rule_name | Yes | Name of the rule to move | |
| anchor_rule | Yes | Name of the rule to use as anchor/reference point | |
| write_to_file | No | If true, writes modified grammar back to from_file (requires from_file to be set) | |
| grammar_content | No | The ANTLR4 grammar file content |