forward-sexp should know what to do in any given mode, so you could perhaps base it on this:
(save-excursion (ignore-errors (forward-sexp) (1- (point))))
Something like how
You could use that exact same code. Look at M-x
show-paren-function and how it uses the results of
(funcall show-paren-data-function), and adapt to your purposes.
show-paren-data-function is a variable defined in `paren.el'.
Its value is `show-paren--default'
This variable may be risky if used as a file-local variable.
Function to find the opener/closer "near" point and its match.
The function is called with no argument and should return either nil
if there's no opener/closer near point, or a list of the form
(HERE-BEG HERE-END THERE-BEG THERE-END MISMATCH)
Where HERE-BEG..HERE-END is expected to be near point.