fix-quantifier-issues
Fix suspicious quantifier patterns in ANTLR4 grammars, converting ')?' to ')*' for rules that should allow repetition. Targets rules with alternatives and collection-named rules.
Instructions
Selectively fix suspicious quantifier patterns - change )? to )* for specific rules.
When to use: After detect-quantifier-issues identifies problems.
Workflow:
Run detect-quantifier-issues to see what's suspicious
Review the suggestions
Run fix-quantifier-issues with specific rule_names to fix
What it fixes:
Rules with alternatives: (a | b | c)? → (a | b | c)*
Multiple optional elements that suggest repetition
Collection-named rules (_rules, _settings) using )?
Examples:
// Step 1: Detect issues detect-quantifier-issues(from_file: "PaloAlto_interface.g4") → Shows: snie_ethernet, snie_lacp, sniel_high_availability, snil_units
// Step 2: Fix specific rules fix-quantifier-issues( from_file: "PaloAlto_interface.g4", rule_names: ["snie_ethernet", "snie_lacp", "snil_units"] ) → Fixes only those 3 rules
// Fix all detected issues fix-quantifier-issues(from_file: "PaloAlto_interface.g4") → Fixes all suspicious patterns
// Preview without changing fix-quantifier-issues( from_file: "PaloAlto_interface.g4", dry_run: true ) → Shows what would change
Real-world: Palo Alto grammar had 15 rules flagged. User fixed 12, left 3 as-is (they were correct).
Returns: List of changes with line numbers and reasoning
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | If true, shows what would change without modifying. Default: false | |
| from_file | No | Optional: path to a grammar file to read | |
| rule_names | No | Optional: Array of specific rule names to fix. If omitted, fixes all suspicious patterns | |
| output_mode | No | Output mode: "full" returns complete grammar, "diff" returns git-style diff (default: diff), "none" returns no content | |
| 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 |