aboutsummaryrefslogtreecommitdiffstats
path: root/incdec.pm
diff options
context:
space:
mode:
authorTeddy Wing2021-08-18 20:24:57 +0200
committerTeddy Wing2021-08-18 20:24:57 +0200
commit7b6610832b2a4244b048e0565ef2d299495012c3 (patch)
tree0c70fd0a2e61d738e7820e609d9b99fbcfc9d1b6 /incdec.pm
parent990ca11c40881d6c4c407007b045d66b61d979d9 (diff)
downloadreadline-incdec-7b6610832b2a4244b048e0565ef2d299495012c3.tar.bz2
incdec: Work out positions for new match algorithm
This updated loop gets the start position of the appropriate number nearest to point. It currently only works left to right, but seems like it should be easy enough to extend to be right to left.
Diffstat (limited to 'incdec.pm')
-rw-r--r--incdec.pm14
1 files changed, 10 insertions, 4 deletions
diff --git a/incdec.pm b/incdec.pm
index 19fb951..e1222a7 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -46,7 +46,7 @@ sub incdec {
my @matches = $line =~ /(\d+)/g;
print "[[@matches]]";
# TODO: @- and @+ hold a list of captured groups. You need to loop through matches to get positions for each match with $-+[0]. It doesn't give you a list of positions of all matches.
- print "-[[@-]]-.+[[@+]]+";
+ # print "-[[@-]]-.+[[@+]]+";
# for (my $i = 0; $i < scalar @+ - 1; $i++) {
# print "..$-[$i]:$+[$i]..$point_position..";
# if ($point_position < $+[$i + 1]) {
@@ -67,15 +67,21 @@ sub incdec {
# }
my $i = 0;
+ my $start_position = 0;
while ($line =~ /(\d+)/g) {
my $pos = pos $line;
- print "..+[@+]..perlpos[:$pos]..pos[$point_position]..";
- if ($point_position < $+) {
- print "x[$matches[$i]]x";
+ print "\n-[$-[0]]-+[$+[0]]+\n";
+ # print "..+[@+]..perlpos[:$pos]..pos[$point_position]..";
+ if ($point_position < $+[0]) {
+ print "//[$matches[$i]]//";
+ $start_position = $-[0];
+
+ last;
}
$i++;
}
+ print "\npos[$start_position]\n";
# Final match, final match before point