Repository navigation
Recommend using + for token part of parsing regex - #750
RobertCochran wants to merge 1 commit into
Conversation
| NOTE: Some simplistic regular expression engines may not support the `+` | ||
| (match one or more) operator. If your language's regular expression engine | ||
| is one such implementation, then you may need to substitute the `+` for `*` | ||
| (match zero or more) and filter out empty tokens from the input stream | ||
| manually. |
There was a problem hiding this comment.
kanaka asks in #503 to add a blurb about working around deficient regex implementations that don't have +, so I did so. I'm not exactly happy that there's no further guidance than 'it might not work ¯\_(ツ)_/¯'. What are some known-problematic implementations? How can an implementer tell they've managed to stumble on one?
| * ```[\[\]{}()'`~^@]```: Captures any special single character, one of | ||
| ```[]{}()'`~^@``` (tokenized). | ||
|
|
||
| * `"(?:\\.|[^\\"])*"?`: Starts capturing at a double-quote and stops at the |
There was a problem hiding this comment.
This string-parsing segment of the regex uses a PCRE non-capture group to group parts of the string parsing part of the regex together without creating another capture entry. Shouldn't we also say something about working around this if needed? IMO, it is far more likely that a more simplistic regex package wouldn't support non-capture groups than the + operator.
| of all the tokens (strings) in it. The following regular expression | ||
| (PCRE) will match all mal tokens. |
There was a problem hiding this comment.
We explicitly say that this regex is PCRE but then provide advice for how to work around an implementation that doesn't support +? A regex engine that claims to be PCRE that doesn't support + is just broken.
Perhaps instead we should say something along the lines of 'if your engine does not support PCRE, then you can adapt this regex with <list of possible problem spots and their solutions>'. That will probably clue in a potential implementer better that they are (perhaps inadvertently) wandering off the beaten path and either inspire them to be sure their regex engine really is PCRE or will need to take more care in using a regex to parse in their implementation.
The old token parsing regex used
*to match non-special tokens, which would occasionally match and add empty string to the token stream. Change to+to fix this.Addresses #503 on the guide side; does not change any implementations.