Lines Matching refs:rex
89 static const char* rexname(Rex_t* rex)
91 if (!rex)
93 if (rex->type >= elementsof(rexnames))
95 return rexnames[rex->type];
249 _matchpush(Env_t* env, Rex_t* rex)
257 if (rex->re.group.number <= 0 || (num = rex->re.group.last - rex->re.group.number + 1) <= 0)
265 f->match = m = env->match + rex->re.group.number;
281 pospush(Env_t* env, Rex_t* rex, unsigned char* p, int be)
290 pos->serial = rex->serial;
403 parserep(Env_t* env, Rex_t* rex, Rex_t* cont, unsigned char* s, int n)
409 DEBUG_TEST(0x0010,(sfprintf(sfstdout, "AHA#%04d 0x%04x parserep %s %d %d %d %d `%-.*s'\n", __LINE__, debug_flag, rexname(rex->re.group.expr.rex), rex->re.group.number, rex->lo, n, rex->hi, env->end - s, s)),(0));
410 if ((rex->flags & REG_MINIMAL) && n >= rex->lo && n < rex->hi)
412 if (env->stack && pospush(env, rex, s, END_ANY))
414 i = follow(env, rex, cont, s);
428 if (n < rex->hi)
431 catcher.serial = rex->serial;
432 catcher.re.rep_catch.ref = rex;
436 catcher.next = rex->next;
438 rex->re.rep_catch.beg = s;
441 if (matchpush(env, rex))
443 if (pospush(env, rex, s, BEG_ONE))
445 DEBUG_TEST(0x0004,(sfprintf(sfstdout,"AHA#%04d 0x%04x PUSH %d (%d,%d)(%d,%d)(%d,%d) (%d,%d)(%d,%d)(%d,%d)\n", __LINE__, debug_flag, rex->re.group.number, env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so, env->best[2].rm_eo, env->match[0].rm_so, env->match[0].rm_eo, env->match[1].rm_so, env->match[1].rm_eo, env->match[2].rm_so, env->match[2].rm_eo)),(0));
447 r = parse(env, rex->re.group.expr.rex, &catcher, s);
448 DEBUG_TEST(0x0010,(sfprintf(sfstdout, "AHA#%04d 0x%04x parserep parse %d %d `%-.*s'\n", __LINE__, debug_flag, rex->re.group.number, r, env->end - s, s)),(0));
452 matchpop(env, rex);
453 DEBUG_TEST(0x0004,(sfprintf(sfstdout,"AHA#%04d 0x%04x POP %d %d (%d,%d)(%d,%d)(%d,%d) (%d,%d)(%d,%d)(%d,%d)\n", __LINE__, debug_flag, rex->re.group.number, r, env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so, env->best[2].rm_eo, env->match[0].rm_so, env->match[0].rm_eo, env->match[1].rm_so, env->match[1].rm_eo, env->match[2].rm_so, env->match[2].rm_eo)),(0));
465 if (rex->flags & REG_MINIMAL)
471 if (n < rex->lo)
473 if (!(rex->flags & REG_MINIMAL) || n >= rex->hi)
475 if (env->stack && pospush(env, rex, s, END_ANY))
477 i = follow(env, rex, cont, s);
492 r = (rex->flags & REG_MINIMAL) ? BEST : GOOD;
500 parsetrie(Env_t* env, Trie_node_t* x, Rex_t* rex, Rex_t* cont, unsigned char* s)
505 if (p = rex->map)
536 if (rex->flags & REG_MINIMAL)
537 switch (follow(env, rex, cont, s))
548 switch (parsetrie(env, x->son, rex, cont, s))
557 if (rex->flags & REG_MINIMAL)
567 if (!(rex->flags & REG_MINIMAL))
568 switch (follow(env, rex, cont, s))
651 collmatch(Rex_t* rex, unsigned char* s, unsigned char* e, unsigned char** p)
662 ic = (rex->flags & REG_ICASE);
708 if (ic ? collic(rex->re.collate.elements, (char*)key, (char*)key, c, x) : collelt(rex->re.collate.elements, (char*)key, c, x))
719 return rex->re.collate.invert ? !r : r;
798 parse(Env_t* env, Rex_t* rex, Rex_t* cont, unsigned char* s)
820 DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), env->end - s, s)),(0));
821 switch (rex->type)
826 if (matchpush(env, rex))
828 if (pospush(env, rex, s, BEG_ALT))
831 catcher.serial = rex->serial;
833 catcher.next = rex->next;
834 r = parse(env, rex->re.group.expr.binary.left, &catcher, s);
835 if (r < BEST || (rex->flags & REG_MINIMAL))
837 matchcopy(env, rex);
838 ((Pos_t*)env->pos->vec + env->pos->cur - 1)->serial = catcher.serial = rex->re.group.expr.binary.serial;
839 n = parse(env, rex->re.group.expr.binary.right, &catcher, s);
844 matchpop(env, rex);
848 if ((r = parse(env, rex->re.group.expr.binary.left, cont, s)) == NONE)
849 r = parse(env, rex->re.group.expr.binary.right, cont, s);
855 if (pospush(env, rex, s, END_ANY))
857 r = follow(env, rex, rex->re.alt_catch.cont, s);
861 o = &env->match[rex->lo];
869 if (!(p = rex->map))
893 if ((!(rex->flags & REG_NEWLINE) || s <= env->beg || *(s - 1) != '\n') && ((env->flags & REG_NOTBOL) || s != env->beg))
897 if (LEADING(env, rex, s))
899 n = rex->hi;
902 m = rex->lo;
906 if (!(rex->flags & REG_MINIMAL))
909 if (!settst(rex->re.charclass, s[i]))
915 switch (follow(env, rex, cont, s))
931 if (!settst(rex->re.charclass, *s))
936 switch (follow(env, rex, cont, s))
946 if (s >= e || !settst(rex->re.charclass, *s))
953 if (LEADING(env, rex, s))
955 n = rex->hi;
958 m = rex->lo;
963 if (!(rex->flags & REG_MINIMAL))
970 for (i = 0; s < e && i < n && collmatch(rex, s, e, &t); i++)
975 for (; i-- >= rex->lo; s -= b[i])
976 switch (follow(env, rex, cont, s))
996 if (!collmatch(rex, s, e, &t))
1000 switch (follow(env, rex, cont, s))
1010 if (s >= e || !collmatch(rex, s, e, &s))
1018 next.next = rex->next;
1020 catcher.re.conj_left.right = rex->re.group.expr.binary.right;
1024 return parse(env, rex->re.group.expr.binary.left, &catcher, s);
1026 rex->re.conj_left.cont->re.conj_right.end = s;
1027 cont = rex->re.conj_left.cont;
1028 s = rex->re.conj_left.beg;
1029 rex = rex->re.conj_left.right;
1032 if (rex->re.conj_right.end != s)
1034 cont = rex->re.conj_right.cont;
1041 DEBUG_TEST(0x0100,(sfprintf(sfstdout,"AHA#%04d 0x%04x %s (%d,%d)(%d,%d)(%d,%d)(%d,%d) (%d,%d)(%d,%d)\n", __LINE__, debug_flag, rexname(rex), env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so, env->best[2].rm_eo, env->best[3].rm_so, env->best[3].rm_eo, env->match[0].rm_so, env->match[0].rm_eo, env->match[1].rm_so, env->match[1].rm_eo)),(0));
1044 if (rex->flags & REG_MINIMAL)
1072 DEBUG_TEST(0x0100,(sfprintf(sfstdout,"AHA#%04d 0x%04x %s (%d,%d)(%d,%d)(%d,%d)(%d,%d) (%d,%d)(%d,%d)\n", __LINE__, debug_flag, rexname(rex), env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so, env->best[2].rm_eo, env->best[3].rm_so, env->best[3].rm_eo, env->match[0].rm_so, env->match[0].rm_eo, env->match[1].rm_so, env->match[1].rm_eo)),(0));
1075 if (LEADING(env, rex, s))
1077 n = rex->hi;
1080 m = rex->lo;
1083 if ((c = rex->explicit) >= 0 && !mbwide())
1091 if (!(rex->flags & REG_MINIMAL))
1096 switch (follow(env, rex, cont, s))
1120 switch (follow(env, rex, cont, s))
1144 switch (follow(env, rex, cont, s))
1162 switch (follow(env, rex, cont, s))
1176 if ((!(rex->flags & REG_NEWLINE) || *s != '\n') && ((env->flags & REG_NOTEOL) || s < env->end))
1180 DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), env->end - s, s)),(0));
1183 if (rex->re.group.number)
1184 env->match[rex->re.group.number].rm_so = s - env->beg;
1185 if (pospush(env, rex, s, BEG_SUB))
1187 catcher.re.group_catch.eo = rex->re.group.number ? &env->match[rex->re.group.number].rm_eo : (regoff_t*)0;
1190 catcher.serial = rex->serial;
1192 catcher.next = rex->next;
1193 r = parse(env, rex->re.group.expr.rex, &catcher, s);
1197 if (rex->re.group.number)
1198 env->match[rex->re.group.number].rm_so = -1;
1202 DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s=>%s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), rexname(rex->re.group_catch.cont), env->end - s, s)),(0));
1205 if (rex->re.group_catch.eo)
1206 *rex->re.group_catch.eo = s - env->beg;
1207 if (pospush(env, rex, s, END_ANY))
1210 r = follow(env, rex, rex->re.group_catch.cont, s);
1214 if (rex->re.group_catch.eo)
1215 *rex->re.group_catch.eo = -1;
1220 catcher.flags = rex->flags;
1221 catcher.serial = rex->serial;
1224 catcher.next = rex->next;
1225 return parse(env, rex->re.group.expr.rex, &catcher, s);
1227 return follow(env, rex, rex->re.rep_catch.cont, rex->re.rep_catch.beg);
1229 r = parse(env, rex->re.group.expr.rex, NiL, s);
1231 r = follow(env, rex, cont, s);
1236 if ((s - env->beg) < rex->re.group.size)
1239 catcher.flags = rex->flags;
1240 catcher.serial = rex->serial;
1244 catcher.next = rex->next;
1245 for (t = s - rex->re.group.size; t >= env->beg; t--)
1248 r = parse(env, rex->re.group.expr.rex, &catcher, t);
1255 if (s != rex->re.behind_catch.beg)
1257 env->end = rex->re.behind_catch.end;
1258 return follow(env, rex, rex->re.behind_catch.cont, rex->re.behind_catch.beg);
1260 if ((s - env->beg) < rex->re.group.size)
1269 for (t = s - rex->re.group.size; t >= env->beg; t--)
1271 r = parse(env, rex->re.group.expr.rex, &catcher, t);
1278 r = follow(env, rex, cont, s);
1283 return s == rex->re.neg_catch.beg ? GOOD : NONE;
1285 if (q = rex->re.group.expr.binary.right)
1292 if (q = rex->re.group.expr.binary.left)
1295 catcher.flags = rex->flags;
1296 catcher.serial = rex->serial;
1300 catcher.next = rex->next;
1305 else if (!rex->re.group.size || rex->re.group.size > 0 && env->match[rex->re.group.size].rm_so >= 0)
1315 catcher.next = rex->next;
1318 return follow(env, rex, cont, s);
1320 rex->re.cond_catch.yes = 1;
1322 catcher.flags = rex->flags;
1323 catcher.serial = rex->serial;
1324 catcher.re.group_catch.cont = rex->re.cond_catch.cont;
1325 catcher.next = rex->next;
1326 return parse(env, rex->re.cond_catch.next[1], &catcher, rex->re.cond_catch.beg);
1328 return follow(env, rex, rex->re.group_catch.cont, s);
1331 catcher.flags = rex->flags;
1332 catcher.serial = rex->serial;
1334 catcher.next = rex->next;
1335 return parse(env, rex->re.group.expr.rex, &catcher, s);
1337 switch (r = follow(env, rex, rex->re.group_catch.cont, s))
1348 f = rex->re.string.fail;
1349 b = rex->re.string.base;
1350 n = rex->re.string.size;
1353 if (p = rex->map)
1368 switch (follow(env, rex, cont, t))
1399 switch (follow(env, rex, cont, t))
1417 if (LEADING(env, rex, s))
1426 catcher.next = rex->next;
1427 if (parse(env, rex->re.group.expr.rex, &catcher, s) == BAD)
1435 switch (follow(env, rex, cont, s + i))
1458 bitset(rex->re.neg_catch.index, s - rex->re.neg_catch.beg);
1465 if ((c = *s++) == rex->re.nest.primary)
1467 if (s >= env->end || !(s = nestmatch(s, env->end, rex->re.nest.type, c)))
1471 if (rex->re.nest.primary >= 0)
1473 if (rex->re.nest.type[c] & (REX_NEST_delimiter|REX_NEST_separator|REX_NEST_terminator))
1475 if (!(s = nestmatch(s, env->end, rex->re.nest.type, c)))
1477 } while (s < env->end && !(rex->re.nest.type[*(s-1)] & (REX_NEST_delimiter|REX_NEST_separator|REX_NEST_terminator)));
1482 n = rex->hi;
1485 m = rex->lo;
1489 c = rex->re.onechar;
1490 if (!(rex->flags & REG_MINIMAL))
1494 if (p = rex->map)
1507 switch (follow(env, rex, cont, s))
1528 if (!(rex->flags & REG_ICASE))
1549 switch (follow(env, rex, cont, s))
1572 if (p = rex->map)
1580 switch (follow(env, rex, cont, s))
1602 switch (follow(env, rex, cont, s))
1619 if (!(rex->flags & REG_ICASE))
1629 switch (follow(env, rex, cont, s))
1653 switch (follow(env, rex, cont, s))
1671 if (env->stack && pospush(env, rex, s, BEG_REP))
1673 r = parserep(env, rex, cont, s, 0);
1678 DEBUG_TEST(0x0020,(sfprintf(sfstdout, "AHA#%04d 0x%04x %s n %d len %d s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), rex->re.rep_catch.n, s - rex->re.rep_catch.beg, env->end - s, s)),(0));
1679 if (env->stack && pospush(env, rex, s, END_ANY))
1681 if (s == rex->re.rep_catch.beg && rex->re.rep_catch.n > rex->re.rep_catch.ref->lo)
1687 DEBUG_TEST(0x0002,(sfprintf(sfstdout, "AHA#%04d %p re.group.back=%d re.group.expr.rex=%s\n", __LINE__, rex->re.rep_catch.ref->re.group.expr.rex, rex->re.rep_catch.ref->re.group.expr.rex->re.group.back, rexname(rex->re.rep_catch.ref->re.group.expr.rex))),(0));
1688 if (!env->stack || s != rex->re.rep_catch.ref->re.rep_catch.beg && !rex->re.rep_catch.ref->re.group.expr.rex->re.group.back)
1690 else if (pospush(env, rex, s, END_ANY))
1694 r = follow(env, rex, rex->re.rep_catch.cont, s);
1699 r = parserep(env, rex->re.rep_catch.ref, rex->re.rep_catch.cont, s, rex->re.rep_catch.n);
1704 DEBUG_TEST(0x0200,(sfprintf(sfstdout,"AHA#%04d 0x%04x parse %s \"%-.*s\" `%-.*s'\n", __LINE__, debug_flag, rexname(rex), rex->re.string.size, rex->re.string.base, env->end - s, s)),(0));
1705 if (rex->re.string.size > (env->end - s))
1707 t = rex->re.string.base;
1708 e = t + rex->re.string.size;
1709 if (!(p = rex->map))
1733 if (((s + rex->re.trie.min) > env->end) || !(x = rex->re.trie.root[rex->map ? rex->map[*s] : *s]))
1735 return parsetrie(env, x, rex, cont, s);
1738 r = (*env->disc->re_execf)(env->regex, rex->re.exec.data, rex->re.exec.text, rex->re.exec.size, (const char*)s, env->end - s, &u, env->disc);
1783 if (!(rex = rex->next))
1785 if (!(rex = cont))
1822 listnode(e->re.group.expr.rex, level + 1);
1830 list(Env_t* env, Rex_t* rex)
1833 if (rex)
1834 listnode(rex, 1);
1894 DEBUG_TEST(0x1000,(list(env,env->rex)),(0));
1896 if ((e = env->rex)->type == REX_BM)
2036 drop(env->disc, env->rex);