Skip to content

Commit c36e173

Browse files
hvdijkkatef
authored andcommitted
Fix two issues in PCRE printing.
Fix unused local variable localflags: the idea of PR #249 was to use this variable in the call to pp_iter, but this was accidentally still using re_flags. This had no effect because we never need to group an operand of |, as | has the lowest precedence of all operators, but we may want to group operands of | in the future for simpler flag printing. Fix printing of changed flags to ignore a change in global flags: RE_ANCHORED applies to whole regexps only, not individual subexpressions, and cannot be turned on or off. This cannot occur when constructing ASTs from regexps, as the RE_ANCHORED flag will be the same for all AST nodes, but can happen when constructing ASTs from FSMs when additionally using the -b option (which should have no effect).
1 parent b987814 commit c36e173

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/libre/print/pcre.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ re_flags_print(FILE *f, enum re_flags fl)
6767
if (fl & RE_ZONE ) { fprintf(f, "z"); }
6868
}
6969

70+
enum {
71+
RE_FLAGS_PRINTABLE = RE_ICASE | RE_TEXT | RE_MULTI | RE_REVERSE | RE_SINGLE | RE_ZONE
72+
};
73+
7074
static void
7175
print_endpoint(FILE *f, const struct fsm_options *opt, const struct ast_endpoint *e)
7276
{
@@ -93,10 +97,10 @@ pp_iter(FILE *f, const struct fsm_options *opt, enum re_flags *re_flags, struct
9397

9498
if (n == NULL) { return; }
9599

96-
if (n->re_flags != *re_flags) {
100+
if ((n->re_flags ^ *re_flags) & RE_FLAGS_PRINTABLE) {
97101
fprintf(f, "(?");
98102
re_flags_print(f, n->re_flags & ~*re_flags);
99-
if (*re_flags & ~n->re_flags) {
103+
if (*re_flags & ~n->re_flags & RE_FLAGS_PRINTABLE) {
100104
fprintf(f, "-");
101105
re_flags_print(f, *re_flags & ~n->re_flags);
102106
}
@@ -133,7 +137,7 @@ pp_iter(FILE *f, const struct fsm_options *opt, enum re_flags *re_flags, struct
133137
} else {
134138
enum re_flags localflags = *re_flags;
135139
fprintf(f, "(?:");
136-
pp_iter(f, opt, re_flags, n->u.alt.n[i]);
140+
pp_iter(f, opt, &localflags, n->u.alt.n[i]);
137141
fprintf(f, ")");
138142
}
139143
if (i + 1 < n->u.alt.count) {

0 commit comments

Comments
 (0)