Move <-- HERE arrow for ‘Switch condition not recognized’
$ ./perl -Ilib -e '/(?(1(?#...)))/'
Switch condition not recognized in regex; marked by <-- HERE in m/(?(1( <-- HERE ?#...)))/ at -e line 1.
$ ./perl -Ilib -e '/(?(1x(?#...)))/'
Switch condition not recognized in regex; marked by <-- HERE in m/(?(1x(?#...) <-- HERE ))/ at -e line 1.
With the first one-liner, the arrow in the error message is pointing
to the first offending character.
With the second one-liner, the arrow points to the comment following
the offending character.
The logic for positioning the character is a little odd. The idea is
supposed to be something like:
if current_character++ is not ')'
croak with the arrow right before current_character
But nextchar() is used instead of ++, and nextchar() skips trailing
whitespace and comments after incrementing the current parse position.
We already have code right here to revert back to the previous parse
position and then increment it by one character, for the sake of UTF8.
Indeed, it behaves differently if you add a non-ASCII character under
‘use utf8’:
$ ./perl -Ilib -e 'use utf8; /é(?(1x(?#...)))/'
Switch condition not recognized in regex; marked by <-- HERE in m/?(?(1x <-- HERE (?#...)))/ at -e line 1.
So what this commit does is extend that backtrack logic to happen all
the time, not just with UTF8.