generate-tokens-from-pattern
Generate ANTLR4 lexer tokens from natural language input patterns, converting sample text into grammar rules for prototyping.
Instructions
Generate lexer tokens automatically from natural language input patterns.
When to use:
Quick token generation from sample input text
Convert configuration snippets into grammar rules
Generate tokens from command examples
Prototype grammars from example input
Example - Generate tokens from command: input_pattern: "ignore config system ftm-push" → Generates: IGNORE, CONFIG, SYSTEM, FTM_PUSH tokens
Example - Generate single compound token: input_pattern: "config-system-admin" tokenize: false → Generates: CONFIG_SYSTEM_ADMIN token
Example - Add prefix to generated tokens: input_pattern: "show running-config" prefix: "CMD" → Generates: CMD_SHOW, CMD_RUNNING_CONFIG tokens
Features:
Automatic tokenization (splits on whitespace by default)
Intelligent name generation (uppercase with underscores)
Optional prefix for token namespacing
Supports all standard token options (skip, channel, fragment)
Generates proper ANTLR4 string literal patterns
Returns:
List of generated tokens with names and patterns
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 | |
| prefix | No | Optional: Prefix to add to all generated token names | |
| channel | No | Optional: Channel name for all generated tokens | |
| fragment | No | If true, marks all generated tokens as fragments | |
| tokenize | No | If true (default), splits input into individual tokens. If false, creates single token. | |
| from_file | No | Optional: path to a grammar file to read. Required if using write_to_file. | |
| input_pattern | Yes | Input text to generate tokens from (e.g., "ignore config system ftm-push") | |
| write_to_file | No | If true, writes modified grammar back to from_file | |
| grammar_content | No | The ANTLR4 grammar file content |