#18 Make "match at least/exactly n times" code rely on counter

open
nobody
None
5
2010-01-24
2010-01-24
Rui Maciel
No

If a user needs to rely on the "match at least n times" or "match exactly n times" regular expression, re2c ends up generating a separate state for each match. That has the very nasty effect of ballooning the size of the generated source code, particularly if the user needs to match long instances of a certain regex pattern.

Possibly a good way to sidestep this problem is to rely on a counter instead of implementing a long sequence of states. By implementing a counter then it would be possible to only implement the states related to the pattern of a single repetition and then test the counter to check the number of matches that were already made.

Discussion