m-ender / retina

A regex-based programming language.
MIT License
231 stars 10 forks source link

Repeat something N times #56

Closed m-ender closed 6 years ago

m-ender commented 8 years ago

I have no good solution for this yet, but Retina could really use a way to repeat any stage or group of stages N times, where N is either read from the string, a match or a substitution.

m-ender commented 6 years ago

This has been added for Retina 1.0. You can either give a loop stage an integer parameter (technically syntax abuse of limits, but well...), which will run the loop that many times, or you can give it a string parameter which is then used as a substitution for matching \A(?s:.*)\z against the input, and the loop count is parsed from the result. The substitution will usually either access the history or be an expression based on the match length $.&. The sign of the iteration count will be used to determine whether the loop still terminates when the string stops changing.