update-rule
Replace an existing ANTLR4 grammar rule definition in place, preserving its position. Handles multi-line definitions for complex grammar modifications.
Instructions
Update an existing rule definition in place. Now supports multi-line definitions!
When to use: Modify rule logic, add alternatives, refine patterns, or fix issues.
Example - Simple update: rule_name: "expression" new_definition: "term ((PLUS | MINUS) term)*"
Example - Multi-line update (string with \n): rule_name: "srp_uuid_null" new_definition: "UUID\n | ~(\n ACTION\n | FROM\n )"
Example - Multi-line update (JSON array): rule_name: "srp_uuid_null" new_definition: ["UUID", " | ~(", " ACTION", " | FROM", " )"]
Multi-line support:
Pass a string with embedded \n characters, OR
Pass an array of strings (one per line) - more readable!
Formatting is automatically preserved based on grammar style
Preserves rule position in grammar. Use rename-rule if changing the rule name.
Returns: Modified grammar with rule updated, success message, file write confirmation if applicable.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read. Required if using write_to_file. | |
| rule_name | Yes | Name of the rule to update (case-sensitive) | |
| output_mode | No | Output format: "full" returns entire modified grammar, "diff" returns git-style unified diff (default for modification tools), "none" returns no content (useful for write-only operations) | |
| write_to_file | No | If true, writes modified grammar back to from_file (requires from_file to be set) | |
| new_definition | Yes | The new rule definition to replace the existing one | |
| grammar_content | No | The ANTLR4 grammar file content |