As a quick update for anyone interested in this work, I was able to implement a flawed, but partially functioning solution for positive lookbehinds! You can check out all the changes at this commit but here's the core algorithm:
save(restoringAt: success)
save(restoringAt: intercept)
moveBack(<sub-pattern max length>
<sub-pattern> // failure restores at intercept
clearThrough(intercept) // remove intercept and any leftovers from <sub-pattern>
fail(preservingCaptures: true) // ->success
intercept:
clearSavePoint // remove success
fail // propagate failure
success:
...
As an example, this implementation is able to successfully find a match for (?<=abc)def
in the string zabcdefg
Many thanks to @Michael_Ilseman for his guidance and help getting me to this point.
As I mentioned above however, this solution is quite flawed and has many cases that should work but don't. My next goal is to replace this solution with reverse matching which should enable unbounded variable-length assertions in lookbehinds as well as things like String.ends(with: RegexComponent)