Better cursor position after input syntax error

This commit is contained in:
Juerd Waalboer 2023-12-28 20:36:57 +01:00
parent e79d5ea2c0
commit 71d2179ea2
3 changed files with 29 additions and 16 deletions

View file

@ -21,13 +21,16 @@ sub split_input($input) {
my @terms;
my $pos = 0;
my $lastpos = 0;
my sub _P($nudge = 0) { $pos = pos($input) + $nudge; }
while (
$input =~ m[
\G \s*+
(?| (') ( (?: \\. | [^\\'] )*+ ) ' (?=\s|;|$)
| (") ( (?: \\. | [^\\"] )*+ ) " (?=\s|;|$)
| () ( (?: \\. | [^\\;'"\s] )++ ) (?=\s|;|$)
(?| (') (?{_P -1}) ( (?: \\. | [^\\'] )*+ ) ' (?{_P}) (?=\s|;|$)
| (") (?{_P -1}) ( (?: \\. | [^\\"] )*+ ) " (?{_P}) (?=\s|;|$)
| () ( (?: \\. | [^\\;'"\s] )++ ) (?{_P}) (?=\s|;|$)
| () (;)
)
]xg
@ -38,11 +41,12 @@ sub split_input($input) {
: $1 && $2 eq "abort" ? "abort"
: $2
);
$pos = pos($input) || 0;
$lastpos = pos($input) || 0;
$pos ||= $lastpos;
}
# End of string not reached
return \$pos if $pos < length($input);
return \$pos if $lastpos < length($input);
# End of string reached
s[\\(.)]{ $escapes{$1} // $1 }ge for @terms;