mruby-regexp: rename has_nongreedy to needs_backtrack

The flag is set not only for non-greedy quantifiers but also for
lookahead, lookbehind, and backreferences. The new name accurately
reflects its purpose: indicating that the backtracking engine is
required instead of the Pike VM.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-03-23 09:38:36 +09:00
parent 13e63657a4
commit 355c68f487
3 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ typedef struct mrb_regexp_pattern {
re_named_capture *named_captures;
uint16_t num_named;
mrb_bool has_backref; /* true if pattern uses \1-\9 */
mrb_bool has_nongreedy; /* true if pattern uses *?, +?, ?? */
mrb_bool needs_backtrack; /* true if pattern needs backtracking engine */
} mrb_regexp_pattern;
/* Regexp flags */
+6 -6
View File
@@ -28,7 +28,7 @@ typedef struct {
re_named_capture *named_captures;
uint16_t num_named;
mrb_bool has_backref;
mrb_bool has_nongreedy;
mrb_bool needs_backtrack;
char *stripped; /* allocated buffer for x-mode preprocessing */
} re_compiler;
@@ -365,7 +365,7 @@ compile_atom(re_compiler *c)
c->code[la_pos].offset = (uint16_t)c->code_len; /* patch: skip past sub-pattern */
if (peek(c) != ')') compile_error(c, "unmatched '('");
next_char(c);
c->has_nongreedy = TRUE; /* needs backtracking engine */
c->needs_backtrack = TRUE; /* needs backtracking engine */
break; /* done with this atom */
}
else if (c->p[1] == '<' && c->p + 2 < c->src_end && (c->p[2] == '=' || c->p[2] == '!')) {
@@ -390,7 +390,7 @@ compile_atom(re_compiler *c)
if (peek(c) != ')') compile_error(c, "unmatched '('");
next_char(c);
c->has_nongreedy = TRUE; /* needs backtracking engine */
c->needs_backtrack = TRUE; /* needs backtracking engine */
break;
}
else if (c->p[1] == '<' && c->p + 2 < c->src_end && c->p[2] != '=' && c->p[2] != '!') {
@@ -548,7 +548,7 @@ compile_quantified(re_compiler *c)
mrb_bool nongreedy = (peek(c) == '?');
if (nongreedy) {
next_char(c);
c->has_nongreedy = TRUE;
c->needs_backtrack = TRUE;
}
@@ -582,7 +582,7 @@ compile_quantified(re_compiler *c)
mrb_bool nongreedy = (peek(c) == '?');
if (nongreedy) {
next_char(c);
c->has_nongreedy = TRUE;
c->needs_backtrack = TRUE;
}
/* For {n,m}: repeat atom min times, then optional (max-min) times */
@@ -774,7 +774,7 @@ re_compile(mrb_state *mrb, const char *pattern, mrb_int len, uint32_t flags)
pat->named_captures = c.named_captures;
pat->num_named = c.num_named;
pat->has_backref = c.has_backref;
pat->has_nongreedy = c.has_nongreedy;
pat->needs_backtrack = c.needs_backtrack;
if (c.stripped) mrb_free(mrb, c.stripped);
return pat;
+1 -1
View File
@@ -515,7 +515,7 @@ re_exec(mrb_state *mrb, const mrb_regexp_pattern *pat,
const char *str, mrb_int len, mrb_int start,
int *captures, int captures_size)
{
if (pat->has_backref || pat->has_nongreedy) {
if (pat->has_backref || pat->needs_backtrack) {
return backtrack_exec(mrb, pat, str, len, start, captures, captures_size);
}
return pike_vm(mrb, pat, str, len, start, captures, captures_size);