Skip to content

Commit

Permalink
Fix two issues in PCRE printing.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
hvdijk authored and katef committed Sep 20, 2020
1 parent b987814 commit c36e173
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/libre/print/pcre.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ re_flags_print(FILE *f, enum re_flags fl)
if (fl & RE_ZONE ) { fprintf(f, "z"); }
}

enum {
RE_FLAGS_PRINTABLE = RE_ICASE | RE_TEXT | RE_MULTI | RE_REVERSE | RE_SINGLE | RE_ZONE
};

static void
print_endpoint(FILE *f, const struct fsm_options *opt, const struct ast_endpoint *e)
{
Expand All @@ -93,10 +97,10 @@ pp_iter(FILE *f, const struct fsm_options *opt, enum re_flags *re_flags, struct

if (n == NULL) { return; }

if (n->re_flags != *re_flags) {
if ((n->re_flags ^ *re_flags) & RE_FLAGS_PRINTABLE) {
fprintf(f, "(?");
re_flags_print(f, n->re_flags & ~*re_flags);
if (*re_flags & ~n->re_flags) {
if (*re_flags & ~n->re_flags & RE_FLAGS_PRINTABLE) {
fprintf(f, "-");
re_flags_print(f, *re_flags & ~n->re_flags);
}
Expand Down Expand Up @@ -133,7 +137,7 @@ pp_iter(FILE *f, const struct fsm_options *opt, enum re_flags *re_flags, struct
} else {
enum re_flags localflags = *re_flags;
fprintf(f, "(?:");
pp_iter(f, opt, re_flags, n->u.alt.n[i]);
pp_iter(f, opt, &localflags, n->u.alt.n[i]);
fprintf(f, ")");
}
if (i + 1 < n->u.alt.count) {
Expand Down

0 comments on commit c36e173

Please sign in to comment.