]> git.neil.brown.name Git - edlib.git/commitdiff
rexel: fix bug with capturing groups.
authorNeilBrown <neil@brown.name>
Tue, 15 Aug 2023 12:18:18 +0000 (22:18 +1000)
committerNeilBrown <neil@brown.name>
Tue, 15 Aug 2023 12:18:18 +0000 (22:18 +1000)
The post-parse editing of group matches to put all the right branches
in place was messing up capture requests.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
rexel.c

index 0f5f91a44e96e215689274d30b507fb0db0e4fda..1644c25ce4005e3f84f4b4db278275145f1900b7 100644 (file)
@@ -21,7 +21,7 @@ the file.
       final non-eol item
 - [X] resolve fixme around wrap_margin when splitting
 - [X] resolve fixme reguarding margin in find_curs
-- [ ] search "\brl([123]*|end)\b" replace "ri\1" does rlend -> rirlend
+- [X] search "\brl([123]*|end)\b" replace "ri\1" does rlend -> rirlend
 - [ ] when should lib-renderline call measure_line? Only when asked?
       Or whenever content, width, scale change?
 - [ ] When is left_margin used?  Can I use it for hanging indent?  If
diff --git a/rexel.c b/rexel.c
index 6399ba7fd95bfec57599170f45fdf88a681ebab5..204309eaed1e68b0703aafb4c91e5c1ec1ae17ff 100644 (file)
--- a/rexel.c
+++ b/rexel.c
@@ -1966,8 +1966,8 @@ static int parse_prefix(struct parse_state *st safe)
 
 static bool parse_re(struct parse_state *st safe, int capture_flag)
 {
-       int re_start = st->next;
-       int start = re_start;
+       int re_start;
+       int start;
        int save_mod = st->mod;
        int ret;
        int capture = st->capture;
@@ -2000,6 +2000,8 @@ static bool parse_re(struct parse_state *st safe, int capture_flag)
                st->capture += 1;
        }
        capture_start = capture_max = st->capture;
+       start = re_start = st->next;
+
        while ((ret = parse_branch(st)) != 0 && *st->patn == '|') {
                st->patn += 1;
                relocate(st, start, 1);
@@ -2505,6 +2507,8 @@ static struct test {
        { "a[^\\s123]+b", " a b a12b axyb ", 0, 10, 4},
        { "([\\w\\d]+)\\s*=\\s*(.*[^\\s])", " name = some value ", 0, 1, 17,
         "\\1,\\2", "name,some value"},
+       { "\\brl([123]*|end)\\b", " ->rlend = ", 0, 3, 5,
+        "->ri\\1 = ", "->riend = "},
        { "?|foo(bar)|(bat)foo", "foobar", 0, 0, 6, "\\1", "bar"},
        { "?|foo(bar)|(bat)foo", "batfoo", 0, 0, 6, "\\1", "bat"},
        // compare greedy and non-greedy