merge-rules
Consolidate two ANTLR4 grammar rules into one rule with alternatives, reducing grammar complexity and rule count.
Instructions
Merge two related rules into one rule with alternatives.
When to use: Consolidate similar rules, reduce rule count, group related alternatives.
Example - Merge literal rules: rule1_name: "intLiteral" rule2_name: "floatLiteral" new_rule_name: "numericLiteral"
Result: numericLiteral: intLiteral | floatLiteral
Benefits:
Reduces grammar complexity
Groups related alternatives logically
Simplifies parser structure
Note: Original rules are removed; references to them should be updated manually or use rename-rule first.
Returns: Modified grammar with merged rule created and original rules removed.
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": {
"rule1_name": "<rule1_name>",
"rule2_name": "<rule2_name>",
"new_rule_name": "<new_rule_name>"
},
"name": "merge-rules"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| rule1_name | Yes | Name of the first rule to merge (will be removed) | |
| rule2_name | Yes | Name of the second rule to merge (will be removed) | |
| new_rule_name | Yes | Name for the merged rule (must follow ANTLR4 naming conventions) | |
| grammar_content | No | The ANTLR4 grammar file content |