| 1913 | |
| 1914 | |
| 1915 | static Capture *findback (CapState *cs, Capture *cap) { |
| 1916 | lua_State *L = cs->L; |
| 1917 | for (;;) { |
| 1918 | if (cap == cs->ocap) { /* not found */ |
| 1919 | const char *s = lua_tostring(L, -1); |
| 1920 | if (s == NULL) s = lua_pushfstring(L, "(a %s)", luaL_typename(L, -1)); |
| 1921 | luaL_error(L, "back reference '%s' not found", s); |
| 1922 | } |
| 1923 | cap--; |
| 1924 | if (isclosecap(cap)) |
| 1925 | cap = findopen(cap); |
| 1926 | else if (!isfullcap(cap)) |
| 1927 | continue; /* opening an enclosing capture: skip and get previous */ |
| 1928 | if (captype(cap) == Cgroup) { |
| 1929 | getfromenv(cs, cap->idx); /* get group name */ |
| 1930 | if (lua_equal(L, -2, -1)) { /* right group? */ |
| 1931 | lua_pop(L, 2); /* remove reference name and group name */ |
| 1932 | return cap; |
| 1933 | } |
| 1934 | else lua_pop(L, 1); /* remove group name */ |
| 1935 | } |
| 1936 | } |
| 1937 | } |
| 1938 | |
| 1939 | |
| 1940 | static int backrefcap (CapState *cs) { |
no test coverage detected