From a561630f17e61548193666abf9a8b20f20462558 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 15 Jun 2023 11:28:33 -0300 Subject: Full captures can contain nested captures Nested captures can be recognized because they start (and end) inside the character range of the full capture. This optimization can remove a lot of 'close' captures from the capture logs. --- lpcap.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lpcap.h') diff --git a/lpcap.h b/lpcap.h index 7cf8c24..30f3714 100644 --- a/lpcap.h +++ b/lpcap.h @@ -59,6 +59,18 @@ typedef struct CapState { } CapState; +#define captype(cap) ((cap)->kind) + +#define isclosecap(cap) (captype(cap) == Cclose) +#define isopencap(cap) ((cap)->siz == 0) + +/* true if c2 is (any number of levels) inside c1 */ +#define capinside(c1,c2) \ + (isopencap(c1) ? !isclosecap(c2) \ + : (c2)->index < (c1)->index + (c1)->siz - 1) + + + int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); int getcaptures (lua_State *L, const char *s, const char *r, int ptop); int finddyncap (Capture *cap, Capture *last); -- cgit v1.2.3-55-g6feb