Add comprehensive documentation for subroutine calls and recursion level backreferences#1
Add comprehensive documentation for subroutine calls and recursion level backreferences#1Copilot wants to merge 4 commits into
Conversation
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
…vel backreferences Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
keith-hall
left a comment
There was a problem hiding this comment.
Looks good, just a couple of places I could use a bit more clarification on please. See individual comments for details.
| ``` | ||
|
|
||
| Behavior: | ||
| - **Backreferences**: Try groups in reverse order (most recent definition first) |
There was a problem hiding this comment.
bearing in mind that some regex patterns could have a backreference to groups with the same name, some defined to the right of the backref and some to the left, and could be part of a different group which is called as a recursive subexpression, what does most recent definition refer to here?
| \n # Backreference group n (n >= 1) | ||
| \k<n> # Alternative syntax for group n | ||
| \k<-n> # Nth group counting backwards | ||
| \k<+n> # Nth group counting forwards |
There was a problem hiding this comment.
can you give some practical examples of these Nth groups counting forwards/backwards please - does it differ when the \k<...> is inside a capture group etc.?
|
|
||
| #### Example 5: Multiple Named Groups | ||
|
|
||
| When multiple groups share the same name, backreference tries them in reverse order (most recent first): |
There was a problem hiding this comment.
Can you give some more examples which involve backtracking, perhaps backtracking inside one of those groups, as well as when a less "recent" group needs to be matched as the backref for the whole thing to match overall etc.
| ```regex | ||
| \n # Backreference group n (n >= 1) | ||
| \k<n> # Alternative syntax for group n | ||
| \k<-n> # Nth group counting backwards |
There was a problem hiding this comment.
can you give some practical examples of these Nth groups counting forwards/backwards please - does it differ when the \k<...> is inside a capture group etc.?
| Behavior: | ||
| - **Backreferences**: Try groups in reverse order (most recent definition first) |
There was a problem hiding this comment.
bearing in mind that some regex patterns could have a backreference to groups with the same name, some defined to the right of the backref and some to the left, and could be part of a different group which is called as a recursive subexpression, what does most recent definition refer to here?
| #### Example 5: Multiple Named Groups | ||
|
|
||
| When multiple groups share the same name, backreference tries them in reverse order (most recent first): |
There was a problem hiding this comment.
Can you give some more examples which involve backtracking, perhaps backtracking inside one of those groups, as well as when a less "recent" group needs to be matched as the backref for the whole thing to match overall etc.
Documents
\g<...>subroutine calls and\k<name±level>recursion level backreferences for developers implementing these features in other regex engines without C/C++ background.Changes
Added
doc/SUBROUTINE_CALLS.md(912 lines)\k<name+0>(same level),\k<name+1>(parent),\k<name-1>(child)Updated
README.mdKey Examples
Palindrome with same-level backreference:
Nested XML tags with cross-level backreference:
Target Audience
Developers implementing regex engines in languages like Rust who need to understand capture behavior at recursion boundaries and edge cases around call stack management.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.