This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parses a message and replaces all [a,b,c] structures with a random | |
* selection. | |
* | |
* Supports nested structures and escaping those special characters. | |
* | |
* The general approach is to make a single pass through the whole message | |
* character by character, keeping a stack of lists representing all the choices | |
* at the current index. The outer stack tracks the current nesting level while | |
* the inner list tracks the choices at the given nesting level. |