add-tokens-with-template
Batch add multiple ANTLR4 lexer tokens using a template pattern, with custom naming, skip/channel/fragment options, and per-rule success feedback.
Instructions
Add multiple similar lexer tokens at once using template-based generation.
When to use:
Add multiple tokens that follow a similar pattern
Generate tokens for command sequences (e.g., "config system X", "set X Y")
Batch-add tokens with consistent naming conventions
Example - Add tokens for "config system X" patterns: base_names: ["ftm-push", "dns", "firewall", "admin"] preceding_tokens: ["SYSTEM", "CONFIG"]
Example - Add multiple keyword tokens: base_names: ["enable", "disable", "show", "hide"] pattern: "'{NAME}'"
Example - Add tokens with custom pattern: base_names: ["tcp", "udp", "icmp"] pattern: "'protocol-{NAME}'"
Features:
Automatically generates proper token names (uppercase with underscores)
Supports custom patterns with {NAME} placeholder
Uses existing bulk add infrastructure for reliability
All standard options supported (skip, channel, fragment)
Returns:
Generated rules list
Per-rule success/failure status
Modified grammar
Summary of results
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| skip | No | If true, adds "-> skip" directive to all generated tokens | |
| channel | No | Optional: Channel name for all generated tokens | |
| pattern | No | Optional: Custom pattern template. Use {NAME} as placeholder for base name. Default: '{NAME}' | |
| fragment | No | If true, marks all generated tokens as fragments | |
| from_file | No | Optional: path to a grammar file to read. Required if using write_to_file. | |
| base_names | Yes | Base names for tokens (e.g., ["ftm-push", "dns", "firewall"]) | |
| write_to_file | No | If true, writes modified grammar back to from_file | |
| grammar_content | No | The ANTLR4 grammar file content | |
| preceding_tokens | No | Optional: Tokens that precede these (for documentation purposes) |