FindNextSubmatch
: return submatches when searching
#3552
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR complements
FindNext
byFindNextSubmatch
. In addition to the start and end of the match as a whole this function returns start and end of each submatch, analogous to Regexp.FindSubmatchIndex. I think this is very useful for certain non-trivial search operations, for example for finding the current environment of some position in a LaTeX file. One could also think of other search functions, for example in the spirit of Regexp.FindAllSubmatchIndex. In any case, this PR is at least a start.This is the first time I work with Go (and Lua). So please check that everything is OK. I've played around with the new function, and it seems to work well. The only issue I have found is possibly due to the way the Go-Lua interface handles slices as opposed to arrays. When accessing a slice element from Lua, I seem to get a pointer instead of a struct. For example, the Lua function
gives
Is there a way to avoid this?