MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / match

Function match

Source/Misc/lua/src/lua.c:14042–14117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14040
14041
14042static const char *match (MatchState *ms, const char *s, const char *p) {
14043init: /* using goto's to optimize tail recursion */
14044switch (*p) {
14045case '(': { /* start capture */
14046if (*(p+1) == ')') /* position capture? */
14047return start_capture(ms, s, p+2, CAP_POSITION);
14048else
14049return start_capture(ms, s, p+1, CAP_UNFINISHED);
14050}
14051case ')': { /* end capture */
14052return end_capture(ms, s, p+1);
14053}
14054case L_ESC: {
14055switch (*(p+1)) {
14056case 'b': { /* balanced string? */
14057s = matchbalance(ms, s, p+2);
14058if (s == NULL) return NULL;
14059p+=4; goto init; /* else return match(ms, s, p+4); */
14060}
14061case 'f': { /* frontier? */
14062const char *ep; char previous;
14063p += 2;
14064if (*p != '[')
14065luaL_error(ms->L, "missing " LUA_QL("[") " after "
14066LUA_QL("%%f") " in pattern");
14067ep = classend(ms, p); /* points to what is next */
14068previous = (s == ms->src_init) ? '\0' : *(s-1);
14069if (matchbracketclass(uchar(previous), p, ep-1) ||
14070!matchbracketclass(uchar(*s), p, ep-1)) return NULL;
14071p=ep; goto init; /* else return match(ms, s, ep); */
14072}
14073default: {
14074if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
14075s = match_capture(ms, s, uchar(*(p+1)));
14076if (s == NULL) return NULL;
14077p+=2; goto init; /* else return match(ms, s, p+2) */
14078}
14079goto dflt; /* case default */
14080}
14081}
14082}
14083case '\0': { /* end of pattern */
14084return s; /* match succeeded */
14085}
14086case '$': {
14087if (*(p+1) == '\0') /* is the `$' the last char in pattern? */
14088return (s == ms->src_end) ? s : NULL; /* check end of string */
14089else goto dflt;
14090}
14091default: dflt: { /* it is a pattern item */
14092const char *ep = classend(ms, p); /* points to what is next */
14093int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
14094switch (*ep) {
14095case '?': { /* optional */
14096const char *res;
14097if (m && ((res=match(ms, s+1, ep+1)) != NULL))
14098return res;
14099p=ep+1; goto init; /* else return match(ms, s, ep+1); */

Callers 15

matchMethod · 0.85
matchMethod · 0.85
matchMethod · 0.85
matchMethod · 0.85
matchMethod · 0.85
max_expandFunction · 0.85
min_expandFunction · 0.85
start_captureFunction · 0.85
end_captureFunction · 0.85
str_find_auxFunction · 0.85
gmatch_auxFunction · 0.85
str_gsubFunction · 0.85

Calls 10

start_captureFunction · 0.85
end_captureFunction · 0.85
matchbalanceFunction · 0.85
luaL_errorFunction · 0.85
classendFunction · 0.85
matchbracketclassFunction · 0.85
match_captureFunction · 0.85
singlematchFunction · 0.85
max_expandFunction · 0.85
min_expandFunction · 0.85

Tested by

no test coverage detected